标签:
}
2、答案:
#include <iostream>
#include <string>
int main()
{
using namespace std;
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";
return 0;
}
3、答案:
#include <iostream>
#include <cstring>
int main()
{
using namespace std;
char* fname = new char [15];
char* lname = new char [8];
cout << "Enter your first name: ";
cin.getline(fname,5);
cout<<"Enter your last name:";
cin.getline(lname,8);
strcat(fname,",");
strcat(fname,lname);
cout << "Here‘s the information in a single string: "
<<fname;
delete [] fname;
delete [] lname;
return 0;
}
4、答案:
#include <iostream>
#include <string>
int main()
{
using namespace std;
string fname;
string lname;
cout << "Enter your first name: ";
getline(cin,fname);
cout<<"Enter your last name:";
getline(cin,lname);
fname +=", ";
fname += lname;
cout << "Here‘s the information in a single string: "
<<fname;
return 0;
}
5、答案
#include <iostream>
#include <string>
using namespace std;
struct CandyBar
{
string brand;
float weight;
int carlo;
};
int main()
{
CandyBar snack = {"Mocha Munch",2.3,350};
cout<<"brand = "<<snack.brand<<endl
<<"weight = "<<snack.weight<<endl
<<"carlo = "<<snack.carlo<<endl;
return 0;
}
6、答案
#include <iostream>
#include <string>
using namespace std;
struct CandyBar
{
string brand;
float weight;
int carlo;
};
int main()
{
CandyBar snack[3] = {{"Mocha Munch",2.3,350},{"Mocha Middle",2.0,300},{"Mocha Little",3.2,600}};
for(int i=0;i<3;i++)
cout<<"snack[i].brand = "<<snack[i].brand<<endl
<<"snack[i].weight = "<<snack[i].weight<<endl
<<"snack[i].carlo = "<<snack[i].carlo<<endl;
return 0;
}
7、答案
#include <iostream>
#include <string>
using namespace std;
struct pizaInfo
{
string coname;
int diameter;
float weight;
};
int main()
{
pizaInfo p1;
cout << "Enter the infomation:\n";
cout << "Corpotion name:";
getline(cin,p1.coname);
cout <<"piza diameter: ";
cin>>p1.diameter;
cout << "Piza weight: ";
cin >>p1.weight;
cout<<"\n\n"<<"Corpotion name:"<<p1.coname<<endl
<<"piza diameter:"<<p1.diameter<<endl
<<"Piza weight: "<<p1.weight;
}
8、答案
#include <iostream>
#include <string>
using namespace std;
struct pizaInfo
{
string coname;
int diameter;
float weight;
};
int main()
{
pizaInfo* ps = new pizaInfo;
cout << "Enter the infomation:\n";
cout <<"piza diameter: ";
cin>>ps->diameter;
cout << "Corpotion name:";
cin>>ps->coname;
cout << "Piza weight: ";
cin >>ps->weight;
cout<<"\n\n"<<"Corpotion name:"<<ps->coname<<endl
<<"piza diameter:"<<ps->diameter<<endl
<<"Piza weight: "<<ps->weight;
delete ps;
}
9、答案
#include <iostream>
#include <string>
using namespace std;
struct CandyBar
{
string brand;
float weight;
int carlo;
};
int main()
{
CandyBar* snack = new CandyBar[3];
snack[0].brand = "Mocha Munch";
snack[0].carlo= 2.3;
snack[0].weight = 350;
snack[1].brand = "Mocha Middle";
snack[1].carlo= 2.0;
snack[1].weight = 300;
snack[2].brand = "Mocha Little";
snack[2].carlo= 3.2;
snack[2].weight = 600;
for(int i=0;i<3;i++)
cout<<"snack[i].brand = "<<snack[i].brand<<endl
<<"snack[i].weight = "<<snack[i].weight<<endl
<<"snack[i].carlo = "<<snack[i].carlo<<endl;
delete [] snack;
return 0;
}
10、答案
#include <iostream>
#include <array>
using namespace std;
int main()
{
array<float,3> scores;
cout<<"Please enter three times score of 40-meters-run: \n";
for(int i =0;i<3;i++)
{
cout<<"The "<<i<<" time score:";
cin>>scores[i];
}
cout << "The average of scores is :"
<<(scores[0]+scores[1]+scores[2])/3;
return 0;
}
标签:
原文地址:http://blog.csdn.net/walkman_lfq/article/details/51321214