how to put username and password in this code?

// my main subject
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <iomanip>
#include <string.h>
using namespace std;

const int xxx=100;

class food
{
int del; int id; char name[100]; char type[100]; int price;

public:
food(){}
char *getname()
{return name;}

int getdel()
{return del;}

int getid()
{return id;}

int getprice()
{return price;}


void settype(char t[])
{
strcpy(type,t);
}


void setname(char na[])//
{
strcpy(name,na);
}


void getprice(int pr){price=pr;}
void delna(){del=1;}//delete


void addfood(int n,int pr,char *na,char *t)//add
{
del=0;
id=n;
price=pr;
strcpy(name,na);
strcpy(type,t);
}


void disp()//Display Food info
{
if (del!=1)
{
cout<<setw(10)<<id<<setw(10)<<name<<setw(10)<<"$"<<price<<setw(10)<<type<<setw(10)<<endl;
}
}
};


class Database//Food data
{
int top;
food read[xxx];

public:
Database()//read Food data from food.txt to read[]
{ food s;
top=-1;
fstream file("food.txt",ios::in);

while (1)
{
file.read((char *)&s,sizeof(s));
if (!file) break;
top++;
read[top]=s;
}
file.close();
}


void clear()//delete all
{
top=-1;
}

int addfood (int n, int pr,char *na,char*t) //add Food
{
food *p=query(n);
if (p==NULL)
{
top++;
read[top].addfood(n,pr,na,t);
return 1;
}
return 0;
}
food *query(int foodid)
{
for (int i=0;i<=top;i++)
if (read[i].getid()==foodid && read[i].getdel()==0)
return &read[i];
return NULL;
}
food *query1(char foodna[100])
{
for (int i=0;i<=top;i++)
if ((read[i].getname()==foodna) && read[i].getdel()==0)
return &read[i];
return NULL;
}
void disp() //Display Food
{
for (int i=0;i<=top;i++)
read[i].disp();
}
void fooddata();
~Database() // read data from read[]to file food.txt
{
fstream file("food.txt",ios::out);
for (int i=0;i<=top;i++)
if (read[i].getdel()==0)
file.write((char *)&read[i],sizeof(read[i]));
file.close();
}
};
void Database::fooddata()//Food Service
{
int choice=1;
int m=1;int b=1;
char rname[20];
int itemid; int pr;char q[20];
food *r;
system("cls");
while (choice!=0)
{
cout<<" Food Service \n";
cout<<endl;
cout<<" -------------------------------------- \n";
cout<<" { 0. Return To Admin } \n";
cout<<" {====================================} \n";
cout<<" { 1. Add Food/Drinks } \n";
cout<<" { 2. Update Existed Food/Drinks } \n";
cout<<" { 3. Delete Food/Drinks } \n";
cout<<" { 4. Search Food/Drinks } \n";
cout<<" { 5. Display All Food/Drinks } \n";
cout<<" { 6. Reset The Program } \n";
cout<<" -------------------------------------- \n";
cout<<endl;
cout<<" Please Enter The Given Number: ";
cin>>choice;
system("cls");
switch (choice)
{
case 1:
cout<<" These Are The Choices. Please Choose\n";
cout<<endl;
cout<<" ------------------- \n";
cout<<" / 1. Pizza \\ "<<endl;
cout<<" / 2. Desert \\ "<<endl;
cout<<" / 3. Steak \\ "<<endl;
cout<<" / 4. Pasta \\ "<<endl;
cout<<" / 5. Drink \\ "<<endl;
cout<<" ------------------------------- \n";
cout<<endl;
cout<<" Please Enter The Given Number: ";
cin>>m;
system("cls");
while(m!=0){
switch(m)
{
case 1:
cout<<"Please Enter Pizza ID: ";
cin>>itemid;
cout<<"Please Enter Price: ";
cin>>pr;
cout<<"Please Enter Name: ";
cin>>rname;
addfood(itemid,pr,rname,"Pizza");
cout<<rname<<" is in the Pizza List now\n";
break;

case 2:
cout<<"Please Desert ID: ";
cin>>itemid;
cout<<"Please Enter Price: ";
cin>>pr;
cout<<"Please Enter Desert Name: ";
cin>>rname;
addfood(itemid,pr,rname,"Desert");
cout<<rname<<" is in the Desert List now\n";
break;

case 3:
cout<<"Please Steak ID: ";
cin>>itemid;
cout<<"Please Enter Price: ";
cin>>pr;
cout<<"Please Enter Steak Name: ";
cin>>rname;
addfood(itemid,pr,rname,"Steak");
cout<<rname<<" is in the Steak List now\n";
break;

case 4:
cout<<"Please Pasta ID: ";
cin>>itemid;
cout<<"Please Enter Price: ";
cin>>pr;
cout<<"Please Enter Pasta Name: ";
cin>>rname;
addfood(itemid,pr,rname,"Pasta");
cout<<rname<<" is in the Pasta List now\n";
break;

case 5:
cout<<"Please enter Drinks name: ";
cin>>rname;
cout<<"Please Enter Price: ";
cin>>pr;
cout<<"Please Enter Drinks ID: ";
cin>>itemid;
addfood(itemid,pr,rname,"Drinks");
cout<<rname<<" is in the Drinks List now\n";
break;
}
break;
}
break;

case 2:
cout<<"Please enter ID: ";
cin>>itemid;
r=query(itemid);

if (r==NULL)
{
cout<<"The Choice Doesnt Exist. Please Select Again"<<endl;
break;
}

cout<<"Enter Enter Price: ";
cin>>pr;
r->getprice(pr);
cout<<"Enter New Position: ";
cin>>q;
r->settype(q);
addfood(itemid,pr,rname,q);
break;

case 3:
cout<<"Enter Food/Drinks ID: ";
cin>>itemid;
r=query(itemid);

if (r==NULL)
{
cout<<"The Choice Doesnt Exist. Please Select Again"<<endl;
break;
}
r->delna();
break;

case 4:

cout<<"Choose \n";
cout<<"0. Return \n";
cout<<"1. Search ID: \n";

cin>>b;
system("cls");
while(b!=0){
switch(b)
{
case 1:
cout<<"Enter ID";
cin>>itemid;
r=query(itemid);
if (r==NULL)
{
cout<<"The Choice Doesnt Exist. Please Select Again"<<endl;
break;
}

cout<<setw(10)<<"ID"<<setw(10)<<"Name"<<setw(10)<<"Price"<<setw(10)<<"Type"<<setw(10)<<endl;
r->disp();

break;
case 2:
break;
}
break;
}
break;
case 5:
cout<<setw(10)<<"ID"<<setw(10)<<"Name"<<setw(10)<<"Price"<<setw(10)<<"Type"<<setw(10)<<endl;
disp();
break;
case 6:
clear();
break;
}
}
}
void main()

