Using c++, write a program that reads students’ names followed by their test scores. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in a class variable of type studentType, which has four private components: studentFName and studentLName of type string, testScore of type int (testScore is between 0 and 100), and grade of type char. Suppose that the class has 20 students. Use an array of 20 components of type studentType. Your program must contain at least the following functions: A function to read the students’ data into the array. A function to assign the relevant grade to each student. A function to find the highest test score. A function to print the names of the students having the highest test score. Your program must output each student’s name in this form: last name followed by a comma, followed by a space, followed by the first name; the name must be left justified. Moreover, other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter9: Records (struct)
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

Using c++, write a program that reads students’ names followed by their test scores. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score.

Student data should be stored in a class variable of type studentType, which has four private components: studentFName and studentLName of type string, testScore of type int (testScore is between 0 and 100), and grade of type char. Suppose that the class has 20 students. Use an array of 20 components of type studentType.
Your program must contain at least the following functions:
  1. A function to read the students’ data into the array.
  2. A function to assign the relevant grade to each student.
  3. A function to find the highest test score.
  4. A function to print the names of the students having the highest test score.
Your program must output each student’s name in this form: last name followed by a comma, followed by a space, followed by the first name; the name must be left justified. Moreover, other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 7 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

It says there is an error in the class solution(the followup one), specifically in the read data function students[i].setGrade(); It says it is empty, but when I add the declaration char grade; to the function and change the statement to students[i].setGrade(grade); it still says there is an error. What does it need to be instead?

Here is my code:

#include <iostream>

#include <string>

 

using namespace std;

 

const int numstudents = 20;

 

class studentType

{

private:

      string studentFName;

      string studentLName;

      int testscore;

      char grade;

public:

      void setName(string first, string last)

      {

            studentFName = first;

            studentLName = last;

      }

      void setScore(int score)

      {

            testscore = score;

      }

      void setGrade(char grade)

      {

            if (testscore >= 90)

            {

                  grade = 'A';

            }

            if (testscore <= 90 && testscore >= 80)

            {

                  grade = 'B';

            }

            if (testscore <= 80 && testscore >= 70)

            {

                  grade = 'C';

            }

            if (testscore <= 70 && testscore >= 60)

            {

                  grade = 'D';

            }

            else

            {

                  grade = 'F';

            }

      }

      string getFirstName()

      {

            return studentFName;

      }

      string getLastName()

      {

            return studentLName;

      }

      int getScores()

      {

            return testscore;

      }

      char getGrade()

      {

            return grade;

      }

};

 

void readData(studentType students[])

{

      string firstName, lastName;

      int score;

      char grade;

      for (int i = 0; i < numstudents; i++)

      {

            cout << "Enter student #" << i + 1 << "'s first name, last name, and test score: ";

            cin >> firstName >> lastName >> score;

            students[i].setName(firstName, lastName);

            students[i].setScore(score);

            students[i].setGrade(grade);

      }

}

 

void printData(studentType students[])

{

      for (int i = 0; i < numstudents; i++)

      {

            cout << left << students[i].getLastName() << ", " << students[i].getFirstName() << ": ";

            cout << students[i].getScores() << " (" << students[i].getGrade() << ")" << endl;

      }

}

 

void findHighestScore(studentType students[], int& highestScore, string& highestName)

{

      highestScore = -1;

      for (int i = 0; i < numstudents; i++)

      {

            if (students[i].getScores() > highestScore)

            {

                  highestScore = students[i].getScores();

                  highestName = students[i].getLastName() + ", " + students[i].getFirstName();

            }

      }

}

 

void printHighestScore(int highestScore, string highestName)

{

      cout << "The highest score is " << highestScore << endl;

      cout << "The following student(s) received the highest score : " << highestName << endl;

}

 

int main()

{

      studentType students[numstudents];

      readData(students);

      printData(students);

      int highestScore;

      string highestName;

      findHighestScore(students, highestScore, highestName);

      printHighestScore(highestScore, highestName);

 

      system("pause");

      return 0;

}

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

This is supposed to use class type not a struct type?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr