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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education