#include<iostream>#include<cstring>#include<string>intmain(){
using namespace std;
string f_name,l_name;
cout<<"Enter your first name: ";
cin>>f_name;
cout<<"Enter your last name: ";
cin>>l_name;
l_name+=", "+f_name;
cout<<"Here's the information in a single string: "<<l_name;}
#include<iostream>#include<string>struct pizza
{
std::string brand;int diameter;float weight;};intmain(){
using namespace std;
pizza * snack=new pizza;
cout<<"Enter the name of pizza company: ";
cin>>snack->brand;
cout<<"Enter the diameter of the pizza: ";
cin>>snack->diameter;
cout<<"Enter the weight of the pizza: ";
cin>>snack->weight;
cout<<"snack.brand:"<<snack->brand<<endl
<<"snack.diameter:"<<snack->diameter<<endl
<<"snack.weight:"<<snack->weight;}
编写一个程序,让用户输入3次40m跑成绩并显示次数和平均成绩,数据用array对象存储。
#include<iostream>#include<array>intmain(){
using namespace std;
array<float,3> vi;int i;for(i=0;i<3;i++){
cout<<"Please input your time of 40m-racing"<<endl;
cin>>vi[i];}float ave;
ave=(vi[0]+vi[1]+vi[2])/3;
cout<<"You have gone on 3 times and your average time is "<<ave<<" S";}