标签:
4-13_1
1 /* Author : grey_qisen */ 2 // 4-13_1.cpp 3 #include<iostream> 4 const int Size = 20; 5 6 int main(){ 7 using namespace std; 8 char firstName[Size]; char lastName[Size]; 9 char deserveGrade; char trueGrade; 10 int age; 11 12 cout << "What is your first name? "; 13 cin.getline(firstName,Size); 14 cout << "What is your last name? "; 15 cin.getline(lastName,Size); 16 cout << "What letter grade do you deserve? "; 17 cin >> deserveGrade; 18 cout << "What is your age? "; 19 cin >> age; 20 21 if(deserveGrade == 68) deserveGrade = 69; 22 if(deserveGrade == 70) deserveGrade = 69; 23 trueGrade = deserveGrade + 1; 24 25 cout << "Name:" << lastName << ", " << firstName << endl; 26 cout << "Grade: " << trueGrade << endl; 27 cout << "Age: " << age << endl; 28 29 return 0; 30 }
4-13_2
1 /* Author : grey_qisen */ 2 // 4-13_2.cpp 3 #include<iostream> 4 #include<string> 5 #include<cstring> 6 7 int main(){ 8 using namespace std; 9 string name; string dessert; 10 cout << "Enter your name:\n"; 11 getline(cin,name); 12 cout << "Enter your favorite dessert:\n"; 13 getline(cin,dessert); 14 cout << "I have some delicious " << dessert; 15 cout << " for you, " << name << ".\n"; 16 17 return 0; 18 }
4-13_3
1 /* Author : grey_qisen */ 2 // 4-13_3.cpp 3 #include<iostream> 4 #include<cstring> 5 const int MaxSize = 20; 6 7 int main(){ 8 using namespace std; 9 char firstName[MaxSize]; char lastName[MaxSize]; 10 cout << "Enter your first name: "; 11 cin >> firstName; 12 cout << "Enter your last name: "; 13 cin >> lastName; 14 15 strcat(lastName,", "); 16 strcat(lastName,firstName); 17 cout << "Here‘s the information in a single string: " << lastName << endl; 18 19 return 0; 20 }
4-13_4
1 /* Author : grey_qisen */ 2 // 4-13_4.cpp 3 #include<iostream> 4 #include<string> 5 #include<cstring> 6 7 int main(){ 8 using namespace std; 9 string firstName; string lastName; 10 cout << "Enter your first name: "; 11 cin >> firstName; 12 cout << "Enter your last name: "; 13 cin >> lastName; 14 15 lastName += ", "; 16 lastName += firstName; 17 cout << "Here‘s the information in a single string: " << lastName << endl; 18 19 return 0; 20 }
4-13_5
1 /* Author : grey_qisen */ 2 // 4-13_5.cpp 3 #include<iostream> 4 const int MaxSize = 20; 5 struct CandyBar{ 6 char name[20]; // the name of candy 7 double weight; // the weight of candy 8 int Kaluli; // the kaluli of candy 9 }; 10 11 int main(){ 12 using namespace std; 13 CandyBar snack = { 14 "Mocha Munch", 15 2.3, 16 350 17 }; 18 19 cout << "The information of candy is :\n"; 20 cout << "candy name: " << snack.name << endl 21 << "candy weight: " << snack.weight << endl 22 << "candy Kaluli: " << snack.Kaluli << endl; 23 24 return 0; 25 }
4-13_6
1 /* Author : grey_qisen */ 2 // 4-13_6.cpp 3 #include<iostream> 4 const int MaxSize = 20; 5 struct CandyBar{ 6 char name[20]; // the name of candy 7 double weight; // the weight of candy 8 int Kaluli; // the kaluli of candy 9 }; 10 11 int main(){ 12 using namespace std; 13 CandyBar candy[3] = { 14 {"MM_1", 2.0, 200}, 15 {"MM_2", 1.1, 250}, 16 {"MM_3", 2.2, 300} 17 }; 18 19 cout << "The information of candy is :\n"; 20 cout << "first candy name is: " << candy[0].name << endl 21 << "first candy weight is " << candy[0].weight << endl 22 << "first candy Kaluli is " << candy[0].Kaluli << endl; 23 24 cout << "second candy name is: " << candy[1].name << endl 25 << "second candy weight is " << candy[1].weight << endl 26 << "second candy Kaluli is " << candy[1].Kaluli << endl; 27 28 cout << "third candy name is: " << candy[2].name << endl 29 << "third candy weight is " << candy[2].weight << endl 30 << "third candy Kaluli is " << candy[2].Kaluli << endl; 31 32 return 0; 33 }
4-13_7
1 /* Author : grey_qisen */ 2 // 4-13_7.cpp 3 #include<iostream> 4 const int MaxSize = 20; 5 struct Pizza{ 6 char pizzaName[MaxSize]; 7 int pizzaDiam; 8 double pizzaWeight; 9 }; 10 11 int main(){ 12 using namespace std; 13 Pizza WWpizza = {}; 14 cout << "Enter the pizza‘s name: "; 15 cin.getline(WWpizza.pizzaName,MaxSize); 16 cout << "Enter the diam of pizza: "; 17 cin >> WWpizza.pizzaDiam; 18 cout << "Enter the weight of pizza: "; 19 cin >> WWpizza.pizzaWeight; 20 21 cout << "Your pizza‘s information is:" << endl; 22 cout << "Pizza‘s name: " << WWpizza.pizzaName << endl 23 << "Diam of Pizza: " << WWpizza.pizzaDiam << endl 24 << "Weight of Pizza: " << WWpizza.pizzaWeight << endl; 25 26 return 0; 27 }
标签:
原文地址:http://www.cnblogs.com/grey-qisen/p/4765237.html