C++ Primer Plus 编程练习ch4
来源:互联网 发布:什么是数据库的安全性 编辑:程序博客网 时间:2024/06/08 19:41
4-1
#include<iostream>#include<string>#include<cstring>using namespace std;int main() { cout << "What is your first name? "; char fname[20]; cin.getline(fname, 20); cout << "What is your last name? "; char lname[20]; cin.getline(lname, 20); cout << "What letter grade do you deserve? "; char grade; cin >> grade; cout << "What is your age? "; int age; cin >> age; cout << "Name: " << lname << "," << fname << endl; cout << "Grade: " << ++grade << endl; cout << "Age: " << age << endl; system("pause"); return 0;}
4-2
#include<iostream>#include<string>#include<cstring>using namespace std;int main() { cout << "What is your first name? "; string fname; getline(cin, fname); cout << "What is your last name? "; string lname; getline(cin, lname); cout << "What letter grade do you deserve? "; char grade; cin >> grade; cout << "What is your age? "; int age; cin >> age; cout << "Name: " << lname << "," << fname << endl; cout << "Grade: " << ++grade << endl; cout << "Age: " << age << endl; system("pause"); return 0;}
4-3
#include<iostream>#include<string>#include<cstring>using namespace std;int main() {cout << "Enter your first name:";char fname[20];cin >> fname;cout << "Enter your last name:";char lname[20];cin >> lname;cout << "Here's the information in a single string:";strcat_s(lname, ", ");strcat_s(lname, fname);cout << lname << endl;system("pause");return 0;}
4-4
#include<iostream>#include<string>#include<cstring>using namespace std;int main() {cout << "Enter your first name:";string fname;cin >> fname;cout << "Enter your last name:";string lname;cin >> lname;cout << "Here's the information in a single string:";lname += ", ";lname += fname;cout << lname << endl;system("pause");return 0;}
4-5
#include<iostream>#include<string>#include<cstring>using namespace std;int main() {struct CandyBar {string brand;double weight;int calorie;};CandyBar snack = { "Mocha Munch", 2.3, 350 };cout << "snack.brand = " << snack.brand << endl;cout << "snack.weight = " << snack.weight << endl;cout << "snack.calorie = " << snack.calorie << endl;system("pause");return 0;}
4-6
#include<iostream>#include<string>#include<cstring>using namespace std;int main() {struct CandyBar {string brand;double weight; //poundint calorie;};CandyBar renko[3];renko[0] = { "Mocha Munch", 2.3, 350 };renko[1] = { "Orio Strawberry Cake", 1.1,1390 };renko[2] = { "Egg Pudding", 0.2, 174 };for (int i = 0; i < 3; i++) {cout << "renko[" << i << "].brand = " << renko[i].brand << endl;cout << "renko[" << i << "].weight = " << renko[i].weight << endl;cout << "renko[" << i << "].calorie = " << renko[i].calorie << endl;}system("pause");return 0;}
4-9
#include<iostream>#include<string>#include<cstring>using namespace std;int main() {struct CandyBar {string brand;double weight; //poundint calorie;};CandyBar * renko = new CandyBar[3];renko[0] = { "Mocha Munch", 2.3, 350 };renko[1] = { "Orio Strawberry Cake", 1.1,1390 };renko[2] = { "Egg Pudding", 0.2, 174 };for (int i = 0; i < 3; i++) {cout << "renko[" << i << "].brand = " << renko[i].brand << endl;cout << "renko[" << i << "].weight = " << renko[i].weight << endl;cout << "renko[" << i << "].calorie = " << renko[i].calorie << endl;}delete[] renko;system("pause");return 0;}
4-10
#include<iostream>#include<string>#include<cstring>#include<array>using namespace std;int main() {array<double, 3>run;cout << "The first test: ";cin >> run[0];cout << "The seond test: ";cin >> run[1];cout << "The third test: ";cin >> run[2];double ave = (run[0] + run[1] + run[2]) / 3.0;cout << "The average is " << ave << endl;system("pause");return 0;}
1 0
- C++ Primer Plus 编程练习ch4
- c++primer plus 2.7编程练习作业
- C++primer plus 编程练习10.10
- C Primer Plus第二章编程练习
- c++primer plus第五章编程练习
- C++primer plus第六章编程练习
- C++primer plus第十七章编程练习
- c primer plus 5 ch4 字符串和格式化输入/输出
- C Primer Plus 13章编程练习7问题
- 《C Primer Plus 第五版》第十章编程练习
- C++primer Plus 第六版 编程练习3.7.1
- 《c primer plus》编程练习回顾-第二章
- 《c primer plus》编程练习回顾-第三章
- 《c primer plus》编程练习回顾-第四章
- 《c primer plus》编程练习回顾-第五章
- 《c primer plus》编程练习回顾-第六章
- 《c primer plus》编程练习回顾-第七章
- 《c primer plus》编程练习回顾-第八章
- Android培训笔记
- linux( Ubuntu15.04) 和 win7 双系统情况下,正常关闭win7 无法启动,无法修复提示版本不兼容
- Express开发(一):Node.js、Express安装
- x265-1.7版本-encoder/weightPrediction.cpp注释
- UI_Block传值
- C++ Primer Plus 编程练习ch4
- java-自定义注解
- Hive学习笔记(四) 内部表与外部表
- Unity5.3 AssetBundleName批量赋值
- Leetcode 73. Set Matrix Zeroes
- 经典的GDB调试命令
- 多继承与单继承实现代码复用
- 月下西风卷残霜,徒惹一地冷寒沧桑
- UI_协议传值