Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create a class called Student with four (4) private member variables, name (s

ID: 3881845 • Letter: 1

Question

1.       Create a class called Student with four (4) private member variables, name (string), quiz, midterm, final (all double type);

2.       Include all necessary member functions for this class;

3.       Declare three (3) objects of Student type (individual or array);

4.       Read from the keyboard values of quiz, midterm, final and assign them to each object;

5.       Using the object’s member function to calculate the grade for each student (grade = quiz * 0.2 + midterm * 0.4 + final * 0.4)

6.       Display on the screen the name of each student and the grade.


Hints:

Member function in the object

Not the function outside of object

-Action (data processed?must be inside the object

-read and display plot (display) may be outside.

Actions build in the class

Explanation / Answer

Student.cpp
-------------------------

#include <iostream>

using namespace std;

// Creating a Student class

class Student {

// Declaring private member variables

private :

string name;

double quiz;

double midterm;

double final;

// Declaring all necessary member functions

public :

// This function is used to retrieve the name

string getName() {

return name;

}

// This function is used to set the name

void setName(string name) {

this->name = name;

}

// This function is used to retrieve quiz score

double getQuiz() {

return quiz;

}

// This function is used to set quiz score

void setQuiz(double quiz) {

this->quiz = quiz;

}

// This function is used to get midterm score

double getMidterm() {

return midterm;

}

// This function is used to set midterm score

void setMidterm(double midterm) {

this->midterm = midterm;

}

// This function is used to get final score

double getFinal() {

return final;

}

// This function is used to set final score

void setFinal(double final) {

this->final = final;

}

// This function is used to calculate the grade

double calculateGrade(double quiz, double midterm, double final) {

double grade = (quiz*0.2) + (midterm*0.4) + (final*0.4);

return grade;

}

};

int main() {

// Declaring variables to store quiz scores

double firstQuiz;

double secondQuiz;

double thirdQuiz;

// Declaring variables to store midterm scores

double firstMidterm;

double secondMidterm;

double thirdMidterm;

// Declaring variables to store final scores

double firstFinal;

double secondFinal;

double thirdFinal;

// Declaring variables to store names

string firstName;

string secondName;

string thirdName;

// Greeting the user to this system

cout << "Welcome to Grading System" << endl;

// Prompting the User to enter the details of first student

cout << "Enter the name of First Student" << endl;

cin >> firstName;

cout << "Enter the scores of "+firstName << endl;

cout << "Enter Quiz Score: " << endl;

cin >> firstQuiz;

cout << "Enter Midterm Score: " << endl;

cin >> firstMidterm;

cout << "Enter Final Score: " << endl;

cin >> firstFinal;

// Prompting the user to enter the details of second student

cout << "Enter the name of Second Student" << endl;

cin >> secondName;

cout << "Enter the scores of "+secondName << endl;

cout << "Enter Quiz Score: " << endl;

cin >> secondQuiz;

cout << "Enter Midterm Score: " << endl;

cin >> secondMidterm;

cout << "Enter Final Score: " << endl;

cin >> secondFinal;

// Prompting the user to enter the details of third student

cout << "Enter the name of Third Student" << endl;

cin >> thirdName;

cout << "Enter the scores of "+thirdName << endl;

cout << "Enter Quiz Score: " << endl;

cin >> thirdQuiz;

cout << "Enter Midterm Score: " << endl;

cin >> thirdMidterm;

cout << "Enter Final Score: " << endl;

cin >> thirdFinal;

// Creating the object of first student

Student firstStudent;

// Setting the scores of first student using member functions

firstStudent.setName(firstName);

firstStudent.setQuiz(firstQuiz);

firstStudent.setMidterm(firstMidterm);

firstStudent.setFinal(firstFinal);

// Creating the object of second student

Student secondStudent;

// Setting the scores of second student using member functions

secondStudent.setName(secondName);

secondStudent.setQuiz(secondQuiz);

secondStudent.setMidterm(secondMidterm);

secondStudent.setFinal(secondFinal);

// Creating the object of third student

Student thirdStudent;

// Setting the scores of third student using member functions

thirdStudent.setName(thirdName);

thirdStudent.setQuiz(thirdQuiz);

thirdStudent.setMidterm(thirdMidterm);

thirdStudent.setFinal(thirdFinal);

// Calculating the grades by calling the member function

double firstGrade = firstStudent.calculateGrade(firstStudent.getQuiz(), firstStudent.getMidterm(), firstStudent.getFinal());

double secondGrade = secondStudent.calculateGrade(secondStudent.getQuiz(), secondStudent.getMidterm(), secondStudent.getFinal());

double thirdGrade = thirdStudent.calculateGrade(thirdStudent.getQuiz(), thirdStudent.getMidterm(), thirdStudent.getFinal());

// Displaying the data (name and grade details) to the user.

cout << firstName << "'s grade is " << firstGrade << endl;

cout << secondName << "'s grade is " << secondGrade << endl;

cout << thirdName << "'s grade is " << thirdGrade << endl;

}

Sample Input:
Larry
50
60
80
Sergi
60
90
95
Robert
40
60
50

Sample Output:
Larry's grade is 66
Sergi's grade is 86
Robert's grade is 52