I have it almost finished. But i cant figure out how to Average the GPA of the Records that the user inputs. Heres my Code.. I would appreciate some help.
The GPA is in a Structure, And i enter different records. And im not exactly sure how Average out each records GPA..
I need to Average the GPa from all the records that the user Creates. And i cant figure out how? I probably have to do it somewhere in the File that i output it to, Which is still am not sure how to do, I would appreciate some help, Not looking for Exact code or whatnot, just dont know where to start. Thanks.
//
//CSC250 Sec1
//
// This program allows the user to enter in there own records, and edit + view them again.
#include<iostream>
#include <cstring>
#include <iomanip>
#include <fstream>
using namespace std;
//Stucture for the information in a file.
const int SIZE = 40;
struct Recordinfo
{
char name[SIZE];
int idnum;
float gpa;
};
//Function Prototypes
void CreateRecords(fstream &stud);
void UserInfo(fstream &stud);
void ShowRecords(fstream &stud);
void Findgpa(fstream &stud);
int main()
{
fstream stud;
//Function Calls.
CreateRecords(stud);
ShowRecords(stud);
UserInfo(stud);
Findgpa(stud);
system("pause");
return 0;
}//main
void CreateRecords(fstream &stud)
{
int go =7;
int i = 0;
Recordinfo Info;
stud.open("student.dat",ios::out | ios::binary);
if(stud.fail())
stud.open("student.data",ios::out | ios::binary);
cout<<"****CREATE A RECORD****"<<endl;
cout<<""<<endl;
do{
cout<<"Please Enter The Person's Name: ";
cin.getline(Info.name,SIZE);
cout<<""<<endl;
cout<<"Please Enter "<< Info.name<<"'s ID #: ";
cin>>Info.idnum;
cout<<""<<endl;
cout<<"Please Enter " <<Info.name <<"'s GPA: ";
cin>>Info.gpa;
cout<<""<<endl;
stud.seekp(0L,ios::end);
stud.write(reinterpret_cast<char *>(&Info),sizeof(Info));
cout<<"Hit 7 to stop entering, Or any other # to keep Enter Records"<<endl;
cin>>go;
cout<<""<<endl;
cin.ignore();
}while(go!=7);
stud.close();
return;
}
void ShowRecords(fstream &stud)
{
stud.clear();
Recordinfo Info;
int go;
int recordnum=0;
int choices;
long size;
int numgpa;
double avggpa;
//Open file for input to screen
stud.open("student.dat",ios::in | ios::binary);
//Test for file Error.
if(!stud)
{
cout << "Error opening file. Program exiting!";
exit(0);
}
do
{
stud.seekg(0L,ios::end);
size =stud.tellg();
recordnum = size/(sizeof(Info));
stud.seekg(0L,ios::beg);
cout<<"There are " <<recordnum<<" files"<<endl;
cout<<""<<endl;
cout<<"Which File would you like to Search For? 0 is File #1...: ";
cin>>choices;
stud.seekg((choices*sizeof(Info)),ios::beg);
stud.read(reinterpret_cast<char *>(&Info),sizeof(Info));
cout<<""<<endl;
cout<<"**************************************"<<endl;
cout<<""<<endl;
cout << "Name :"<<Info.name<<endl;
cout << "ID #:"<<Info.idnum<<endl;
cout << "GPA :"<<Info.gpa<<endl;
cout<<""<<endl;
cout<<"***************************************"<<endl;
cout<<"Would you like to Search for another, Hit 7 for no, any other # for yes:";
cin>>go;
}while (go!=7);
stud.close();
return;
}
void UserInfo(fstream &stud)
{
int more=0;
cout<<""<<endl;
cout<<"Would you Like to ENTER anymore Records?Press 7 If yes:";
cin>>more;
cin.ignore();
if(more ==7)
CreateRecords(stud);
cout<<""<<endl;
return;
}
void Findgpa(fstream &stud)
{
return;
}

New Topic/Question
Reply




MultiQuote




|