* this is the actual code the other one was something else sorry
this is what i need help on
#include <iostream>
#include <iomanip>
#include<fstream>
using namespace std;
const int size=20;
struct studentType
{
string firstname[size];
string lastname[size];
int testscore[size];
char lettergrade[size];
}
void print(studentType firstname[], studentType lastname[],studentType testscore[],studentType lettergrade[]);
void init(studentType firstname[], studentType lastname[], studentType testscore[], ifstream& infile);
void letgrade(studentType testscore[], studentType lettergrade[]);
void testhi(studentType firstname[],studentType lastname[],studentType testscore[]);
int main()
{
ifstream infile;
infile.open("e:\\input.txt");
init(firstname, lastname, testscore,infile);
letgrade(testscore, lettergrade);
print(firstname, lastname, testscore,lettergrade);
testhi(firstname, lastname, testscore);
return 0;
}
void init(studentType firstname[], studentType lastname[], studentType testscore[], ifstream& infile)
{
for(int i=0;i<size;i++)
{
infile>>studentType.firstname[i]>>studentType.lastname[i]>>studnetType.testscore[i];
if(testscore>100||testscore<0)
cout<<studentType.firstname[i]<<" "<<studentType.lastname[i]<<"invalid test score"<<endl;
}
}
void letgrade(studentType testscore[], studentType lettergrade[])
{
for(int i=0;i<size;i++)
{
if(studentType.testscore>=90)
studentType.lettergrade[i]='a';
else if(studentType.testscore>=80)
studentType.lettergrade[i]='b';
else if(studentType.testscore>=70)
studentType.lettergrade[i]='c';
else if(studentType.testscore>=60)
studentType.lettergrade[i]='d';
else
studentType.lettergrade[i]='f';
}
}
void testhi(studentType firstname[],studentType lastname[],studentType testscore[])
{
string highstudentf;
string highstudentl;
int highscore=0;
for(int i=0;i<size;i++)
{
if (highscore<studentType.testscore[i])
{
highscore= studentType.testscore[i];
highstudentf=studentType.firstname;
highstudentl=studentType.lastname;
}
}
cout<<setw(10)<<"student with high score is "<<highstudentf<<" "<<highstudentl<<" "<<highscore<<endl;
}
Last edited on
how do i put that in my code though
That was an illustrative piece of code to show you how to start solving your problem. We don't give out homework answers here :)
i figured it out...
but do i put that in main or in the struct part thats what i was askin
in my main it says that my variables are undeclared ..
is that wrong too or will that fix when i fix everything else
how would i go about doing that