Here is my code:
//Preprocessor Directives
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <fstream>
using namespace std;
//Global Variables
ifstream fin;
struct studentType{
string name[2];
int scores[6];
};
//Function Prototypes
void headerfn();
void inputfn(studentType it210[40], int counter);
void outputfn(studentType it210[40],int counter);
//Function Definitions
int main()
{
//Background Color Change
system("color f0");
//Function Call
headerfn();
//Declarations
studentType it210[40];
int counter = 0;
string filename;
//Input File Command
cout << "Please enter an input filename: ";
cin >> filename;
cout << endl;
fin.open(filename.c_str());
//Input File Error Check
if(!fin){
cout << "Input Failure!" << endl << endl;
system("pause");
return 1;
}//end of error check
cout << "Filename: (" << filename << ") has been validated" << endl << endl;
cout << "Press any key to perform calculations";
getch();
system("cls");
inputfn(it210, counter);
outputfn(it210, counter);
cout << "Number of records = " << counter << endl;
cout << "\n" << endl;
system("pause");
}//End of Main
//*************************************************************************
//Header Function
//*************************************************************************
void headerfn(){
cout << "_________________________________________________"
<< endl << endl;
cout << " C++ "
<< endl;
cout << " Student Grades "
<< endl << endl;
cout << "_________________________________________________"
<< endl << endl;
}//End of headerfn
//*************************************************************************
//Input Function
//*************************************************************************
void inputfn(studentType it210[40], int counter){
while(fin&&counter<40){
for(int col=0; col<2; col++)
fin >> it210[counter].name[col];
for(int col = 0; col < 6; col++)
fin >> it210[counter].scores[col];
counter++;
if(fin.peek()=='n')fin.ignore();
}//end of while loop
}//end of input function
//*************************************************************************
//Output Function
//*************************************************************************
void outputfn(studentType it210[40],int counter){
cout << fixed << showpoint << left << setprecision(2);
for(int row = 0; row < counter; row++){
cout << setw(25) << it210[row].name[0] + " " + it210[row].name[1];
for(int col = 0; col < 6; col++)
cout << setw(5) << it210[row].scores[col];
cout << endl;
}//end of outer for loop
}//end of outputfn
This post has been edited by WELA: 28 April 2008 - 01:44 PM

New Topic/Question
Reply




MultiQuote








|