Hey? Can someone help me to this program? I need to Search an specific information of a student.
#include<iostream>
#include<fstream>
#include<istream>
#include<stdlib.h>
#include<string>
using namespace std;
void login(),registr(),form(),Add(),ShowList(),Search(),Update();
struct Student
{
int id;
char name[25];
char name1[25];
char address[25];
char city[25];
int age;
char gender[5];
string email;
string contact;
char course[25];
char gname[25];
char gname1[25];
};
Student s;
int main()
{
system("cls");
int o;
m:
cout<<"Admission System"<<endl;
cout<<"1. Login"<<endl;
cout<<"2. Register"<<endl;
cout<<"3. Log Out"<<endl;
cout<<endl;
cout<<"Enter operation: ";
cin>>o;
switch(o)
{
case 1:
{
login();
break;
}
case 2:
{
registr();
break;
}
case 3:
{
exit(0);
break;
}
default:
{
goto m;
}
}
}
void login() //Login Form
{
system("cls");
string user,pass,u,p;
int count=0; //Stand as a true or false
for(int x=0;x<3;x++)
{
system("cls");
cout<<"Username : ";
cin>>user;
cout<<"Password : ";
cin>>pass;
ifstream input("adminlogin.txt");
while(input>>u>>p)
{
if(u==user&&p==pass)
{
count=1; //True
}
}
if(count==1)
{
system("cls");
cout<<"Access Granted...";
cin.get();
cin.get();
form();
break;
}
system("cls");
cout<<"Access denied...";
cin.get();
cin.get();
}
}
void registr() //Registration Form
{
system("cls");
string reguser,regpass,ru,rp;
cout<<"New Username : ";
cin>>reguser;
cout<<"New Password : ";
cin>>regpass;
ofstream reg("adminlogin.txt",ios::app);
reg<<reguser<<" "<<regpass<<endl;
cout<<"Account has been registered...";
cin.get();
cin.get();
login();
}
void form()
{
system("cls");
int o;
cout<<"Admission Form"<<endl;
cout<<"1. Add Student"<<endl;
cout<<"2. Show List of Student"<<endl;
cout<<"3. Search Student"<<endl;
cout<<"4. Update Student"<<endl;
cout<<"5. Log Out"<<endl;
cout<<"Enter operation: ";
cin>>o;
switch(o)
{
case 1:
{
Add();
break;
}
case 2:
{
ShowList();
break;
}
case 3:
{
Search();
break;
}
case 4:
{
Update();
break;
}
case 5:
{
exit(0);
break;
}
}
}
void Add()
{
system("cls");
cout<<"\n\tEnter student ID : ";
cin>>s.id;
cout<<"\n\tEnter student first name : ";
cin>>s.name;
cout<<"\n\tEnter student last name : ";
cin>>s.name1;
cout<<"\n\tEnter address : ";
cin>>s.address;
cout<<"\n\tEnter City : ";
cin>>s.city;
cout<<"\n\tEnter Age : ";
cin>>s.age;
cout<<"\n\tEnter Gender : ";
cin>>s.gender;
cout<<"\n\tEnter Email : ";
cin>>s.email;
cout<<"\n\tEnter Contact Number : ";
cin>>s.contact;
cout<<"\n\tEnter Course : ";
cin>>s.course;
cout<<"\n\tGuardians First Name : ";
cin>>s.gname;
cout<<"\n\tGuardians Last Name : ";
cin>>s.gname1;
ofstream sdata;
sdata.open("studentxp.txt", ios::app);
sdata<<endl;
sdata<<s.id;
sdata<<endl;
sdata<<s.name;
sdata<<endl;
sdata<<s.name1;
sdata<<endl;
sdata<<s.address;
sdata<<endl;
sdata<<s.city;
sdata<<endl;
sdata<<s.age;
sdata<<endl;
sdata<<s.gender;
sdata<<endl;
sdata<<s.email;
sdata<<endl;
sdata<<s.contact;
sdata<<endl;
sdata<<s.course;
sdata<<endl;
sdata<<s.gname;
sdata<<endl;
sdata<<s.gname1;
sdata<<endl;
sdata<<endl;
sdata.close();
}
void ShowList()
{
ifstream dataFile("studentxp.txt");
dataFile>>s.id;
dataFile>>s.name;
dataFile>>s.name1;
dataFile>>s.address;
dataFile>>s.city;
dataFile>>s.age;
dataFile>>s.gender;
dataFile>>s.email;
dataFile>>s.contact;
dataFile>>s.course;
dataFile>>s.gname;
dataFile>>s.gname1;
while (!dataFile.fail() && !dataFile.eof() )
{
cout<<"\n\n\tStudent ID is : "<<s.id;
cout<<"\n\tStudent Name : "<<s.name<<" "<<s.name1;
cout<<"\n\tStudent Address : "<<s.address;
cout<<"\n\tCity : "<<s.city;
cout<<"\n\tAge : "<<s.age;
cout<<"\n\tGender : "<<s.gender;
cout<<"\n\tEmail : "<<s.email;
cout<<"\n\tContact Number : "<<s.contact;
cout<<"\n\tCourse : "<<s.course;
cout<<"\n\tGuardian's Name : "<<s.gname<<" "<<s.gname1;
dataFile>>s.id;
dataFile>>s.name;
dataFile>>s.name1;
dataFile>>s.address;
dataFile>>s.city;
dataFile>>s.age;
dataFile>>s.gender;
dataFile>>s.email;
dataFile>>s.contact;
dataFile>>s.course;
dataFile>>s.gname;
dataFile>>s.gname1;
}
}
void Search()
{
int id;
string name,name1;
ifstream searchs;
searchs.open("studentxp.txt");
searchs>>id>>name>>name1;
searchs.close();
int sid;
cout<<"Search ID : ";
cin>>sid;
if(!searchs.eof()&&sid==id)
{
cout<<id<<name<<name1;
}
}
void Update()
{
}