{
int choice=1;
Database DB;
while(choice!=0)
{
cout<<" __________________________________________________"<<endl;
cout<<endl;
cout<<" ******Welcome To Menu Management System Users*****"<<endl;
cout<<" __________________________________________________"<<endl;
cout<<endl;
cout<<endl;
cout<<" 0.Leave The program\n";
cout<<" 1.Open Admin Program\n";
cout<<endl;
cout<<endl;
cout<<" Please Select The Given Number: ";

cin>>choice;
system("cls");
switch(choice)
{
case 1:
while(1){
DB.fooddata();
break;
break;
}
}
}
}
Last edited on
//this are the code for username and password but idk how to combine it together.
#include <iostream>
#include <string>
using namespace std;

int main(){
string username;
string password;
bool loginSuccess = false;

cout << "\tWelcome User. Please Enter Your Username And Password\n\n";

do{
cout << "Username: ";
cin >> username;
cout << "Password: ";
cin >> password;

if(username == "Username" && password == "Password"){

cout << "\nSuccessful Login\n\n";
loginSuccess = true;
}

else{
cout << "\nInccorrect username password\n";
cout << "Please try to login again.\n";
cout << endl;
}

}while(!loginSuccess);

system("pause");
return 0;
}
Topic archived. No new replies allowed.