can you guys help me out i dont know any of the c++ functions and i dont know how to convert this tnx in advance
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
struct student
{
char fname[100];
char lname[100];
int id;
float cgpa;
};
int add( student * , int &);
void displayStudents( student *, int);
void save(student *, int);
void load( student *, int &);
int main(int argc, char *argv[])
{
char x;
student info [200 ];
int numOfStudents = 0;
do
{
cout <<"============================\n";
cout <<" Menu \n";
cout <<"============================\n";
cout <<endl;
cout <<"={1}= Add a new student.\n";
cout <<"={2}= Display all\n";
cout <<"={3}= Save\n";
cout <<"={4}= Load\n";
cout <<"={5}= Exit\n";
cout <<"============================\n";
cout <<"Your Choice: ";
cin >>x;
switch ( x )
{
case '1' : add( info , numOfStudents );
break;
case '2' : displayStudents( info , numOfStudents);break;
case '3' : save( info, numOfStudents);break;
case '4' : load( info, numOfStudents);break;
case '5' : ;break;
default : cout <<"Invalid Choice\n";
}
}while ( x != '5' );
system("PAUSE");
return 0;
}
//================================================== ===
//================================================== ==========
// Add a new student to the database
int add(student * info , int & numOfStudents )
{
if( numOfStudents < 200 )
{
cout << "Enter student's first name: ";
cin >>info[numOfStudents].fname;
cout << "Enter student's second name: ";
cin >>info[numOfStudents].lname;
cout <<"Enter the student id: ";
cin >> info[numOfStudents].id;
cout << "Enter the student CGPA: ";
cin >> info[numOfStudents].cgpa;
numOfStudents++;
}
else
{
cout << "No more room in array!" << endl;
}
return 0;
}
//===============================[ display ]=======================
void displayStudents( student * studentArray , int numOfStudents )
{
int index = 0;
while ( index < numOfStudents )
{
cout << "Name: "<< studentArray [ index ].fname << " " << studentArray [ index ].lname << endl;
cout << "ID: " << studentArray [ index ].id << endl;
cout << "CGPA: "<< studentArray [ index ].cgpa << endl;
index++;
}
}
//========================[ save ]=============================
void save( student * info, int numOfStudents)
{
int index = 0;
ofstream fout;
fout.open("datab.txt");
fout << numOfStudents << endl;
for( ; index < numOfStudents; ++index)
{
fout << info [ index ].fname << " " << info [ index ].lname << ' ' <<info [ index ].id << ' ' << info [ index ].cgpa << endl;
}
fout.close();
}
//=======================[load]=================================
void load( student * info, int & numOfStudents)
{
ifstream fin;
fin.open("datab.txt");
fin >> numOfStudents;
int index = 0;
while(index < numOfStudents)
{
fin >> info [ index ].fname >> info [ index ].lname >> info [ index ].id >> info [ index ].cgpa;
index++;
}
fin.close();
}