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;
}

C++ Primer Plus 编程练习ch4相关推荐

  1. C++ Primer Plus 编程练习3

    C++ Primer Plus 编程练习3 1,编写一个小程序,要求用户使用一个整数指出自己的身高(单位为英寸),然后将身高转换为英尺和英寸.该程序使用下划线字符来指示输入位置.另外,使用一个cons ...

  2. C++ Primer Plus 编程练习4

    C++ Primer Plus 编程练习4 1编写一个C++程序,如下述输出示例所示的那样请求并显示信息: 2,修改程序清单4.4,使用C++ string类而不是char数组. 3,编写一个程序,它 ...

  3. 整理:C Primer Plus 编程练习

    第一章 无 第二章 C Primer Plus 第6版 第2章 编程练习 第三章C Primer Plus 第6版 第3章 编程练习 第四章C Primer Plus 第6版 第4章 编程练习 第五章 ...

  4. C Primer Plus编程题-第五章 运算符、表达式和语句

    第一题: 编写一个程序,把用分钟表示的时间转换成用小时和分钟表示的时间.使用#define或const创建一个表示60的符号常量或const变量.通过while循环让用户重复输入值,直到用户输入小于或 ...

  5. C++primer plus编程练习参考答案

    目录 第2章 开始学习C++ 第3章 处理数据 第4章 复合类型 第5章 循环和关系表达式 第6章 分支语句和逻辑运算符 第7章 函数C++编程模块 第8章 函数探幽 第9章 内存模型和名称空间 第1 ...

  6. C++ Primer Plus编程作业

    编写一个C++程序,如下述输出示例所示的那样请求并显示信息: What is your first name? Betty Sue What is your last name? Yewe What ...

  7. c++ primer plus编程练习题参考第四章

    1.编写一个c++程序,如下述输出示例请求并显示信息. 注意,改程序应该接受的名字包含多个单词,另外,程序将向下调整成绩,既向上条一个字母. #include <iostream> #in ...

  8. C++ Primer Plus 编程练习4.13

    //4.13编程练习#include <iostream> #include<string> #include <vector> #include <arra ...

  9. 【C Primer Plus 编程题】里程和耗油量的测量方案

    编写一个程序,提示用户输入旅行的里程和消耗的汽油量.然后计算并显示消耗每加仑汽油行驶的英里数,显示小数点后面一位数字.接下来,使用1加仑大约3.785升,1英里大约为1.609千米,把单位是英里/加仑 ...

最新文章

  1. ecplise 设置代码自动提示功能的设置
  2. Java:如何更优雅的处理空值?
  3. python多元线性回归模型_python – 使用Tensorflow的多元线性回归模型
  4. linux i o的使用情况,Linux下使用iostat 监视I/O状态
  5. java数组类型转换_java数据类型转换和数组总结
  6. php边框圆角,css3圆角和圆角边框使用方法总结
  7. 使用 mitmproxy + python 做拦截代理
  8. [原]问题解决办法:there are offline or missing virtual drivers with preserved cache
  9. web自动化知识点-01
  10. 解决物理机U盘安装Kali Linux2018.1,光驱无法加载问题
  11. 零件测绘与计算机作图理论试题,浅谈《零部件测绘与cad成图技术》技能竞赛对中职机械制图和cad制图课程整合的影响...
  12. 【转载】北京三险一金计算器
  13. 电力数据可视化大屏设计
  14. OFDM链路自适应算法 注水算法简单c++实现
  15. 计算机信息系统集成高级工程师,软考信息系统项目管理师(高级资格/高级工程师)简介...
  16. 一元函数,多元函数,可微的含义 多元函数微分的几何意义 多元函数偏导 那么为什么有微分和可导 能不能固定两个或者多个条件,多偏微分,哈哈
  17. java我的世界教学视频,快来看鸭~
  18. 2013下学期c语言作业,2013年计算机二级C语言模拟试题三及答案
  19. 如何将阿里云旧服务器上的数据转移到新服务器上
  20. 软件测试自动化分类,自动化测试的主要分类

热门文章

  1. 微信小程序正则表达式判断邮箱格式
  2. 学渣考深大计算机,考深圳大学的研究生难吗?
  3. 公路车sava和Java_入门之作 意外惊喜 SAVA追风5.0公路车 评测
  4. ArcGISPro加载在线底图和影像
  5. 瑞丽噪声与信噪比的关系_信噪比SNR , Eb/N0 , Es/N0区别与联系之深入剖析
  6. 知识图谱-生物信息学-医学顶刊论文(Briefings in Bioinformatics-2021):MPG:一种有效的自我监督框架,用于学习药物分子的全局表示以进行药物发现
  7. 开源!用于3D激光雷达SLAM回环检测的实时词袋模型BoW3D
  8. [系列] - go-gin-api 规划目录和参数验证(二)
  9. android 11中置入第三方应用apk
  10. jenkins连接外部k8s集群