Professional Documents
Culture Documents
CPP Data Struct
CPP Data Struct
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <fstream>
struct Student
{
char names [ 16 ];
int other;
};
void createFile();
void mainMenu();
void funcSwitch();
void addRecord();
int displayRecord();
void updateRecord();
void deleteRecord();
void printRecords();
int searchRecord();
//------------------------------------------------------------------------------
int main ( int argc, char* argv [] )
{
createFile();
mainMenu();
}
//------------------------------------------------------------------------------
void mainMenu()
{
cout << "Welcome to School Enrolment System" << endl << endl
<< "Please enter your selection: " << endl
<< "1. Register - New Student (Add record)" << endl
<< "2. Look Up - Existing Student (Display record)" << endl
<< "3. Change Details (Update record)" << endl
<< "4. Remove Student (Delete record)" << endl
<< "5. Show all Students (Print all)" << endl
<< "6. Exit " << endl << endl
<< "Selection: ";
funcSwitch();
}
//------------------------------------------------------------------------------
void funcSwitch()
{
char choice;
choice = getch();
clrscr();
while ( choice != 54 )
{
switch ( choice )
{
case '1' :
addRecord();
getch();
clrscr();
break;
case '2' :
displayRecord();
getch();
break;
case '3' :
updateRecord();
getch();
break;
case '4' :
deleteRecord();
getch();
break;
case '5' :
printRecords();
getch();
break;
case '6' :
break;
default :
cout << choice << " is not a vaild choice" << endl << endl
<< "Press any key to choose again... ";
getch();
clrscr();
}
mainMenu();
choice = getch();
clrscr();
}
}
//------------------------------------------------------------------------------
void addRecord()
{
Student temp;
return 0;
}
//------------------------------------------------------------------------------
int displayRecord()
{
Student temp;
int age;
int position;
if ( age != temp.other )
{
cout << endl << "No record found. Press any key to continue...";
}
else
{
cout << "We found your record: " << endl << endl
<< "Name: " << temp.names << endl
<< "Age: " << temp.other << endl;
}
cout << endl << "Press any key to continue..." << endl;
getch();
clrscr();
mainMenu();
MyFile.close();
return 0;
}
//------------------------------------------------------------------------------
void updateRecord()
{
Student temp;
time_t t;
char choice;
int position;
position = displayRecord ();
if( position != -1 )
{
cout << endl << "Do you want to Update this Record( y or n )";
choice = getch();
}
//------------------------------------------------------------------------------
void deleteRecord()
{
Student temp;
char choice;
int position;
choice = getch();
getch();
clrscr();
mainMenu();
MyFile.close();
}
//-----------------------------------------------------------------------------
void printRecords()
{
Student temp;
while ( ! MyFile.eof() )
{
cout << "Name: " << temp.names << endl
<< "Age: " << temp.other << endl << endl;
cout << endl << "Press any key to continue back to main menu" << endl;
getch();
clrscr();
mainMenu();
MyFile.close();
}
//------------------------------------------------------------------------------
void createFile()
{
if( ! MyFile )
{
MyFile.close();
MyFile.open(FILE_PATH, ios::binary | ios::in | ios::out);
}
if ( ! MyFile )
{
cout << "File Error: File does not exist. Creating new file..."
<< endl << "Click to continue to main menu...";
getch();
clrscr();
}
}