Question

PROGRAMMING

Consider the following program that reads students’ test scores into an array and prints the contents of the array.   You will add more functions to the program.  The instructions are given below.

image.png

image.png


image.pngimage.png

For each of the following exercises, write a function and make the appropriate function call in main.

Comments are to be added in the program.

 

1.       Write a void function to find the average test score for each student and store in an array studentAvgs.

 

void AverageScores( const int scores[][MAX_TESTS],

                       int numberOfStudents,

                       int numberOfTests,

                       double studentAvgs[]);

 

2.       Write a void function to find the average score on each test and store in an array testAvgs.

 

 

3.       Write a void function to print the average score for each student, i.e. print the contents of the array studentAvgs.  The output will be well formatted and accompanied with appropriate messages.

 

 

4.       Write a void function to print the average score on each test, i.e. print the contents of the array testAvgs.  The output will be well formatted and accompanied with appropriate messages.

 

 

5.       Add the following declaration for the array studentsPassing in the function main.

 

bool studentsPassing[MAX_STUDENTS];

 

6.       Write a function that initializes all components of the array studentsPassing to false.  The array studentsPassing is a parameter.

 

void Initialize(bool studentsPassing[],int numberOfStudents)

 

7.       Write a function that has studentsPassingstudentAvgs, and numberOfStudents as parameters.  Set the components of passing to true whenever the corresponding value in studentAvgs is greater than or equal to 50.0

 

8.       Write a function that has studentsPassing as parameter and print the number of students who passed, i.e. count and print the number of components in studentsPassing that are true.  It will also print which students passed.  Display meaningful messages.

 

9.       Write a function that has studentAvgs and numberOfStudents as parameters, and determine the highest average score of the class.  This value and the student number with this value will be formatted and printed with an appropriate message.

 

10.       Complete the program with the functions and the appropriate function calls.  Run the program using the following test data:

 

Number of students :  5

Number of tests: 4

The test scores for the 5 students:

(note that each row represents the four test scores for one student)

69  80  90  95

70  90  65  85

50  50  60  60

40  45  30  50

25  35  45  49

 

Note: Your program will have good layout following the guidelines for program layout.  It will also have appropriate comments and function headers with good description.

 

Run the program again using at least two other data sets using a different number of students and tests for each test run.

 

The output from the program must be well-formatted and meaningful.

 

 

 


0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<iomanip>

using namespace std;


//constat declaration

const int MAX_STUDENTS = 30;

const int MAX_TESTS = 10;


//function prototypes

void ReadScores(double[] [MAX_TESTS],int&, int&);

void PrintScores(double[] [MAX_TESTS], int, int);

void AverageScores(double [][MAX_TESTS], int, int,double [MAX_STUDENTS]);

void PrintAverageScores(double [MAX_STUDENTS],int);

void TestAverage(double [][MAX_TESTS], int, int,double [MAX_TESTS]);

void PrintTestAverage(double [MAX_TESTS],int);

void initialize(bool [MAX_STUDENTS], int);

void setResult(bool [MAX_STUDENTS], double [MAX_STUDENTS], int);

void printResult(bool [MAX_STUDENTS], int);

void highestScore(double [MAX_STUDENTS], int);


int main(){

   //variable declaration

   double scores[MAX_STUDENTS][MAX_TESTS];

   double studentAvgs[MAX_STUDENTS];

   double testAvgs[MAX_TESTS];

   int numberOfStudents;

   int numberOfTests;

   bool studentPassing[MAX_STUDENTS];

   

   //calling functions

   ReadScores(scores,numberOfStudents, numberOfTests);

   PrintScores(scores, numberOfStudents, numberOfTests);

   AverageScores(scores, numberOfStudents, numberOfTests, studentAvgs);

   PrintAverageScores(studentAvgs, numberOfStudents);

   TestAverage(scores, numberOfStudents, numberOfTests, testAvgs);

   PrintTestAverage(testAvgs, numberOfTests);

   initialize(studentPassing, numberOfStudents);

   setResult(studentPassing, studentAvgs, numberOfStudents);

   printResult(studentPassing, numberOfStudents);

   highestScore(studentAvgs, numberOfStudents);

}


void ReadScores(double scores[][MAX_TESTS], int& numberOfStudents, int& numberOfTests){

   int student;

   int test;

   cout<<"Enter the number of students (up to "<<MAX_STUDENTS<<" ): ";

   cin>>numberOfStudents;

   cout<<"Enter the number of tests (up to "<<MAX_TESTS<<" ): ";

   cin>>numberOfTests;

   

   for(student = 0;student < numberOfStudents; student++){

      cout<<"Enter the "<<numberOfTests<<" test scores (0-100 inclusive) for student "<<(student+1)<<endl;

      for(test=0;test<numberOfTests;test++){

         cin>>scores[student][test];

      }

   }

}


void PrintScores(double scores[][MAX_TESTS], int numberOfStudents, int numberOfTests){

   int student;

   int test;

   cout<<"--------------------Test Score--------------------"<<endl;

   

   for(student=0;student<numberOfStudents;student++){

      cout<<"Student: "<<student+1<<" : ";

      for(test=0;test<numberOfTests;test++){

         cout<<"Test "<<test+1<<" : "<<setw(3)<<scores[student][test]<<" ";

      }

      cout<<endl;

   }

}


void AverageScores(double scores[][MAX_TESTS],int numberOfStudents, int numberOfTests, double studentAvgs[]){

   int student;

   int test;

   for(student = 0;student<numberOfStudents;student++){

      double sum=0;

      for(test = 0;test<numberOfTests;test++){

         sum += scores[student][test];

      }

      double avg = sum/numberOfTests;

      studentAvgs[student] = avg;  

   }

   

}


void PrintAverageScores(double studentAvgs[],int numberOfStudents){

   cout<<"-------Average Marks of students------"<<endl;

   for(int student=0;student<numberOfStudents;student++)

      cout<<"Student "<<student+1<< " : "<<studentAvgs[student]<<endl;

   cout<<endl;

}



void TestAverage(double scores[][MAX_TESTS],int numberOfStudents, int numberOfTests, double testAvgs[]){

   int student;

   int test;

   for(student = 0;student<numberOfStudents;student++){

      double sum=0;

      for(test = 0;test<numberOfTests;test++){

         sum += scores[test][student];

      }

      double avg = sum/numberOfTests;

      testAvgs[student] = avg;  

   }

   

}


void PrintTestAverage(double testAvgs[],int numberOfTests){

   cout<<"-------Average Marks of each Test------"<<endl;

   for(int test=0;test<numberOfTests;test++)

      cout<<"Test "<<test+1<< " : "<<testAvgs[test]<<endl;

   cout<<endl;

}


void initialize(bool StudentPassing[], int numberOfStudents){

   for(int student = 0;student<numberOfStudents;student++){

      StudentPassing[student] = false;

   }

}


void setResult(bool studentPassing[], double studentAvgs[], int numberOfStudents){

   double cutOff = 50;

   for(int student=0;student<numberOfStudents;student++){

      if(studentAvgs[student] > cutOff)

         studentPassing[student] = true;

   }

}


void printResult(bool studentPassing[], int numberOfStudents){

   int count = 0;

   cout<<"-------List of passed student-------"<<endl;

   for(int student = 0;student<numberOfStudents;student++){

      if(studentPassing[student] == true){

         cout<<"Student: "<<student+1<<endl;

         count++;

      }

   }

   cout<<"Total number of student passed: "<<count<<endl;

}


void highestScore(double studentAvgs[], int numberOfStudents){

   double maxScore = 0;

   int topperID;

   for(int student=0;student<numberOfStudents;student++){

      if(studentAvgs[student] > maxScore){

         maxScore = studentAvgs[student];

         topperID = student;

      }

   }

   cout<<"----------Topper-------"<<endl;

   cout<<"Student : "<<topperID+1<<" "<<endl;

   cout<<"Marks : "<<maxScore<<" "<<endl;

}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
PROGRAMMING
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
  • Consider the following program that reads students’ test scores into an array and prints the contents of the array. You will add more functions to the program. The instructions are given below.

    Consider the following program that reads students’ test scores into an array and prints the contents of the array.   You will add more functions to the program.  The instructions are given below.              For each of the following exercises, write a function and make the appropriate function call in main.Comments are to be added in the program. 1.       Write a void function to find the average test score for each student and store in an array studentAvgs. void AverageScores( const int scores[][MAX_TESTS],                       int...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • c++ Instructions Overview In this programming challenge you will create a program to handle student test...

    c++ Instructions Overview In this programming challenge you will create a program to handle student test scores.  You will have three tasks to complete in this challenge. Instructions Task 1 Write a program that allocates an array large enough to hold 5 student test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the...

  • Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The...

    Rewrite the Course class in Listing 10.6 to implement the comparable and the cloneable interfaces. The clone method must allow a deep copy on the students field. In addition, add the equals(Object o) and the toString() methods. Write a test program to invoke the compareTo, clone, equals, and toString methods in a meaningful way. Below is the Listing from the book that needs to be rewritten public class Course {    private String courseName;    private String[] students = new...

  • (C++ programming) Need help with homework. Write a program that can be used to gather statistical...

    (C++ programming) Need help with homework. Write a program that can be used to gather statistical data about the number of hours per week college students play video games. The program should perform the following steps: 1). Read data from the input file into a dynamically allocated array. The first number in the input file, n, represents the number of students that were surveyed. First read this number then use it to dynamically allocate an array of n integers. On...

  • (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...

    (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...

  • Arrays C++ #include <iostream> using namespace std; int main() {       int   tests[6]; // array declaration...

    Arrays C++ #include <iostream> using namespace std; int main() {       int   tests[6]; // array declaration       int   sum = 0;       float avg;       //input test scores       cout << " Enter " << 6 << " test scores: " << endl;       for (int i = 0; i < 6; i++)       {             cout << "Enter Test " << i + 1 << ": ";             cin >> tests[i];       }       return 0; }    Type...

  • #ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores...

    #ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include <string> using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores { private: string studentName; // The student's name double *testScores; // Points to array of test scores int numTestScores; // Number of test scores // Private member function to create an // array of test scores. void createTestScoresArray(int size) { numTestScores = size; testScores = new double[size]; for (int i = 0; i < size; i++) testScores[i] = DEFAULT_SCORE; } public: // Constructor StudentTestScores(string...

  • Small Basic Programming Question: Average Score- Write a program that uses loop to collect data and...

    Small Basic Programming Question: Average Score- Write a program that uses loop to collect data and calculate the average score over a number of tests for a number of students. The program should: 1. first ask the user to enter the number of students in the range of 1 to 10. 2. then the program asks the user to enter the number of tests (in the range of 1 to 5) 3. Then use a loop to collect the scores...

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