1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
krok68 [10]
3 years ago
13

Write a program to read as many test scores as the user wants from the keyboard (assuming at most 50 scores). Print the scores i

n (1) original order, (2) sorted from high to low (3) the highest score, (4) the lowest score, and (5) the average of the scores. Implement the following functions using the given function prototypes: void displayArray(int array[], int size) - Displays the content of the array void selectionSort(int array[], int size) - sorts the array using the selection sort algorithm in descending order. Hint: refer to example 8-5 in the textbook. int findMax(int array[], int size) - finds and returns the highest element of the array int findMin(int array[], int size) - finds and returns the lowest element of the array double findAvg(int array[], int size) - finds and returns the average of the elements of the array
Computers and Technology
1 answer:
Oksana_A [137]3 years ago
8 0

Answer: Provided in the explanation segment

Explanation:

Below is the code to carry out this program;

/* C++ program helps prompts user to enter the size of the array. To display the array elements, sorts the data from highest to lowest, print the lowest, highest and average value. */

//main.cpp

//include header files

#include<iostream>

#include<iomanip>

using namespace std;

//function prototypes

void displayArray(int arr[], int size);

void selectionSort(int arr[], int size);

int findMax(int arr[], int size);

int findMin(int arr[], int size);

double findAvg(int arr[], int size) ;

//main function

int main()

{

  const int max=50;

  int size;

  int data[max];

  cout<<"Enter # of scores :";

  //Read size

  cin>>size;

  /*Read user data values from user*/

  for(int index=0;index<size;index++)

  {

      cout<<"Score ["<<(index+1)<<"]: ";

      cin>>data[index];

  }

  cout<<"(1) original order"<<endl;

  displayArray(data,size);

  cout<<"(2) sorted from high to low"<<endl;

  selectionSort(data,size);

  displayArray(data,size);

  cout<<"(3) Highest score : ";

  cout<<findMax(data,size)<<endl;

  cout<<"(4) Lowest score : ";

  cout<<findMin(data,size)<<endl;

  cout<<"(5) Lowest scoreAverage score : ";

  cout<<findAvg(data,size)<<endl;

  //pause program on console output

  system("pause");

  return 0;

}

 

/*Function findAvg that takes array and size and returns the average of the array.*/

double findAvg(int arr[], int size)

{

  double total=0;

  for(int index=0;index<size;index++)

  {

      total=total+arr[index];

  }

  return total/size;

}

/*Function that sorts the array from high to low order*/

void selectionSort(int arr[], int size)

{

  int n = size;

  for (int i = 0; i < n-1; i++)

  {

      int minIndex = i;

      for (int j = i+1; j < n; j++)

          if (arr[j] > arr[minIndex])

              minIndex = j;

      int temp = arr[minIndex];

      arr[minIndex] = arr[i];

      arr[i] = temp;

  }

}

/*Function that display the array values */

void displayArray(int arr[], int size)

{

  for(int index=0;index<size;index++)

  {

      cout<<setw(4)<<arr[index];

  }

  cout<<endl;

}

/*Function that finds the maximum array elements */

int findMax(int arr[], int size)

{

  int max=arr[0];

  for(int index=1;index<size;index++)

      if(arr[index]>max)

          max=arr[index];

  return max;

}

/*Function that finds the minimum array elements */

int findMin(int arr[], int size)

{

  int min=arr[0];

  for(int index=1;index<size;index++)

      if(arr[index]<min)

          min=arr[index];

  return min;

}

cheers i hope this help!!!

You might be interested in
You have to calculate the total amount you spent at the mall today. Which function should you use to do so?
rosijanka [135]
If it has to be exactly then C-sum
3 0
3 years ago
Read 2 more answers
Given an list of N integers, Insertion Sort will, for each element in the list starting from the second element: Compare the ele
Elena L [17]

Answer:

def insSort(arr):

ct=0;

for i in range(1, len(arr)):

key = arr[i]

j = i-1

while j >=0 and key < arr[j] :

arr[j+1] = arr[j]

j -= 1

ct=ct+1;

arr[j+1] = key

return arr,ct;

print(insSort([2,1]))

Output of the program is also attached.

8 0
4 years ago
The process of redefining the functionality of a built-in operator, such as , -, and *, to operate on programmer-defined objects
Ksenya-84 [330]

It should be noted that the process of redefining the functionality of a built-in operator to operate is known as <u>operator overloading</u>.

Operator overloading simply means polymorphism. It's a manner in which the operating system allows the same operator name to be used for different operations.

Operator overloading allows the operator symbols to be bound to more than one implementation. It's vital in redefining the functionality of a built-in operator to operate on programmer-defined objects.

Read related link on:

brainly.com/question/25487186

3 0
3 years ago
The content an craigalist is mainly monitered by?
Jlenok [28]
D)no one

..........................................
8 0
3 years ago
Suppose we are writing a program to calculate the gross pay of workers in a grocery store.
Stolb23 [73]

Answer:

The explaination fo this question is given below in the explanation section. However, the correct option of this question is D.

Explanation:

The correct option of this question is D

keep_going = 'y'

while keep_going == 'y':

   hours = float(input('How many hours did this worker work? '))

   gross_pay = hours * 10

   print('Gross pay:', gross_pay)

   keep_going = input('Calculate another gross pay? [Enter y for yes] ')

# this program will print in a sequence and produce the correct result as #shown in attached picture.    

<u>Why Other options are not correct</u>

<u>A</u>. This option is not correct becuase it not running in a sequence. It asked first "Calculate another gross pay enter y for yes"  . then it get started in unterminated loop and do not finish the loop.

The following output is produce by this code

Calculate another gross pay? [Enter y for yes] y                                                               How many hours did this worker work? 12                                                                                        Gross pay: 120.0                                                                                                               How many hours did this worker work? 10                                                                                        Gross pay: 100.0                                                                                                               How many hours did this worker work? 13                                                                                        Gross pay: 130.0                                                                                                               How many hours did this worker work?  

<u>  B.  </u>This option produce the following output

     How many hours did this worker work? 10                                                                                              Gross pay: 100.0                                                                                                                     Calculate another gross pay? [Enter y for yes] y    

In this option as you enter Y. the program get close and terminated.

<u></u>

<u>C. </u>This option produce the following out put.

   while keep_going == 'y':                                                                                                       NameError: name 'keep_going' is not defined

This option is not correct because in it keep_going is not defined.

5 0
3 years ago
Other questions:
  • Ports on the motherboard can be disabled or enabled in ____ setup. RAM Firmware Northbridge BIOS
    8·1 answer
  • What command in windows re gives you the opportunity to manage partitions and volumes installed on the system?
    7·1 answer
  • Please answer this a due tomorrow!!!
    5·1 answer
  • What is a telecomunications system? 1) A system that enables the transmission of data over public or private networks. 2) A comm
    11·1 answer
  • Draw a logic circuit for the function F = (A + B)(B + C)(A + C), using NOR gates only. ​
    9·1 answer
  • Casey, a woodworker, is developing his own website. He plans to use the site as a means of selling his handmade furniture. While
    10·1 answer
  • My question is do you learn how to do a voice over in technology?
    14·1 answer
  • Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 38 then the outpu
    11·1 answer
  • Which These operating systems use a graphical user interface?
    6·1 answer
  • Different between input and output device​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!