Question

Exercise#2: Quiz marks Write a program that generates quiz marks at random, between O and 10 inclusive, for a number (less than 50) of Your program should display the marks, class average, and how many students score students decided by the user. above class average. Sample input/output: nter class size: 15 uiz marks: 8 9 9 1 7 5 5 10 1 07 7 5 8 6 e class average is: 5.87 students scored above average C++ code blocks
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<stdlib.h>

#include<time.h>

using namespace std;

int main(){

                int n; //size of class

                int sum,i, count_above_average;

                double avg; //to store average

               

                cout<<"Enter class size: ";

                cin>>n;

               

                int marks[50]; //to store marks of class maximum size 50

               

                //random number generator

                srand(time(NULL));

               

                sum=0; //initialize sum to zero

                cout<<"Quiz marks: ";

                for(i=0;i<n;i++){

                                //rand()%11 generates 0 to 10

                                marks[i] = rand()%11;

                                //add marks to sum

                                sum = sum + marks[i];

                                //print marks

                                cout<<marks[i]<<" ";

                }

                cout<<endl;

               

                //calculate average

                avg = (double)sum/n;

                cout<<"The class average is: "<<avg<<endl;

               

                //find no. of students above average

                count_above_average = 0; //initialize to zero

                for(i=0;i<n;i++){

                                if(marks[i]>avg)

                                                count_above_average++;

                }

                //print count of students above average

                cout<<count_above_average<<" students scored above average"<<endl;

               

                return 0;

}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
C++ code blocks Exercise#2: Quiz marks Write a program that generates quiz marks at random, between...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question: - write a C++ program that asks user to enter students' quiz scores, calculate the...

    Question: - write a C++ program that asks user to enter students' quiz scores, calculate the total score for each students and average for all. Note: - number of students: 1 through 5. That is, at least one student and up to 5. - number of quizes: 8 through 10. That is, at least 8 quizes and up to 10. - quiz score range: 0 through 100. - when entering quiz scores, if user enters -1, that means the user...

  • Write a C++ program that generates a random number from 0 to 9. It will then...

    Write a C++ program that generates a random number from 0 to 9. It will then prompt the user to guess the random number it generated. Your program stops if the user guesses the right number. (Use the cout function to display the random number the computer generates so that you can determine if your code actually works). SAMPLE OUTPUT Random number = 8 Guess a number in the range [0,9]: 1 Too low Guess a number in the range...

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • JAVA program. I have created a game called GuessFive that generates a 5-digit random number, with...

    JAVA program. I have created a game called GuessFive that generates a 5-digit random number, with individual digits from 0 to 9 inclusive. (i.e. 12345, 09382, 33044, etc.) The player then tries to guess the number. With each guess the program displays two numbers, the first is the number of correct digits that are in the proper position and the second number is the sum of the correct digits. When the user enters the correct five-digit number the program returns...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the...

    (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the four basic arithmetic operations, i.e., addition, subtraction, multiplication and integer division. A sample partial output of the math quiz program is shown below. The user can select the type of math operations that he/she would like to proceed with. Once a choice (i.e., menu option index) is entered, the program generates a question and asks the user for an answer. A sample partial output...

  • In this assignment you are asked to write a python program to maintain the Student enrollment...

    In this assignment you are asked to write a python program to maintain the Student enrollment in to a class and points scored by him in a class. You need to do it by using a List of Tuples What you need to do? 1. You need to repeatedly display this menu to the user 1. Enroll into Class 2. Drop from Class 3. Calculate average of grades for a course 4. View all Students 5. Exit 2. Ask the...

  • 5. The Success Academy is organizing an event for its students. Write a Python program that...

    5. The Success Academy is organizing an event for its students. Write a Python program that prompts the user to enter the student's age and gender. The program should then display the day and time for the event registration based on the table below: Gender Registration Monday, 10:00am- 12:00pm Tuesday, 9:00am-12:00pm Wednesday, 9:00am-12:00pm Age Below 10 years old 10 years old and above Male Female Write a Python program that prompts the user to enter his/her monthly weight for the...

  • Python Code Write a program using functions and mainline logic which prompts the user to enter...

    Python Code Write a program using functions and mainline logic which prompts the user to enter a number. The number must be at least 5 and at most 20. (In other words, between 5 and 20, inclusive.) The program then generates that number of random integers and stores them in a list. The random integers should range from 0 to 100. (You can use a wider range if you want, but the lower end of the range must be at...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT