I am doing my c++ program on hospital data base management. I have users of type admins,hospitals,doctors and patients. Each have their own username and passwords. I used files in order to maintain data base. It does not enter if the user name and passwords does'nt match. But my problem is that its not going even though correct username and passwords are being entered. There is something wrong with my logical function that checks the username and the password. The fuction used is:
int login_check(char usr[],char pwds[])
{
if((strcmp(usr,pat_id)==0)&&(strcmp(pwds,pat_pwd)==0))
{
return 1;
}
else
{
return 0;
}
}
This fuction will get the arguments 2 arguments from the user.It returns the value 1 if both username and the password match with the username and the password that are stored previously in the files. But this is always giving 0 as the return even though the username and passwords match. If there is anyone who can help me out with this?
Full code::
#include<conio.h>
#include<fstream>
#include<stdlib.h>
#include<string.h>
#include<iomanip>
#include<iostream>
using namespace std;
class hospital
{
char id[30];
char pwd[30];
long int ph;
char location[30];
long int pin;
char name[30];
public:
void getdata();
void display();
void login_check(char usr[],char pd[]){if(strcmp(usr,id)==0&&strcmp(pwd,pd)==0){cout<<"\nVerified thet you are the user already registered.But the main page is still under constructon";}}
};
void hospital::getdata()
{
cout<<" *******************************************************************************\n";
cout<<" \n\n\t\tCreate New hospital Database ";
cout<<" *******************************************************************************\n";
cout<<"Hospital id:";
cin>>id;
cout<<"\nhospital password";
cin>>pwd;
cout<<"\nhospital name:";
cin>>name;
cout<<"phone no:";
cin>>ph;
cout<<"\nLocation:";
cin>>location;
cout<<"Enter the area code";
cin>>pin;
}
void hospital::display()
{
cout<<"\nhospital name:"<<name;
cout<<"phone no:"<<ph;
cout<<"\nLocation:"<<location;
cout<<"area code"<<pin;
}
//*******************************************************
// CLASS NAME : patient
//*******************************************************
class patient
{
private:
char pat_id[30];
char pat_pwd[30];
public:
char name[20];
char blood_group[5];
long int phn;
int a;
void patientdata();
void showdata();
int login_check(char usr[],char pwds[])
{
if((strcmp(usr,pat_id)==0)&&(strcmp(pwds,pat_pwd)==0))
{
return 1;
}
else
{
return 0;
}
}
};
//*******************************************************
// FUNCTIONS TO GET AND SHOW DATA
//*******************************************************
void patient::patientdata() //Function for the new user accounts details
{
cout<<" \n************************************************************************\n";
cout<<"\n Create New Patient Database \n";
cout<<" \n************************************************************************\n";
cout<<"\nEnter Patient ID : ";
cin>>pat_id;
cout<<"\nEnter the password:";
cin>>pat_pwd;
cout<<"\nEnter Patient Name : ";
cin>>name;
cout<<"\nEnter Patient Blood Group : ";
cin>>blood_group;
cout<<"\nEnter Patient Phone : ";
cin>>phn;
}
void patient::showdata()
{
cout<<"\nPatient ID\t: "<<pat_id;
cout<<"\nPatient Name\t: "<<name;
cout<<"\nBlood Group\t: "<<blood_group;
cout<<"\nPatient Phone\t: "<<phn;
cout<<"\n\n";
}
/***************************************************************************
Main Function
*************************************************************************/
int main()
{
system("CLS");
static long int patno;
static long int hosno;
int k;
cout<<"\tWelcome to 24-7 health management system\n";
cout<<"_________________________________________________________________________\n\n";
cout<<"\tAll Copy rights reserved to Amrita students\n";
cout<<"\n\nPress Any Key to Continue";
getch();
system("CLS");
char s;
hospital ob[hosno];
patient obj[patno];
z:
int ke=0;
fstream f;
f.open("patient",ios::in|ios::out|ios::app|ios::ate|ios::binary);
cout<<"Enter the choice:\n";
cout<<"=====================================================================";
cout<<"\n1.signin.\n2.Not yet siged? sign up now.";
int choice;
cin>>choice;
switch(choice)
{
case 1:
{
char id[30],pwd[30];
cout<<"\nEnter the id:";
cin>>id;
cout<<"\nEnter the password:";
cin>>pwd;
for(k=1;k<=patno;k++)
{
if(obj[k].login_check(id,pwd)==1)
{
ke++;
}
}
if(ke==0)
{
cout<<" \n***WARNING***\n\nThe username or the password you have entered is incorrect\n\n\n\n";
goto z;
}
else
{
cout<<"\n1.Show all the patient details\n2.Show all the hospital details\n3.Exit";
//*********************************************************************************
int choice2;
cin>>choice2;
switch(choice2)
{
case 1:
{
int i;
cout<<"\n\n";
fstream f;
f.open("patient",ios::in|ios::out|ios::ate|ios::app|ios::binary);
cout<<"\n\n";
char ans;
f.seekg(0);
for(i=1;i<=patno;i++)
{
obj[i].showdata();
}
cout<<"Do You Want To Continue? y/n :";
cin>>ans;
if(ans=='y')
{
f.close();
goto z;
}
else
{
break;
}
}
case 2:
{
int i;
cout<<"\n\n";
fstream f1;
f1.open("hospital",ios::in|ios::out|ios::ate|ios::app|ios::binary);
cout<<"\n\n";
char ans;
f1.seekg(0);
for(i=1;i<=hosno;i++)
{
ob[i].display();
}
cout<<"Do You Want To Continue? y/n :";
cin>>ans;
if(ans=='y')
{
f1.close();
goto z;
}
else
{
break;
}
}
/* Exit */
case 3:
{
exit(1);
}
default:
{
cout<<"\n\tWrong input \n";
cout<<"\n\tDo You Want To Continue?y/n :";
char ans;
ans=getchar();
system("CLS");
if(ans=='Y')
{goto z;}
else
break;
}
}
break;
}
}
case 2:
{
cout<<"\n =============================================================================\n";
cout<<"\t\t\t Welcome \n";
cout<<"\n =============================================================================\n";
cout<<"Please enter the case:\n====================================================================";
cout<<"\n1.New users;\n2.Hospitals\n3.Doctors.\n4.Admin\n";
int choice1;
cin>>choice1;
switch(choice1)
{
case 1:
{
cout<<"\n\t 1 . New patient";
patno++; //static variable incremented when ever new user is creating an account
system("CLS");
fstream f;
f.open("patient",ios::in|ios::out|ios::ate|ios::app|ios::binary);
char ans;
obj[patno].patientdata(); // Call for patientdata function
f.write((char *)&obj[patno],sizeof(obj[patno]));
cout<<"Do You Want To Continue? y/n :";
cin>>ans;
if(ans=='y')
{
goto z;
f.close();
}
else
break;
}
//===========================================================
// Case 2
//============================================================
case 2:
{
f.open("hospital",ios::in|ios::out|ios::app|ios::ate|ios::binary);
cout<<"\n\t 2 . New hospital";
hosno++;
system("CLS");
fstream f1;
f1.open("hospital",ios::in|ios::out|ios::ate|ios::app|ios::binary);
char ans;
ob[hosno].getdata();
f1.write((char *)&ob[hosno],sizeof(ob[hosno]));
cout<<"Do You Want To Continue? y/n :";
cin>>ans;
if(ans=='y')
{
goto z;
f1.close();
}
else
break;
}
case 3:
{
cout<<"#########Under construction######";
goto z;
break;
}
case 4:
{
cout<<"###########Under constuction########";
goto z;
break;
}
break; }
}
break;
}
getch();
return 0;
}
If you think that you could help me out with this.Email me. my eamil adress is manjushcool@gmail.com