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

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

  • use c++ Weighted GPA Calculator2 Many schools factor in the number of credits each course is...

    use c++ Weighted GPA Calculator2 Many schools factor in the number of credits each course is worth, meaning a 4-credit class has more value than a 2-credit class when calculating students GPA Suppose the following were the grades for a student CreditsGrade lass Pre-Calculus History Chemistry Physical Education 1 Letter grades are assigned as follows Letter grades are worth these points 0-60 F 61 -70 D 71 80 C 81 -90 B 91 -100 A Class Pre-Calculus History Chemistr)y Physical...

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

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • Modify Assignment #18 so it drops each student’s lowest score when determining the students’ test score...

    Modify Assignment #18 so it drops each student’s lowest score when determining the students’ test score average and Letter grade. No scores less than 0 or greater than 100 should be accepted #include<iostream> #include<string> using namespace std; int main() { double average[5]; string name[5]; char grade[5]; for(int i=0; i<=5; i++) { cout<<"Enter student name: "; cin.ignore(); getline(cin,name[i]); int sum=0; for(int j=0; j<5; j++) { int grades; cout<<"Enter Grades:"<<j+1<<" : "; cin>>grades; sum+=grades; } average[i]=(float)sum/5; if(average[i]>=90 && average[i]<=100) grade[i]='A'; else if(average[i]>=80...

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