#include <iostream>
#include <string>
#include <cstring>
#include <array>
using namespace std;
struct stu
{
char f_name[15];
char l_name[15];
char degree;
int age;
};
struct Candybar
{
Candybar():C_logo(),C_weight(),C_car(){};
string C_logo;
double C_weight;
int C_car;
};
struct Pizza
{
string P_name;
double d;
double weight;
};
int main()
{
/*cout<<"No.1:"<<endl;
stu stu1;
cout<<"what is your first name:";
cin.getline(stu1.f_name,15);
cout<<"what is your last name:";
cin.getline(stu1.l_name,15);
cout<<"what letter grade do you deserve? ";
cin >>stu1.degree;
stu1.degree+=1;
cout<<"what is your age?";
cin >> stu1.age;
cout << "Name:"<<stu1.f_name<<" "<<stu1.l_name<<endl;
cout << "Grade:"<< stu1.degree<<endl;
cout << "Age:" << stu1.age<<endl;
system("pause");
cout << "N0.2:"<<endl;
cout << "Enter your name:\n";
string name;
string dessert;
cin >> name;
cout << "Enter your favorate dessert:\n";
cin >> dessert;
cout << "I have some deliciuse "<<dessert;
cout << "for you," << name << "\n";
system("pause");
cout << "No.3:"<<endl;
stu stu2;
cout << "Enter your first name:";
cin.getline(stu2.f_name,15);
cout << "Enter your last name:";
cin.getline(stu2.l_name,15);
char combine[30];
strcpy(combine,stu2.f_name);
strcat(combine,",");
strcat(combine,stu2.l_name);
cout << combine;
system("pause");
cout << "No.4:"<<endl;
cout << "Enter your first name:";
string stu1,stu2;
cin >> stu1;
cout << "Enter your last name:";
cin >> stu2;
stu2 = stu2+",";
stu1 = stu2+ stu1;
cout << stu1;
system("pause");
cout << "No.5:"<<endl;
Candybar snack = {
"Mocha Munch",
2.3,
350
};
cout << snack.C_logo <<endl<<snack.C_weight<<endl<<snack.C_car<<endl;
system("pause");
cout << "No.6:"<<endl;
Candybar Array[3]=
{
{"M&m",2.1,250},
{"Kitkat",2.5,300},
{"Dove",2.4,350}
};
for(int i=0;i<3;i++)
{
cout<<"Type"<<i+1<<endl<<Array[i].C_logo<<endl<<Array[i].C_weight<<endl<<Array[i].C_car<<endl;
}
system("pause");
cout << "No.7:"<<endl;
cout <<"input the information of Pizza:"<<endl;
Pizza temp;
cout << "the name:"<<endl;
cin >> temp.P_name;
cout << "the diameter:"<< endl;
cin >> temp.d;
cout << "the weight:"<<endl;
cin >> temp.weight;
cout <<"result is :"<<endl<<temp.P_name<<endl<<temp.d<<endl<<temp.weight<<endl;
system("pause");
cout << "No.8:"<<endl;
cout <<"input the information of Pizza:"<<endl;
Pizza * temp = new Pizza;
cout << "the diameter:"<< endl;
cin >> temp->d;
cout << "the name:"<<endl;
cin >> temp->P_name;
cout << "the weight:"<<endl;
cin >> temp->weight;
cout <<"result is :"<<endl<<temp->P_name<<endl<<temp->d<<endl<<temp->weight<<endl;
system("pause");
delete temp;
cout << "No.9:"<<endl;
Candybar * Array = new Candybar[3];
Array[0].C_logo = "M&m";
Array[0].C_weight = 2.1;
Array[0].C_car = 250;
Array[1].C_logo = "Kitkat";
Array[1].C_weight = 2.5;
Array[1].C_car = 300;
Array[2].C_logo = "Dove";
Array[2].C_weight = 2.4;
Array[2].C_car = 350;
for(int i=0;i<3;i++)
{
cout<<"Type"<<i+1<<endl<<Array[i].C_logo<<endl<<Array[i].C_weight<<endl<<Array[i].C_car<<endl;
}
system("pause");
delete [] Array;
cout << "No.10:"<<endl;
array <double,3> ar;
for(int i = 0;i<3;i++)
{
cout << "No."<<i+1<<" grade:";
cin >> ar.at(i);
}
cout<<"average grade:"<<(ar.at(0)+ar.at(1)+ar.at(2))/3<<endl;
system("pause");*/
return 0;
}
每个题题号都写在代码里了