#include<iostream>#include<stdio.h>#include<string>usingnamespace std;structPerson{
string first_name;
string last_name;char deserve;unsignedshort age;};voidmain(){
cout <<"What is your first name?"<< endl;structPerson p;getline(cin,p.first_name);
cout <<"What is your last name?"<< endl;getline(cin, p.last_name);
cout <<"What letter grade do you deserve?"<< endl;
cin >> p.deserve;
cout <<"What is your age?"<< endl;
cin >> p.age;
cout <<"Name:"<< p.last_name <<", "<< p.first_name << endl;
cout <<"Grade:"<<++p.deserve << endl <<"age:"<< p.age;}
2
#include<iostream>#include<string>usingnamespace std;voidmain(){
string name;
string dessert;
cout <<"Enter your name:\n";getline(cin, name);
cout <<"Enter your favorite dessert:\n";getline(cin, dessert);
cout <<"I have some delicious "<< dessert;
cout <<"for you,"<< name <<".\n";}
3
#include<iostream>#include<cstring>#include<string>usingnamespace std;constint ArSize =20;constchar dot =',';voidmain(){
cout <<"Enter your first name:";char first_name[ArSize];
cin.getline(first_name, ArSize);
cout <<"Enter your last name:";char last_name[ArSize];
cin.getline(last_name, ArSize);
cout <<"Here's the information in a single string: ";char full_name[2* ArSize];strcpy_s(full_name, last_name);strcat_s(full_name,",");strcat_s(full_name, first_name);
cout << full_name << endl;}
4
#include<iostream>#include<string>usingnamespace std;voidmain(){
cout <<"Enter your first name:";
string first_name;
string last_name;
cin >> first_name;
cout <<"Enter your last name:";
cin >> last_name;
cout <<"Here's the information in a single string:";
string full_name = last_name +','+ first_name;
cout <<" "<<full_name << endl;}