Question

Write a program in C++ that inputs an unknown number of test scores (assume that there...

  1. Write a program in C++ that inputs an unknown number of test scores (assume that there is a maximum of 150 scores). Ask the user how many scores that they will be entering. The program should have at least 3 functions. Make sure the functions perform the following:
    1. Calculate the average score
    2. Find the highest score
    3. Find the lowest score
    4. Sort the list from highest to lowest

Output the number of scores, the average, the sorted list, the highest, and the lowest. Use the following data to enter: 10

100 90 89 98 50 66 89 80 92 99

Homework Answers

Answer #1

Code Screenshot :

Executable Code:

#include <iostream>
using namespace std;
void average(int arr[],int n){
   double avg ,sum = 0;
   for (int i = 0; i < n; i++)
   {
       sum+=arr[i];
   }
   cout<<"\nAverage: "<<sum/n;
}
void highest(int arr[],int n){
   int max = arr[0];
   for (int i = 0; i < n; i++)
   {
       if (max < arr[i])
           max = arr[i];
   }
   cout<<"\nHighest Marks: "<<max;
}
void lowest(int arr[],int n){
   int i;
   int min = arr[0];
   for (i = 0; i < n; i++)
   {
       if (min > arr[i])
           min = arr[i];
   }
   cout<<"\nLowest Marks: "<<min;
}
void sort(int arr[],int n){
   int i,temp,j;
       for(i=0;i<n;i++)
       {      
           for(j=i+1;j<n;j++)
           {
               if(arr[i]<arr[j])
               {
                   temp =arr[i];
                   arr[i]=arr[j];
                   arr[j]=temp;
               }
           }
       }
       cout<<"\nMarks after sorting :"<<endl;
       for(i=0;i<n;i++)
           cout<<arr[i]<<"\n";
       cout<<endl;
}
int main()
{
   int marks[150],size;
   cout<<"Please enter the number of test scores: ";
   cin>>size;
   for(int i=0 ;i<size; i++){
       cin>>marks[i];
   }
   highest(marks,size);
   lowest(marks,size);
   sort(marks,size);
   average(marks,size);
   return 0;
}

Sample Output :

Please comment below if you have any queries.
Please do give a thumbs up if you liked the answer thanks :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ Visual Studio 2019 Write a C++ console application that accepts up to 5 numbers from...
C++ Visual Studio 2019 Write a C++ console application that accepts up to 5 numbers from the user. Display all numbers, the highest, the lowest, and the average of the numbers. Ask the user if they want to continue entering another set of numbers. 1) Use proper naming conventions for your variables and functions. 2) Tell the user what the program is all about. Do NOT start the program with “Enter a number”!! 3) Create an array to store the...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
Design a solution that requests and receives student names and an exam score for each. Use...
Design a solution that requests and receives student names and an exam score for each. Use one-dimensional arrays to solve this. The program should continue to accept names and scores until the user inputs a student whose name is “alldone”. After the inputs are complete determine which student has the highest score and display that student’s name and score. Finally sort the list of names and corresponding scores in ascending order. When you are done, printout the Code and, also...
Using python, write the program below. Program Specifications: You are to write the source code and...
Using python, write the program below. Program Specifications: You are to write the source code and design tool for the following specification: A student enters an assignment score (as a floating-point value). The assignment score must be between 0 and 100. The program will enforce the domain of an assignment score. Once the score has been validated, the program will display the score followed by the appropriate letter grade (assume a 10-point grading scale). The score will be displayed as...
The file scores.txt (attached above) contains a list of names and test scores. Create a program...
The file scores.txt (attached above) contains a list of names and test scores. Create a program that reads each line of the file and determines the highest score and who obtained it. This is an exercise in strings. You are required to use at least one string method to determine the names and the scores. Your output should resemble the following: Highest Score: 100 Achieved by: Jay The text file looks like this: Jan 86 Drew 92 Blake 85 Alex...
(C language) <stdio.h> decisions (else if or switch) Write a program to calculate the average of...
(C language) <stdio.h> decisions (else if or switch) Write a program to calculate the average of the 2 highest numbers entered. Ask the user to enter 3 integers, determine which 2 integers are the 2 highest, and then calculate and display the average of the 2 highest numbers. Format the answer to 2 decimal places. The numbers can be entered in any sequence - lowest to highest, highest to lowest, or completely random. A decision block will be necessary to...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
C++ needs to output all of the name of the students not just first Write a...
C++ needs to output all of the name of the students not just first Write a program which uses an array of string objects to hold the five students' full names (including spaces), an array of five characters to hold each student's letter grade, a multi-dimensional array of integers to hold each of the five student's four test scores, and an array of five doubles to hold each student's average test score. The program will use a function to allow...
Write a program that asks for five test scores. The program should calculate the average test...
Write a program that asks for five test scores. The program should calculate the average test score and display it. The number displayed should be formatted in fixed-point notation, with one decimal point of precision. Display: (1) your (1) interactive dialog with the console, (2) the five test scores entered, and (3) the computed average. the pseudo code is: you will need to include a library for the output formatting for specifying decimal point display: #include <iomanip> in std namespace...
Java... Write a class named TestScores. The class constructor should accept an array of test scores...
Java... Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores to...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT