Question

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.

 

 

Capture.PNG

 

 

 Capture 2.PNG

 

 

 


 

 


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

 

 


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

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

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • C++ program that reads students' names followed by their test scores (5 scores) from the given...

    C++ program that reads students' names followed by their test scores (5 scores) from the given input file, students.txt. The program should output to a file, output.txt, each student's first name, last name, followed by the test scores and the relevant grade. All data should be separated by a single space. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, an array of testScores of type int...

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

  • Instructions: Consider the following C++ program. At the top you can see the interface for the...

    Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...

  • codeblock c++ language Write a program that reads students test scores in the range 0-200 from...

    codeblock c++ language Write a program that reads students test scores in the range 0-200 from a file until end of file (use e of() to check if ifstream reaches the End of File Stream) and store those scores in an array. It should then determine the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100- 124, 125–149, 150-174, and 175–200. Finally, the program outputs the total number of students, each score range...

  • read in numbers into array , print out, sort - my program reads in and prints...

    read in numbers into array , print out, sort - my program reads in and prints out but crashes before the sort - crashes after it prints out the scores - *important I have to use pointers!!!! c++ #include <iostream> using namespace std; void sortarray(int *tarray, int ); void displayarray(int *[], int); void averageshowarray(int *[], int); int main() {     int Size;     int count;     cout << "enter the size: " << endl;     cin >> Size;     int...

  • written in c++ Write a program that reads a file consisting of students’ test scores in...

    written in c++ Write a program that reads a file consisting of students’ test scores in the range 0–200. It should then determine the number of students having scores in each of the following ranges: 0–24, 25–49, 50–74, 75–99, 100–124, 125–149, 150–174, and 175–200. Output the score ranges and the number of students. (Run your program with the following input data:76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149,...

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