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;
}

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:

# include <iostream>
# include <string>
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);
}

Mismatched braces here for starters.

Also, you never explicitly typedef student_data as StudentType.

And why are you passing in something called student_class to your functions and then trying to use something called cscclass which is not in scope within your function? Take a few minutes and read your text section on variable scope.

There are other errors, but just start knocking them out one by one. The scope issues are the major ones.

oh that a complete silly mistake!
But guess what!! i have 32 errors now not 19 !!
I thought they wouled lessen -__-

As to your explanation about passing something to something.. I didn't really understand this.

Oh I've just detected one!
at line 31..

int main ()
{

StudentType csclass[20];

==================
please poeople elp me with detecting errors.

In your read_student class above you are passing in a struct and an int. Instead of saying struct pass in an object of type student_data called cscclass so you don't have to change all your functions all around(and still pass in the int of course). It often happens that you uncover more errors when you fix one. Keep at it and when you get completely stuck post back.

ahaa.. I don't know this is the way my instructor taught me..
Aww.. and i'm stuck by the way! I have no clue what to do..
I guesss I'll just submitt it as it is.
Thanks for your help.

How did your instructor teach it to you? It's just a matter that variables used within a function are invisible in other functions. When defining a function (e.g. void myfunc(int param1, int param2) ) the variables names in the parameters are the ones used in the functions. So when you are defining cscclass in main and attempting to use it in your function, there is no such variable. It looks like you are trying to pass a struct in but your syntax is incorrect and the name of the struct that you are passing in is not cscclass.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.