#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <iomanip>
#include <string>
using namespace std;
const int MAX_SIZE = 60;
void discard_line(ifstream &in);
void print_student_records(structarray[], double scmarks[], double sfmarks[], int size) ;
int main()
{
string id[MAX_SIZE];
double cmarks[MAX_SIZE];
double fmarks[MAX_SIZE];
//char grade[MAX_SIZE];
int choice;
char response;
int total_records;
ifstream infile;
cout << "This program shows student's grade."<< endl;
cout<<endl;
infile.open("studentData.txt");
//check for error
if(infile.fail())
{
cerr<<"Error opening file" << endl;
system ("PAUSE");
exit(1);
}
discard_line(infile);
total_records = 0;
while(infile>>id[total_records]>>cmarks[total_records] >> fmarks[total_records])
{
total_records++;
}
infile.close();
print_student_records(id,cmarks,fmarks,total_records);
system ("PAUSE");
return 0;
}
void print_student_records(string sID[], double scmarks[], double sfmarks[], int size)
{
cout<<"\n\nstudentID\tcoursework\tFinal exam"<<endl<<endl;
for(int i = 0; i < size; i++)
{
cout<<sID[i]<<"\t\t"<<scmarks[i]<<"\t\t"<<sfmarks[i]<<endl;
}
cout<<endl;
}
void discard_line(ifstream &in)
{
char c;
do
in.get(c);
while (c!='\n');
}
how can i store data in a array of struct. i am confuse because i don't know how to use it in function??
Thanks