《C++ Primer Plus(第六版)》(5)(第四章 复合类型 答案2)
来源:互联网 发布:it行业 云计算 编辑:程序博客网 时间:2024/05/01 17:34
4.13 编程练习
1.
string firstName = "";string lastName = "";cout << "What is your first name? " ;getline(cin, firstName);cout << "What is your last name? ";getline(cin, lastName);cout << "What letter grade do you deserve? ";char grade;cin >> grade;grade++;cout << "What is your age?";int age;cin >> age;cout << "Name: " << lastName << ", " << firstName << endl;cout << "Grade: " << grade << endl;cout << "Age: " << age << endl;
2.
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;
3.
cout << "Enter your first name:";char firstName[20];cin.getline(firstName, 20);cout << "Enter your last name:";char lastName[20];cin.getline(lastName, 20);char name[80] = {0};//这个不初始化会出现中断strcat_s(name, firstName);strcat_s(name, ", ");strcat_s(name, lastName);cout << "Here's the information in a single string: "<< name;
4.
string firstName = "";string lastName = "";cout << "Enter your first name:";getline(cin, firstName);cout << "Enter your last name:";getline(cin, lastName);string name = firstName + ", " + lastName;cout << "Here's the information in a single string: " << name;
5.
struct CandyBar{string brand;//品牌double weight;//重量int calorie;//卡路里}; CandyBar snack = { "Mocha Munch", 2.3, 350 };cout << "Candy brand:" << snack.brand << " weight:" << snack.weight << " calorie:" << snack.calorie;
6.
struct CandyBar{string brand;//品牌double weight;//重量int calorie;//卡路里void getInfo(){ cout << "Candy brand:" << brand << " weight:" << weight << " calorie:" << calorie << "\n";}}; CandyBar snack = { "Mocha Munch", 2.3, 350 };snack.getInfo();CandyBar candyArr[3] = { { "Mocha Munch", 2.3, 350 }, { "Big Rabbit", 3.4, 150 }, { "Alps", 4.5, 650 } };candyArr[0].getInfo();candyArr[1].getInfo();candyArr[2].getInfo();
7.
struct Pizza{string company;//品牌double weight;//重量double diameter;//直径}; Pizza p = { "", 0, 0 };cout << "Please enter company:";getline(cin, p.company);cout << "Please enter diameter:";cin >> p.diameter;cout << "Please enter weight:";cin >> p.weight;cout << "Pizza company:" << p.company << "\ndiameter:" << p.diameter << "\nweight:" << p.weight << "\n";
8.
struct Pizza{string company;//品牌double weight;//重量double diameter;//直径}; Pizza* p = new Pizza{ "", 0, 0 };cout << "Please enter diameter:";cin >> p->diameter;getline(cin, p->company);//把回车符读取了cout << "Please enter company:";getline(cin, p->company);cout << "Please enter weight:";cin >> p->weight;cout << "Pizza company:" << p->company << "\ndiameter:" << p->diameter << "\nweight:" << p->weight << "\n";delete p;p = NULL;
9.
struct CandyBar{string brand;//品牌double weight;//重量int calorie;//卡路里void printInfo(){ cout << "Candy brand:" << brand << " weight:" << weight << " calorie:" << calorie << "\n";}}; CandyBar* candyArr = new CandyBar[3];candyArr[0] = { "Mocha Munch", 2.3, 350 };candyArr[1] = { "Big Rabbit", 3.4, 150 };candyArr[2] = { "Alps", 4.5, 650 } ;candyArr[0].printInfo();candyArr[1].printInfo();candyArr[2].printInfo();delete[] candyArr;candyArr = NULL;
10.
array<double, 3> socreArr;cout << "Please enter you score:";cin >> socreArr[0];cout << "Please enter you score:";cin >> socreArr[1];cout << "Please enter you score:";cin >> socreArr[2];double totalScore = socreArr[0] + socreArr[1] + socreArr[2];cout << "times:" << 3 << " averageScore:" << totalScore/3;
1 0
- 《C++ Primer Plus(第六版)》(5)(第四章 复合类型 答案2)
- 《C++ Primer Plus(第六版)》(4)(第四章 复合类型 答案1)
- C++ Primer Plus(第六版)—— 第四章 复合类型 笔记和答案
- 《C++ Primer Plus(第六版)》(3)(第四章 复合类型 笔记)
- C Primer Plus(第6版)第六章答案
- C Primer Plus(第6版)第四章答案
- C++Primer Plus(第六版) 第八章 第四题
- C++Primer Plus(第六版) 第十三章 第四题
- C Primer Plus(第六版)第六章编程练习答案。
- C++ primer plus(第六版)第四章练习题
- C++ Primer Plus(第六版)--学习杂记(第四章)
- C++ Primer Plus 第四章 复合类型
- C Primer Plus (第六版)中文版 第十章 编程练习答案
- C Primer Plus (第六版)中文版 第七章 编程练习答案
- C++ Primer Plus第六版 第四章 编程练习答案
- C++ Primer Plus学习:第四章 复合类型(5)
- C++ Primer Plus学习:第四章 复合类型(2)
- C++Primer Plus(第六版) 第六章 第二题
- shader Cg 基本数据类型
- Mysql中的load语句对null的处理
- HYSBZ 2588Spoj 10628. Count on a tree
- numa distance 2
- 数组中出现次数超过一般的数字
- 《C++ Primer Plus(第六版)》(5)(第四章 复合类型 答案2)
- 连续输入密码错误3次,第二天才能登录
- 机器学习-svm.点滴积累
- mysql合并两个表
- linux下安装Mysql
- atitit 短信验证码的源码实现 .docx
- Android Force close是什么引起的?
- 连续型切片与离散加减的思路学习
- web前端之JavaScript DOM编程艺术之DOM