Hello guys.. I have this tutorial that i keep getting errors on no matter what i've tried.. Would someone kindly check it out for me?!
Here is the question:
Q1:- Write a program that reads students’ names followed by their test score. The program should output each student’s name followed by the test score and relevant grade. It should also find and print the highest test score and the name of the student having the highest test score
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( testScore is between 0 and 100 ) and grade of type char. Suppose that the class has 20 students. Use an array of 20 components to type StudentType
Your program should contain the following function:
1. A function to read the student’s data into the array
2. A function to assign the relevant grade to each student
3. A function to find the highest score
4. A function to print the names of students having the highest test score
Here is my code:
# include <iostream>
# include <string>
using namespace std;
struct StudentType
{
string studentFname;
string studentLname;
int testscore ;
char grade;
};
//to read the student data into an array
void read_student_class(struct student_class[], int class_size);
//to assign the relevant grade to each student
void relevant_grade(int grade);
//to find the highest score
int highest_score( struct student_class[], int class_size);
// a function to print the highest test score
void Print_Highest_score(struct the_highest);
int main ()
{
student_data csclass[20];
int n;
cout<<"Please enter the students' first and last name followed by their test score.";
read_student_class(csclass[], 20);
n = highest_score (csclass[], 20);
//then we print the data of all the class
for (int j=0; j<20; j++)
{
cout<< csclass [j].studentFname
<< csclass [j].studentLname
<< csclass [j].testscore
<< csclass [j].grade;
}
Print_Highest_score(csclass[n]);
return 0;
}
//to read the student data into an array
void read_student_class(struct student_class[], int class_size)
{
for(int i=0; i<20; i++)
{
cin>>csclass[i].studentFname
>>csclass[i].studentLname
>>csclass[i].testscore;
relevant_grade(student_class[i].grade);
}
//to assign the relevant grade to each student
void relevant_grade(char grade)
{
if (testscore >= 90)
grade='A';
if ((testscore >=80) && (testscore < 90)
grade='B';
if ((testscore >=70) && (testscore < 80)
grade='C';
if ((testscore >=60) && (testscore < 70)
grade='D'
}
//to find the highest score
int highest_score( struct student_class[], int class_size)
{
int n;
int max=0;
for(int i=0; i<20 ; i++)
{
if (max < csclass[i].testscore)
max = csclass[i].testscore;
}
cout<<"The highest score is: "<<max
<<csclass[n].studentFname
<<csclass[n].studentLname;
return n;
}
// a function to print the highest test score
void Print_Highest_score(struct the_highest)
{
cout << the_highest.studentFname << the_highest.studentLname << the_highest.score << the highest.grade <<endl;
}