Write a C++ Program that requests and displays the information shown below. Note that the program should be able to accept the first names of more than one word. Also, note that the program adjusts the grade downward that is up to one letter.
What is your first name? Betty Sue
What is your last name? Yew
What letter grade do you deserve?B
What is your age?22
Name: Yew Bretty Sue
Grade: C
Age: 22
[Note: Test the data with minimum of two inputs]
C
C
#include
using namespace std;
char gr(char g)
{
if(g==’z’)
{
return ‘a’;
}
else
{
return g+1;
}
}
int main()
{
char fname[20],lname[20],grade;
int age,i;
for(i=0;i<2;i++)
{
cout<<“What is your first name?”;
cin.getline(fname,20);
cout<<“What is your last name?”;
cin.getline(lname,20);
cout<<“What letter grade do you deserve?”;
cin>>grade;
grade=gr(grade);
cout<<“What is your age?”;
while(!(cin>>age))
{
cin.clear();
while(cin.get()!=’\n’)
continue;
cout<<“What is your age?”;
}
cout<<“Name: “<<lname<<“, “<<fname<<“\n”;
cout<<“Grade: “<<grade<<“\n”;
cout<<“Age: “<<age<<“\n”;
cin.get();
}
}
After taking integer value, if we want to take a string as input, there we must need cin.get() between them.
cin.getline(string_name, size) General Syntax.