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

Write a program in c++ that will read student’s ID, first name, last name, and 5

ID: 3799604 • Letter: W

Question

Write a program in c++ that will read student’s ID, first name, last name, and 5 scores from an input file “hw2data.txt”. The 5 scores are midterm exam score, final exam score, homework score, lab score, and quiz score. The program calculates a student’s weighted total based on the formula: Weighted total = 25%(midterm score) + 25%(final exam score) + 30%(homework score) + 10%(lab score) + 10%(quiz score). And then assigns a letter grade to student using the grade scale: 90 <= weighted total <= 100 A 80 <= weighted total < 90 B 70 <= weighted total < 80 C 60 <= weighted total < 70 D 0 <= weighted total < 60 F The program should output each student’s ID, full name, 5 scores, weighted total, and letter grade in a neat format. Your program should define a class Student and implement it as required. The class Student should have the following private member variables. Member Variable Description ID An int variable that holds a student’s ID. firstName A string variable that holds a student’s first name. lastName A string variable that holds a student’s last name. scores An int array that holds a student’s 5 scores in the order of midterm exam score, final exam score, homework score, lab score, and quiz score. The class Student should also have the following public member functions. Member Function Description Default constructor Set ID to 0, firstName and lastName to empty string, and all elements of scores to 0. Overload constructor Accepts a student’s ID, first name, last name, and an int array (storing 5 scores) as arguments. Calls other member functions to copy these values into the appropriate member variables. setID Accepts an int argument and copies it into the ID member variable. setFName Accepts a string argument and copies it into the firstName member variable. setLName Accepts a string argument and copies it into the lastName member variable. setScores Accepts an int array argument and copies it into the scores member variable. getID Returns the value in ID. getFName Returns the value in firstName. getLName Returns the value in lastName. getWeightedTotal Calculates and returns the weighted total as a floating-point value. The weight for the midterm score, final score, homework score, lab score, and quiz score is 25%, 25%, 30%, 10%, and 10%, respectively. getGrade Finds and returns the letter grade based on the student’s weighted total. printStudent Call other member functions and output a student’s ID, first name followed by a space, followed by last name, and followed by 5 scores, weighted total, and letter grade. Align each column in a neat format as shown in the sample output. Suppose that the input data file contains the records of 25 students. Use an array of Student that holds 25 objects. In the main function, the program reads from the data file and calls member functions of class Student to set member variables and output the results. The hw2data.txt file can be downloaded separately. Assume all the data are valid.

Explanation / Answer

student.cpp :

#include<iostream.h>

#include<fstream.h>

#include<conio.h>

#include<string.h>

class Student

{

private:

int ID;

char firstName[20];

char lastName[20];

int scores[5];

public:

Student(){

ID = 0 ;

strcpy(firstName,"");

strcpy(lastName,"");

for(int i=0;i<5;i++){

scores[i] = 0;

}

}

Student(int id,char fn[],char ln[],int sc[]){

setID(id);

setFName(fn);

setLName(ln);

setScores(sc);

}

void setID(int id){

ID = id;

}

void setFName(char fn[]){

strcpy(firstName,fn);

}

void setLName(char ln[]){

strcpy(lastName,ln);

}

void setScores(int sc[]){

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

scores[i] = sc[i];

}

int getID(){

return ID;

}

char* getFName(){

return firstName;

}

char* getLName(){

return lastName;

}

float getWeightedTotal(){

float total = 0;

total += (25*scores[0])/100 + (25*scores[1])/100 + (30*scores[2])/100 + (10*scores[3])/100 + (10*scores[4])/100;

return total;

}

char getGrade(){

char grade = '';

float wt = getWeightedTotal();

if(wt<=100 && wt>=90)

grade = 'A';

else if(wt<90 && wt>=80)

grade = 'B';

else if(wt<80 && wt>=70)

grade = 'C';

else if(wt<70 && wt>=60)

grade = 'D';

else if(wt<60 && wt>=0)

grade = 'F';

return grade;

}

void printStudent(){

cout<<getID()<<" ";

char *f = getFName();

char *l = getLName();

cout<<f<<" "<<l<<" ";

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

cout<<scores[i]<<" ";

cout<<getWeightedTotal()<<" "<<getGrade()<<endl;

}

};

int main(){

clrscr();

Student s[10];

int ID;

char fName[20];

char lName[20];

int scores[5];

ifstream infile;

infile.open("hw2data.txt");

cout<<"SID SName MidScore FinalScore homeWorkScore labScore quizScore Total Grade"<<endl;

cout<<"____________________________________________________________________________"<<endl;

for(int i=0;i<10;i++){

infile>>ID;

infile>>fName;

infile>>lName;

for(int j=0;j<5;j++)

infile>>scores[j];

s[i] = Student(ID,fName,lName,scores);

s[i].printStudent();

}

getch();

return 0;

}

hw2data.txt :

505 Lakshman Rao 74 82 78 67 89

507 Sai Kumar 73 32 63 42 61

504 Venkatesh Jarjapu 68 46 56 92 84

563 Sravan Kumar 53 93 76 49 77

555 Pavan Varma 95 65 74 88 57

594 Sudheer Kumar 58 92 79 66 90

503 Naveen Gold 97 59 68 75 89

506 Dileep kanakala 38 53 42 63 68

552 Manoj Kumar 67 75 54 87 56

574 Mahesh Sharma 70 58 45 40 83

Sample Output :

SID SName MidScore FinalScore homeWorkScore labScore quizScore Total Grade

____________________________________________________________________________

505 Lakshman Rao 74 82 78 67 89 75 C

507 Sai Kumar 73 32 63 42 61 54 F

504 Venkatesh Jarjapu 68 46 56 92 84 61 D

563 Sravan Kumar 53 93 76 49 77 69 D

555 Pavan Varma 95 65 74 88 57 74 C

594 Sudheer Kumar 58 92 79 66 90 75 C

503 Naveen Gold 97 59 68 75 89 73 C

506 Dileep kanakala 38 53 42 63 68 46 F

552 Manoj Kumar 67 75 54 87 56 63 D

574 Mahesh Sharma 70 58 45 40 83 56 F

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote