How you can write program in C++ with very simple selection menu ?
C++ | 9/23/2020 8:35:57 AM
Write a program in c++ language that must take an employee’s personal information such as First Name, Last Name, Middle Name as strings. Create a user menu to perform given tasks.
(A). Input name First Name, Last Name and Middle Name using reference parameter
(B). Display first name
(C). Display middle name
(D). Display last name
(E). Compare the name against a name given from key board.
You are not allowed to use any built-in sting Function. You can develop function on your own.
using namespace std;
#include <conio.h>;
#include <iostream>;
int main()
{
char menu, mainMenu;
string newName, name, firstName, lastName, middleName;
string *n, *fName, *lName, *mName;
n = &name; //save the reference of name in n
fName = &firstName; //save the reference of firstname in fName
lName = &lastName; //save the reference of lastName in lName
mName = &middleName; //save the reference of middleName in mName
cout<<"for use this program use the user menu"<<endl;
cout<<endl;
for(int i =0; i<50; i++)
{
cout<<"-";
}
cout<<endl; cout<<endl;
cout<<"\t user menu"<<endl;
cout<<endl;
for(int i =0; i<50; i++)
{
cout<<"-";
}
cout<<endl;
int count = 1;
while(count == 1)
{
cout<<"Press A : \t Input name, First Name, Last Name and Middle Name using reference parameter."<<endl;
cout<<"Press B : \t Display first name"<<endl;
cout<<"Press C : \t Display middle name"<<endl;
cout<<"Press D : \t Display last name"<<endl;
cout<<"Press E : \t Compare the name against a name given from key board."<<endl;
cout<<"-- please select menu from above menu detail --"<<endl;
cin>> menu;
cout<<endl; cout<<endl;
switch(menu)
{
case 'A':
cout<<"Enter User Name : \t";
cin>>name;
cout<<"Enter First Name : \t";
cin>>firstName;
cout<<"Enter Last name : \t ";
cin>> lastName;
cout<<"Enter Middle Name : \t ";
cin>>middleName;
cout<<endl;
break;
case 'B': //first name printed by reference
cout<<"First Name is : \t"<<*fName;
cout<<endl;
cout<<endl;
break;
case 'C': //middle name printed by reference
cout<<"Middle Name is : \t"<<*mName;
cout<<endl;cout<<endl;
break;
case 'D': //last name printed without by reference, printed by value
cout<<"Last Name is : \t"<<lastName;
cout<<endl; cout<<endl;
break;
case 'E':
cout<<"Compare the name against a name given from key board."<<endl;
cout<<endl;
cout<<"Enter name by keyboard : \t";
cin>>newName;
cout<<endl;
if(name!= newName)
{
cout<<"name is not match with old name"<<endl;
}
else if(name == newName)
{
cout<<"name is matching with old name"<<endl;
}
cout<<endl; cout<<endl;
break;
default:
cout<<"Invalid menu"<<endl;
count += 1;
}
count;
}
getch();
return 0;
}
Output :
for use this program use the user menu
--------------------------------------------------
user menu
--------------------------------------------------
Press A : Input name, First Name, Last Name and Middle Name using reference parameter.
Press B : Display first name
Press C : Display middle name
Press D : Display last name
Press E : Compare the name against a name given from key board.
-- please select menu from above menu detail --