This program gets ID marks from a txt file and determines grade. how to pass the void print_students_records function.



#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>

using namespace std;

const int MAX_SIZE = 10;

class student{
public:
string id;
int marks;
char grade;
};
char determine_grade(int smarks);
void discard_line(ifstream &in);
void print_students_records(string s[],int size);

int main(){

student s[MAX_SIZE];
int total_records;
int choice;
char response;

ifstream input;
cout<<"This program determines the grades of students."<<endl;

input.open("students.txt",ios::in);

if(!input){
cerr<<"File could not be opened"<<endl;
system("PAUSE");
exit(1);
}

discard_line(input);

total_records = 0;

while(input>>s[total_records].id>>s[total_records].marks){
total_records++;

}

for (int i = 0; i < total_records; i++){
s[i].marks = determine_grade(s[i].marks);
}

input.close();


print_students_records(s,total_records);
// what do I have to pass as parameters to make the program work

system("PAUSE");
return 0;
}
void print_students_records(student s[],int size){
cout<<"\n\nstudents' records"<<endl<<endl;
for (int i = 0; i < size; i++){
cout<<"id: "<<s[i]<<", marks: "<<s[i]<<", grade: "<<s[i]<<endl;
}
cout<<endl;
}


char determine_grade(int smarks){
char sgrade;

if (smarks >= 80)
sgrade = 'A';
else if(smarks >= 65)
sgrade = 'B';
else if(smarks >= 50)
sgrade = 'C';
else
sgrade = 'D';

return sgrade;
}

void discard_line(ifstream &in)
{
char c;

do
in.get(c);
while (c!='\n');
}
1
2
3
4
void print_students_records(string s[],int size);

student s[MAX_SIZE];
print_students_records(s,total_records);
The function ask for an array of string, ¿why are you passing an array of students?
Topic archived. No new replies allowed.