1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
//-----------------------------------------------------------------------
//--------------------------Class Definition-----------------------------
//-----------------------------------------------------------------------
class Student{
static int cnt;
char stdname[40];
int Admno;
char ClassSection[4];
char Phone[10];
char Stream[10];
char Address[50];
public:
void GetData();
int GetAdmno()
{return Admno;}
void ShowName()
{puts(stdname);}
void ShowAdmno()
{cout<<Admno;}
void ShowClass()
{puts(ClassSection);}
void ShowPhone()
{puts(Phone);}
void ShowStream()
{puts(Stream);}
void ShowAddress()
{puts(Address);}
}s;//End of Class Definition
void Student::GetData(){
cout<<"\nEnter Student Name:\t";
gets(stdname);
cout<<"\nEnter Admission Number:\t";
cin>>Admno;
cout<<"\nEnter Class and Section (Format - '<Class in Roman Numerals)>-<Section in Caps>':\t";
gets(ClassSection);
cout<<"\nEnter Stream:\t";
gets(Stream);
cout<<"\nEnter Phone Number:\t";
gets(Phone);
cout<<"\nEnter Address:\t";
gets(Address);
}//End of GetData
//----------------------------------------------------------------------
//-----------------------------Login------------------------------------
//----------------------------------------------------------------------
int Login(){
clrscr();
//Variables
char newpass[20];
char checkpass[20];
int cnt=-1;
cout<<"\nLogin Menu -> Login";
|
ifstream ReadFile("pass.txt",ios::in);//DECLARE INPUT STREAM
while(!ReadFile.eof())
{
cnt++;
}
ReadFile.close();
if(cnt==-1){//Create A Password, if it doesn't exist yet.
ofstream WriteToFile("pass.txt",ios::out);
cout<<"\nYou haven't set the password yet. Please set it now.";
cout<<"\nEnter a New Password (Maximum of 20 characters)";
gets(newpass);
for(int i=0;i!='\0';i++)
{
WriteToFile<<newpass[i];
}
WriteToFile.close();
return 1;
}//PASSWORD CREATED!
cout<<"Enter Password:\t";
gets(newpass);
int i=0;
ReadFile.open("pass.txt",ios::in);
while(ReadFile){
ReadFile.get(checkpass[i]);
i++;
}
ReadFile.close();//CLOSE STREAM
if(strcmp(checkpass,newpass)==0)
return 1;
else
{
cout<<"\nWrong Password. Returning to Main Menu.\n";
return 0;
}
}
//----------------------------------------------------------------------
//------------------------------Main Menu-------------------------------
//----------------------------------------------------------------------
int MainMenu(){//Function for Main Menu. Returns the choice made by the user.
//Declaration of Variables
int MMC;
clrscr();
cout<<"\n\t\t\tMENU\n"; //Menu Choices
cout<<"\n0.Exit";
cout<<"\n1.Access Basic Student Details.";
cout<<"\n****--***- Following Options Require Admin Rights -***--****";
cout<<"\n2.Access All Student Details.";
cout<<"\n3.Add A Record";
cout<<"\n4.Update A Record";
cout<<"\n5.Make a new Database (This will DISCARD the current Database!)";
cout<<"\n\n\t\tEnter your choice: \t";//Ask user to enter choice.
cin>>MMC;//Choice entered by user
/*if(MMC<1||MMC>5)//Error displayed if wrong choice is entered.
cout<<"\n\aYou have entered a wrong choice!"
else
*/
return MMC;//Choice made is returned to Main()
}
//----------------------------------------------------------------------
//--------------------------Main()--------------------------------------
//----------------------------------------------------------------------
void main(){
/*
List of Variables in Main()
Continue - Variable to control the while loop for menu.
LoginChoice - To check if the user wants to login or not.
MainMenuChoice - Choice for the main menu.
Rights - To check if the user has entered password or not.
*/
//Declaration Of Variables
//INT TYPE
int Rights=0,MainMenuChoice,SkipLogin=0;
//CHAR TYPE
char LoginChoice='y';
//End of Declaration Of Variables
//Main Loop
while(1){
clrscr();
cout<<"\nWelcome to the Main Menu!\n";
//User-Login
if(Rights==0&&SkipLogin!=1){
cout<<"\nDo you want to login? (Y-Yes | N-No | X-No and don't ask me again.)\n";
cin>>LoginChoice;
if(LoginChoice=='x'||LoginChoice=='X')
SkipLogin=1;
if(LoginChoice=='y'||LoginChoice=='Y')
Rights=Login();
}//End of User-Login Menu
MainMenuChoice=MainMenu();//Fuction to call main menu.
switch(MainMenuChoice){
case 1 : BasicInfo();
break;
case 2 : Info(Rights);
break;
case 3 : AddInfo(Rights);
break;
case 4 : UpdateInfo(Rights);
break;
case 5 : NewDB();
break;
case 0 : exit(1);
break;
default: cout<<"\nWrong Choice... Please select the right option.\n";
}//End of Switch
}// END OF WHILE LOOP
}//End Of Main() |