Question

The following C++ program is a slightly modified version of Program 5.20 from Gary J. Bronson...

The following C++ program is a slightly modified version of Program 5.20 from Gary J. Bronson textbook. In this program, you compute and display the average of three grades of each student for a class of four students. You need to modify the code to compute and display the class average as well as the standard deviation. Your code changes are as follows:

1. The variable “double grade” should be replaced by a two-dimensional array variable “double grade[NUMSTUDENTS][NUMGRADES].” Also replace the variable “double average” by “double average[NUMSTUDENTS].” This is necessary since you need to save the entered grades specially to compute the standard deviations.

2. After completing the display of the average grade of all students, your program should compute the class average (i.e., the average of four students’ average grades) and display.

3. Determine and display the class standard deviation by subtracting the class average from each student’s average grade (that results in a set of new numbers, each called a deviation); squaring each deviation; adding the squared deviations; dividing the sum by the number of students, NUMSTUDENTS; and taking its square root.

#include <iostream>

using namespace std;

int main()

{

const int NUMGRADES = 3;

const int NUMSTUDENTS = 4;

int i,j;

double grade, total, average;

for (i = 0; i < NUMSTUDENTS; i++) // start of outer loop

{

total = 0; // clear the total for this student

for (j = 0; j < NUMGRADES; j++) // start of inner loop

{

cout << "Enter an examination grade for this student: ";

cin >> grade;

total += grade; // add the grade into the total

} // end of the inner for loop

average = total / NUMGRADES; // calculate the average

cout << "\nThe average for student " << i << " is " << average << "\n\n";

} // end of the outer for loop

return 0;

}

Copy and paste your modified C++ code here:

Copy and paste display from the Console Debug window here:

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <bits/stdc++.h>
using namespace std;

int main(){

    const int NUMGRADES = 3;
    const int NUMSTUDENTS = 4;

    int i,j;

    //double grade, total, average;
    double grade[NUMSTUDENTS][NUMGRADES];
    double average[NUMSTUDENTS];
    double total, classAverage = 0, standardDeviation = 0;
    
    for (i = 0; i < NUMSTUDENTS; i++) {
        
        total = 0;                             // clear the total for this student
        
        for (j = 0; j < NUMGRADES; j++) {
            
            cout << "Enter an examination grade for student " << i << ": ";
            cin >> grade[i][j];
            
            total += grade[i][j]; // add the grade into the total
        }
        average[i] = total / NUMGRADES; // calculate the average

        cout << "\nThe average for student " << i << " is " << average[i] << "\n\n";
    }
    
    for(i = 0; i < NUMSTUDENTS; i++) {
        classAverage += average[i];
    }
    
    classAverage /= NUMSTUDENTS;
    
    cout << "The Class Average is " << classAverage << "\n\n";
    
    
    //Standard Deviation calculation
    for(i = 0; i < NUMSTUDENTS; i++) {
        standardDeviation += (classAverage - average[i]) * (classAverage - average[i]);
    }
    
    standardDeviation /= NUMSTUDENTS;
    standardDeviation = sqrt(standardDeviation);

    cout << "The Standard Deviation is " << standardDeviation << "\n";
    
    return 0;
}

Output :-

Enter an examination grade for student 0: 15
Enter an examination grade for student 0: 65
Enter an examination grade for student 0: 28

The average for student 0 is 36

Enter an examination grade for student 1: 87
Enter an examination grade for student 1: 64
Enter an examination grade for student 1: 59

The average for student 1 is 70

Enter an examination grade for student 2: 35
Enter an examination grade for student 2: 84
Enter an examination grade for student 2: 34

The average for student 2 is 51

Enter an examination grade for student 3: 95
Enter an examination grade for student 3: 45
Enter an examination grade for student 3: 94

The average for student 3 is 78

The Class Average is 58.75

The Standard Deviation is 16.3917


Add a comment
Know the answer?
Add Answer to:
The following C++ program is a slightly modified version of Program 5.20 from Gary J. Bronson...
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
  • C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you...

    C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...

  • 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...

  • hello there. can you please help me to complete this code. thank you. Lab #3 -...

    hello there. can you please help me to complete this code. thank you. Lab #3 - Classes/Constructors Part I - Fill in the missing parts of this code #include<iostream> #include<string> #include<fstream> using namespace std; class classGrades      {      public:            void printlist() const;            void inputGrades(ifstream &);            double returnAvg() const;            void setName(string);            void setNumStudents(int);            classGrades();            classGrades(int);      private:            int gradeList[30];            int numStudents;            string name;      }; int main() {          ...

  • What did I do wrong with this C++ code? Assume that we don't need to ask...

    What did I do wrong with this C++ code? Assume that we don't need to ask users for the number of students. #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size; int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total; // average grade and total grades //**************start your code here************************ cout<<"How many student grades...

  • I have homework that asks to create C++ program to include: 1A) Create and populate a...

    I have homework that asks to create C++ program to include: 1A) Create and populate a parallel-array Data Structure using the following code: //Student grade records are stored in a parallel-array Data Structure. //Here is the code to generate and populate //the Parallel-Array Data Structure: const int NG = 4; //Number of Grades string names[] = {"Amy Adams", "Bob Barr", "Carla Carr", "Dan Dobbs", "Elena Evans" }; int assessment[][NG]= { {98,87,93,88}, {78,86,82,91}, {66,71,85,94}, {72,63,77,69}, {91,83,76,60} };    1B) Define a...

  • Implement and test a function that uses dynamic array to store students’ grades and calcuate the...

    Implement and test a function that uses dynamic array to store students’ grades and calcuate the average grade. // This program demonstrates the use of dynamic array // it #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size = 2; grades = new float[size];    int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total;...

  • Write a C program that allows a user to enter up to 30 student id’s and...

    Write a C program that allows a user to enter up to 30 student id’s and 3 grades per student. It will then compute and display a report of the students averages, and then a statement of the class average for those grades. The following is a sample run that demonstrates what your program should look like: Please enter your school name: Cape Tech Welcome to the Cape Tech Grade Calculator Enter the number of students to process (0 -...

  • // This program will read in a group of test scores (positive integers from 1 to...

    // This program will read in a group of test scores (positive integers from 1 to 100) // from the keyboard and then calculate and output the average score // as well as the highest and lowest score. There will be a maximum of 100 scores. // #include <iostream> using namespace std; float findAverage (const int[], int); // finds average of all grades int findHighest (const int[], int); // finds highest of all grades int findLowest (const int[], int); //...

  • *** Please construct a flowchart for the following code (this was in C++): *** #include using...

    *** Please construct a flowchart for the following code (this was in C++): *** #include using namespace std; void printPrompt(int n){    switch(n){        case 1:            cout << "Enter the quiz grades:" <            break;        case 2:            cout << "Enter the assignments grades:" <            break;        case 3:            cout << "Enter the exam grades:" <            break;        case...

  • Please program in C++ and document the code as you go so I can understand what...

    Please program in C++ and document the code as you go so I can understand what you did for example ///This code does~ Your help is super appreciated. Ill make sure to like and review to however the best answer needs. Overview You will revisit the program that you wrote for Assignment 2 and add functionality that you developed in Assignment 3. Some additional functionality will be added to better the reporting of the students’ scores. There will be 11...

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