#include<iostream>usingnamespace std;intmain(){char Firstname[20];char Lastname[20];char grade;int age;
cout <<"What is your first name?";
cin.getline(Firstname,20);
cout <<"What is your last name?";
cin.getline(Lastname,20);
cout <<"What letter grade do you deserve?";
cin >> grade;
cout <<"What is your age?";
cin >> age;
cout <<"Name: "<< Lastname <<" , "<< Firstname <<endl;
cout <<"grade: "<<char(grade +1)<< endl;
cout <<"Age: "<< age <<endl;return0;}
//4.13 编程练习2
#include<iostream>#include<string>usingnamespace std;intmain(){
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 << endl;return0;}
//4.13 编程练习3
#include<iostream>#include<cstring>usingnamespace std;constint SIZE =20;intmain(){char First_name[SIZE];char Last_name [SIZE];char symbol[3]=", ";
cout <<"Enter your first name: ";
cin.getline(First_name,SIZE);
cout <<"Enter your Last_name: ";
cin.getline(Last_name,SIZE);strncat(Last_name,symbol,2);int limit =19-strlen(Last_name);strncat(Last_name,First_name,limit);//Last_name[19] = '\0';
cout <<"Here's the information in a single string: ";
cout << Last_name <<endl;return0;}
// 4.13编程练习4
#include<iostream>#include<string>usingnamespace std;intmain(){
string First_name;
string Last_name ;
cout <<"Enter your first name: ";getline(cin,First_name);
cout <<"Enter your Last_name: ";getline(cin,Last_name);
string str = Last_name +", "+ First_name;
cout <<"Here's the information in a single string: ";
cout << str <<endl;return0;
#include<iostream>#include<array>usingnamespace std;intmain(){
array<float,3> run ={};for(int i=0;i<3;i++){
cout <<"please input the result of "<< i+1<<" 40m run: ";
cin >> run[i];
cout <<"the average is: "<<(run[0]+run[1]+run[2])/(i+1)<< endl;}return0;}