I finally figured that sub-code out(with some hints from others)..For those who do not know, this is a simple way to read an input file containing scores for 3 exams(in this case, of 6 students), and output the highest in each exam...
//Sample Program 12- A non-interactive program to calculate student grades.
//************************************...
#include%26lt;iostream%26gt;
#include%26lt;iomanip%26gt;
#include%26lt;fstream%26gt;
#include%26lt;string%26gt;
using namespace std;
const int SIZE=6;
int GetHighValue(int array[]);
int main()
{
int exam1Array[SIZE];
int exam2Array[SIZE];
int exam3Array[SIZE];
int i=0;
string name;
ifstream inFile;
inFile.open("grades.dat");
if(!inFile)
{
cout%26lt;%26lt;"Unable to open input file, program abnormally ended";
return 1;
}
for(i=0; i%26lt;SIZE; i++)
{
inFile%26gt;%26gt;name%26gt;%26gt;exam1Array[i]%26gt;%26gt;exam2Array[...
}
GetHighValue(exam1Array);
cout%26lt;%26lt;"The highest for exam 1 is"%26lt;%26lt;GetHighValue(exam1Array)%26lt;%26lt;endl;
GetHighValue(exam2Array);
cout%26lt;%26lt;"The highest for exam 2 is"%26lt;%26lt;GetHighValue(exam2Array)%26lt;%26lt;endl;
GetHighValue(exam3Array);
cout%26lt;%26lt;"The highest for exam 3 is"%26lt;%26lt;GetHighValue(exam3Array)%26lt;%26lt;endl;
return 0;
}
int GetHighValue(/*in*/ int array[])
{
int highScore=0;
int i=0;
for(i=0; i%26lt;SIZE; i++)
{
if(array[i]%26gt;highScore)
highScore=array[i];
}
return highScore;
}
C++ update....?
You might want to retry the example code using STL library. It is amazing how easy it is to write over 60% of the code using C++ standard libraries.
It might not be so obvious in this small example, but as you move to bigger projects, you will see the benefit first hand.
Reply:sorry, i don't know, but you can try this site
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment