Can someone please help me out with this code... I'm having a very difficult time with this one... so, I was hoping you guys could help me out... Thanks in advance! :D
#include<iostream>
#include <iomanip>
#include <fstream>
using namespace std;
struct record
{
int prelim,midterm,endterm, idnum;
double final;
string subjct[10];
} ;
int LinearSearch(const record Array[], const int Size, const int ValToSearch);
int main()
{
int index=0,searchIndex=0, choice, searchIdnum,numOfSubj;
record loc[40];
ofstream outputFile;
outputFile.open("record.txt");
do
{
system("cls");
system("color A");
cout <<"M A I N M E N U";
cout <<endl;
cout <<"------------------------";
cout <<endl;
cout <<endl;
cout <<"[1] ADD STUDENT";
cout <<endl;
cout <<endl;
cout <<"[2] ADD SUBJECT";
cout <<endl;
cout <<endl;
cout <<"[3] ADD TERM GRADES";
cout <<endl;
cout <<endl;
cout <<"[4] VIEW STUDENT";
cout <<endl;
cout <<endl;
cout <<"[5] VIEW GRADES";
cout <<endl;
cout <<endl;
cout <<"[6] VIEW SUBJECTS";
cout <<endl;
cout <<endl;
cout <<"[7] QUIT";
cout <<endl;
cout <<endl;
cout <<"------------------------";
cout <<endl;
cout <<endl;
cout <<"Your choice is: ";
cin >>choice;
cout <<endl;
system("pause");
system("cls");
if (choice==1)
{
cout <<endl <<endl;
cout <<"A D D S T U D E N T";
cout <<endl;
cout <<"------------------------------";
cout <<endl;
cout <<endl;
cout <<"Enter ID #: ";
cin >>loc[index].idnum;
index++;
cout <<endl;
cout <<endl;
cout <<endl;
system("pause");
system("cls");
}
if (choice==2)
{
cout <<endl <<endl;
cout <<"A D D S U B J E C T";
cout <<endl;
cout <<"------------------------------";
cout <<endl;
cout <<endl;
cout <<"Enter ID number: ";
cin >>searchIdnum;
searchIndex = LinearSearch(loc, index, searchIdnum);
if(searchIndex>-1)
{
cout<<"How many subjects would you like to enter? ";
cin>>numOfSubj;
cout<<endl;
for(int i=0; i<numOfSubj; i++)
{
cout<<"Enter subject: ";
cin>>loc[searchIndex].subjct[i];
cout<<endl;
}
}
else
{
cout <<"ID number not found...";
cout <<endl;
cout <<"Please try again...";
cout <<endl;
cout <<endl;
cout <<endl;
}
system("pause");
system("cls");
cout <<endl;
cout <<endl;
}
if (choice==3)
{
cout <<endl <<endl;
cout <<"A D D T E R M G R A D E S";
cout <<endl;
cout <<"-----------------------------------------";
cout<<endl;
cout <<endl;
cout <<"Enter ID number: ";
cin >>searchIdnum;
searchIndex=LinearSearch(loc, index, searchIdnum);
if (searchIndex>-1)
{
cout <<endl;
cout <<endl;
cout <<"Enter prelim grade: ";
cin >>loc[searchIndex].prelim;
cout <<endl;
cout <<"Enter midterm grade: ";
cin >>loc[searchIndex].midterm;
cout <<endl;
cout <<"Enter endterm grade: ";
cin >>loc[searchIndex].endterm;
cout <<endl;
loc[searchIndex].final= loc[searchIndex].prelim*.30+loc[searchIndex].midterm*.30+loc[searchIndex].endterm*.40;
cout <<"Final Grade: ";
cout <<loc[searchIndex].final;
cout <<endl;
cout <<endl;
}
else
{
cout <<"ID number not found...";
cout <<endl;
cout <<"Please try again...";
cout <<endl;
cout <<endl;
}
system("pause");
system("cls");
}
if (choice==4)
{
cout <<endl <<endl;
cout <<"V I E W S T U D E N T";
cout <<endl;
cout <<"---------------------------------";
cout <<endl;
cout <<endl;
cout <<"Enter ID number: ";
cin >>searchIdnum;
searchIndex=LinearSearch(loc, index, searchIdnum);
if (searchIndex>-1)
{
cout <<endl;
cout <<endl;
cout <<"ID number: " <<loc[searchIndex].idnum;
cout <<endl;
cout <<endl;
cout<<"Subjects: "<<endl;
for(int i=0; i<10; i++)
cout <<"\t"<<loc[searchIndex].subjct[i]<<endl;
cout <<endl;
cout <<"Prelim grade: " <<loc[searchIndex].prelim;
cout <<endl;
cout <<endl;
cout <<"Midterm grade: " <<loc[searchIndex].midterm;
cout <<endl;
cout <<endl;
cout <<"Endterm grade: " <<loc[searchIndex].endterm;
cout <<endl;
cout <<endl;
cout <<"Final grade: " <<loc[searchIndex].final;
cout <<endl;
cout <<endl;
cout <<endl;
}
else
{
cout <<"ID number not found...";
cout <<endl;
cout <<"Please try again...";
cout <<endl;
cout <<endl;
}
system("pause");
system("cls");
}
if (choice==5)
{
cout <<endl <<endl;
cout <<"V I E W G R A D E S";
cout <<endl;
cout <<"-------------------------------";
cout <<endl;
cout <<endl;
cout <<"Enter ID number: ";
cin >>searchIdnum;
searchIndex=LinearSearch(loc, index, searchIdnum);
if (searchIndex>-1)
{
cout <<endl;
cout <<endl;
cout <<"Prelim grade: " <<loc[searchIndex].prelim;
cout <<endl;
cout <<endl;
cout <<"Midterm grade: " <<loc[searchIndex].midterm;
cout <<endl;
cout <<endl;
cout <<"Endterm grade: " <<loc[searchIndex].endterm;
cout <<endl;
cout <<endl;
cout <<"Final grade: " <<loc[searchIndex].final;
cout <<endl;
cout <<endl;
cout <<endl;
}
else
{
cout <<"ID number not found...";
cout <<endl;
cout <<"Please try again...";
cout <<endl;
cout <<endl;
cout <<endl;
}
system("pause");
system("cls");
}
if (choice==6)
{
cout <<endl;
cout <<endl;
cout <<"V I E W S U B J E C T S";
cout <<endl;
cout <<"------------------------------------";
cout <<endl;
cout <<endl;
cout <<"Enter ID number: ";
cin >>searchIdnum;
searchIndex=LinearSearch(loc, index, searchIdnum);
if (searchIndex>-1)
{
cout <<endl;
cout <<endl;
cout<<"Subjects: "<<endl;
for(int i=0; i<10; i++)
cout <<"\t"<<loc[searchIndex].subjct[i]<<endl;
cout <<endl;
cout <<endl;
}
else
{
cout <<"ID number not found...";
cout <<endl;
cout <<"Please try again...";
cout <<endl;
cout <<endl;
cout <<endl;
}
system("pause");
system("cls");
}
if (choice==7)
{
cout <<endl;
cout <<endl;
cout <<"Thank you for using this program...";
cout <<endl;
cout <<endl;
cout <<endl;
system("pause");
system("cls");
cout <<endl;
cout <<endl;
cout <<"Good bye!";
cout <<endl;
cout <<endl;
cout <<endl;
return 0;
}
for(int i=0; i<index; i++)
{
outputFile<<loc[index].idnum<<endl;
for(int a=0; a<10; a++)
outputFile<<loc[index].subjct[a]<<endl;
outputFile<<"HI";
outputFile<<loc[index].prelim<<endl;
outputFile<<loc[index].midterm<<endl;
outputFile<<loc[index].endterm<<endl;
outputFile<<loc[index].final<<endl;
}
outputFile.close();
}while(choice!=7);
}
int LinearSearch(const record Array[], const int Size, const int ValToSearch)
{
bool NotFound = true;
int i = 0;
while(i < Size && NotFound)
{
if(ValToSearch != Array[i].idnum)
i++;
else
NotFound = false;
}
if( NotFound == false )
return i;
else
return -1;
}