Question: convert this c++ code in c code and also share screenshot pf output #include #include #include #include #include #include #include using namespace std; class directory

convert this c++ code in c code and also share screenshot pf output
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class directory
{
int PhNo;
char fname[50], lname [50];
public:
string getpword()
{
char ch;
string pass="";
cout << "Please Enter the Password: ";
oo:
ch=getch();
if(ch==8)
{
goto oo;
}
while(ch!=13)
{
if(ch==8)
{
if(pass.size()==0)
{
goto ps;
}
pass.erase(pass.size()-1);
cout << "\b \b";
ps:
goto pp;
}
pass.push_back(ch);
cout << "*";
pp:
ch=getch();
}
return pass;
}
int check(string a)
{
int flag=0;
string b;
fstream f1("Accounts.dir",ios::in);
while(f1)
{
f1 >> b;
if(b==a)
{
flag = 1; break;
}
}
f1.close();
if(flag==1)
{
cout << " Sorry! Username already exists. Please try another: ";
return 1;
}
return 0;
}
int SignIn()
{
string uname, password, struname, strpassword, line;
ghi:
fstream file1("Accounts.dir");
int flag=0, nextLoc=0;
system("cls");
cout << " \t\t-----------TELEPHONE DIRECTORY------------- ";
cout << "Please Enter Your Username: ";
cin >> struname;
if (struname=="Admin")
{
return 2;
}
if (struname=="admin")
{
return 3;
}
while (! file1.eof() )
{
getline (file1,line);
nextLoc=line.find(" ");
uname=line.substr(0,nextLoc);
line = line.substr(nextLoc+1,line.length());
password=line;
if(uname==struname)
{
flag=1;
break;
}
}
file1.close();
if(flag==1)
{
def:
strpassword=getpword();
if(strpassword==password)
{
cout << "Sign-In Succesful.";
}
else
{
cout << " Wrong Password! ";
goto def;
}
}
else
{
cout << " Your Username was not Found in our Database. Please Sign-Up or Enter correct Username";
cout << " Press <1> To Sign-Up OR <2> To Sign-In Again ";
int choice1;
cin >> choice1;
if(choice1==1)
{
return 1;
}
else
{
goto ghi;
}
}
return 0;
}
void SignUp()
{ string uname, struname, line, Password;
int flag;
system("cls");
cout << " \t\t-----------TELEPHONE DIRECTORY------------- ";
fstream file1("Accounts.dir",ios::in|ios::out|ios::app);
cout << "Please Enter an Username: ";
cv:
cin >> struname;
flag = check(struname);
if(flag==1)
{
goto cv;
}
cout << "Please Enter a Password: ";
cin >> Password;
file1 << " " << struname << " " << Password;
cout << " Account Created Successfully ";
system("pause");
return;
}
void GetDetails()
{
string fname, lname, tnumber;
char choice = 'y';
fstream myfile("Directory.dir",ios::app);
while(choice=='Y'||choice=='y')
{
system("cls");
cout << " \t\t-----------TELEPHONE DIRECTORY------------- ";
cout << "Enter First Name : ";
cin >> fname;
myfile << fname << " ";
cout << " Enter Last Name : ";
cin >> lname;
myfile << lname << " ";
cout << " Enter Phone Number : ";
cin >> tnumber;
myfile << tnumber << " ";
cout << " Do you want to enter more? (y/n)";
cin >> choice; cout << " ";
}
myfile.close();
}
void SearchAndDisplay()
{
string line;
string fName,lName,tNumber, strFName, strLName;
char choice;
int flag=0;
int nextLoc=0;
system("color F0");
system("cls");
do{
cout << " \t\t-----------APU TELEPHONE DIRECTORY------------- ";
flag=0;
ifstream myfile ("Directory.dir");
if (myfile.is_open())
{
cout<
cin>>strFName;
cout<<"Enter Last Name: ";
cin>>strLName;
while (! myfile.eof() )
{
getline (myfile,line);
nextLoc=line.find(" ");
fName=line.substr(0,nextLoc);
line = line.substr(nextLoc+1,line.length());
nextLoc=line.find(" ");
lName=line.substr(0,nextLoc);
line = line.substr(nextLoc+1,line.length());
tNumber = line;
if(fName==strFName && lName==strLName)
{
cout<<" Found!!"<
cout<
flag=1;
break;
}
}
}
else
{
cout << "Unable to open file"<
exit(0);
}
if(flag==0)
{
cout<<"Not Found...Sorry."<
}
cout << " Do you want to enter more?(y/n) ";
cin >> choice;
system("cls");
}while(choice=='y');
return;
}
void Delete()
{
system("cls");
string line, fName, lName, strLName, strFName, tNumber;
int nextLoc=0,flag=0;
cout << " \t\t-----------TELEPHONE DIRECTORY------------- ";
cout << "Please enter the first name of record you want to delete: ";
cin>>strFName;
cout << " Please enter the last name of record you want to delete: ";
cin>>strLName;
ifstream myfile;
ofstream temp;
myfile.open("Directory.dir");
temp.open("temp.dir");
while (!myfile.eof())
{
getline (myfile,line);
nextLoc=line.find(" ");
fName=line.substr(0,nextLoc);
line = line.substr(nextLoc+1,line.length());
nextLoc=line.find(" ");
lName=line.substr(0,nextLoc);
line = line.substr(nextLoc+1,line.length());
tNumber = line;
if(!(fName==strFName && lName==strLName))
temp << fName <<" "<< lName <<" "<< tNumber<< endl;
else
flag++;
}
if(flag==0)
{
cout<<" Record not found!! ";
goto afg;
}
cout << "The record with the name " << strFName <<" "<
myfile.close();
temp.close();
remove("Directory.dir");
rename("temp.dir", "Directory.dir");
afg:
return;
}
void mod()
{
system("cls");
system("color F0");
string line, fName, lName, strLName, strFName, tNumber;
int nextLoc=0,flag=0;
cout << " \t\t-----------TELEPHONE DIRECTORY------------- ";
afgh:
cout << "Please enter the first name of record you want to modify: ";
cin>>strFName;
cout << " Please enter the last name of record you want to modify: ";
cin>>strLName;
ifstream myfile;
ofstream temp;
myfile.open("Directory.dir");
temp.open("temp1.dir");
while (!myfile.eof())
{
getline (myfile,line);
nextLoc=line.find(" ");
fName=line.substr(0,nextLoc);
line = line.substr(nextLoc+1,line.length());
nextLoc=line.find(" ");
lName=line.substr(0,nextLoc);
line = line.substr(nextLoc+1,line.length());
tNumber = line;
if(!(fName==strFName && lName==strLName))
temp << fName <<" "<< lName <<" "<< tNumber<< endl;
else
flag++;
}
if(flag==0)
{
cout<<" Record not found!! Try Again. ";
goto afgh;
}
myfile.close();
temp.close();
remove("Directory.dir");
rename("temp1.dir", "Directory.dir");
string fname2, lname2, tnumber2;
fstream myfile2("Directory.dir",ios::app);
cout << " Enter New First Name : ";
cin >> fname2;
myfile2 << fname2 << " ";
cout << " Enter New Last Name : ";
cin >> lname2;
myfile2 << lname2 << " ";
cout << " Enter New Phone Number : ";
cin >> tnumber2;
myfile2 << tnumber2;
myfile2.close();
return;
}
};
int main()
{
directory d;
system("color F0");
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = 19;
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
std::wcscpy(cfi.FaceName, L"Consolas");
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
int choice, choice3, returnedValue;
char choice2='y', choice4='y';
string pword;
dkj:
system("cls");
cout << " \t\t-----------TELEPHONE DIRECTORY------------- ";
cout << "Please Sign-In or Sign-Up to Continue \t1. Sign-In to an Existing Account \t2. Create a new Account \t3. Exit ";
cout << " Please Enter your choice: ";
cin >> choice3;
if(choice3==1)
{
returnedValue=d.SignIn();
if(returnedValue==1)
{
d.SignUp();
}
else if(returnedValue==2)
{
yz:
pword=d.getpword();
if(pword=="Root")
{
system("cls");
cout << "Admin Signed In ";
system("pause");
goto mno;
}
else
{
cout << " Password Incorrect! Please Enter Again: ";
goto yz;
}
}
else if(returnedValue==3)
{
vwx:
pword=d.getpword();
if(pword=="root")
{
system("cls");
cout << "Admin Signed In ";
system("pause");
goto mno;
}
else
{
cout << " Password Incorrect. Please Enter Again: ";
goto vwx;
}
}
}
else if(choice3==2)
{
jkl:
d.SignUp();
}
else
{
exit(0);
}
while(choice2=='Y'||choice2=='y')
{
system("color F0");
system("cls");
cout << " \t\t-----------TELEPHONE DIRECTORY------------- ";
cout <<"Do you want to \t1.View Existing Directories \t2.Log Out \t3.Log Out and Exit ";
cout<<" Please enter your choice: ";
abc:
cin >> choice;
switch (choice)
{
case 1: d.SearchAndDisplay(); break;
case 2: cout<<" Logged out successfully! ";
system("pause");
goto dkj;
case 3: exit(0); break;
default: cout << " Wrong Input! Try Again... "; goto abc;
}
}
goto stu;
mno:
system("color F0");
system("cls");
cout << " \t\t-----------TELEPHONE DIRECTORY------------- ";
cout << "Do you want to \t1.Enter New Directories \t2.View Existing Directories \t3.Delete Existing Directories \t4.Modify Existing Directories \t5.Log Out \t6.Log Out and Exit ";
cout<<" Please enter your choice: ";
pqr:
cin >> choice;
lok:
switch (choice)
{
case 1: d.GetDetails(); break;
case 2: d.SearchAndDisplay(); break;
case 3: d.Delete();break;
case 4: d.mod();break;
case 5: cout<<" Logged out successfully! ";
system("pause");
goto dkj;
case 6: exit(0);
default: cout << " Wrong Input! Try Again... "; goto pqr;
}
cout << "Do you want to continue? (y/n) : ";
choice4=getch();
if(choice4=='Y'||choice4=='y')
{
goto lok;
}
else
goto mno;
stu:
exit(0);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!