//第四章编程练习
//eg.1显示信息
#include <iostream>
using namespace std;
const int SIZE = 20;
int main()
{cout << "名字的名是什么?";char first_name[SIZE];cin.get(first_name,SIZE).get();cout << "名字姓是什么?";char second_name[SIZE];cin.get(second_name, SIZE);cout << "你的等级是多少?";char grade;cin >> grade;cout << "你的年龄?";int age;cin >> age;cout << "名字:" << second_name << "," << first_name << endl;grade = grade + 1;cout << "年级:" << grade << endl;cout << "年龄:" << age << endl;system("pause");return 0;
}
//eg.2修改程序4.4,string类代替char类
//#include <iostream>
//#include <string>
//using namespace std;
//int main()
//{// string name;
// string dessert;
// cout << "输入你的名字:\n";
// getline(cin,name);
// cout << "输入你喜欢的点心:\n";
// getline(cin,dessert);
// cout << "我喜欢一些点心" << dessert;
// cout << "," << name << ".\n";
// system("pause");
// return 0;
//}
//eg.3输入名,输入姓,逗号空格组合姓名,存储显示
//#include <iostream>
//#include <cstring>
//const int SIZE = 20;
//int main()
//{// using namespace std;
// char firstName[SIZE];
// char lastName[SIZE];
// char fullName[2 * SIZE + 1];
// cout << "Enter your first name: ";
// cin >> firstName;
// cout << "Enter your last name: ";
// cin >> lastName;
// strncpy_s(fullName, lastName, SIZE);
// strcat_s(fullName, ", ");
// strncat_s(fullName, firstName, SIZE);
// fullName[SIZE - 1] = '\0';
// cout << "Here's the information in a single string: "
//  << fullName << endl;
// cin.get();
// cin.get();
// return 0;
//}
//eg.4string实现题3要求
//#include <iostream>
//#include <string>
//using namespace std;
//const int SIZE = 20;
//int main()
//{// cout << "输入你的名:";
// string ming;
// getline(cin, ming);
// cout << "请输入你的姓:";
// string xing;
// getline(cin, xing);
// string xingming;
// xingming = xing + ", " + ming;//字符串这样连接
// cout << xingming;
// system("pause");
// return 0;
//}
//eg.5一个结构三个成员,声明1个变量,初始化
//#include <iostream>
#include <string> //string logo;
//using namespace std;
//struct CandyBar
//{// char logo[40];
// float weight;
// int kaluli;
//};
//int main()
//{// CandyBar snack
// {//  "Mocha",
//  2.3,
//  350
// };
// cout << snack.logo << " " << snack.weight << " " << snack.kaluli << endl;
// system("pause");
// return 0;
//}
//eg.6创建一个结构数组
//#include <iostream>
//using namespace std;
//struct CandyBar
//{// char logo[40];
// float weight;
// int kaluli;
//};
//int main()
//{// CandyBar snack[3]
// {//  {"candy1",11.1,1},
//  {"candu2",22.2,2},
//  {"candy3",33.3,3}
// };
// cout << "糖果展示如下:\n" << "糖果#1:\n";
// cout << "糖果品牌:" << snack[0].logo << endl;
// cout << "糖果重量:" << snack[0].weight << endl;
// cout << "糖果卡路里:" << snack[0].kaluli << endl;
// cout << "糖果展示如下:\n" << "糖果#2:\n";
// cout << "糖果品牌:" << snack[1].logo << endl;
// cout << "糖果重量:" << snack[1].weight << endl;
// cout << "糖果卡路里:" << snack[1].kaluli << endl;
// cout << "糖果展示如下:\n" << "糖果#3:\n";
// cout << "糖果品牌:" << snack[2].logo << endl;
// cout << "糖果重量:" << snack[2].weight << endl;
// cout << "糖果卡路里:" << snack[2].kaluli << endl;
// system("pause");
// return 0;
//}
//eg.7设计比萨饼结构
//#include <iostream>
//using namespace std;
//const int SIZE = 70;
//struct William_Wingate
//{// char gongsi[SIZE];
// float zhijing;
// float weight;
//};
//int main()
//{// William_Wingate pizza;
// cout << "公司的名称:";
// cin.getline(pizza.gongsi,SIZE);
// cout << "披萨的直径:";
// cin >> pizza.zhijing;
// cout << "披萨的重量:";
// cin >> pizza.weight;
// cout << "公司的名字是:";
// cout << pizza.gongsi << endl;
// cout << "披萨的直径是:";
// cout << pizza.zhijing << endl;
// cout << "披萨的重量是:" ;
// cout << pizza.weight << endl;
// system("pause");
// return 0;
//}
//eg.8new为结构分配内存
//#include <iostream>
//using namespace std;
//const int SIZE = 70;
//struct William_Wingate
//{// char logo[SIZE];
// float zhijing;
// float weight;
//};
//int main()
//{// William_Wingate *ptr = new William_Wingate;
// cout << "你的公司名字:";
// cin >> ptr->logo;
// cout << "你的公司的名字:" << ptr->logo << endl;
// cout << "披萨的直径:";
// cin >> ptr->zhijing;
// cout << "披萨的直径:" << ptr->zhijing << endl;
// cout << "披萨的重量:";
// cin >> ptr->weight;
// cout << "披萨的重量:" << ptr->weight << endl;
// system("pause");
// return 0;
//}
//eg.9new分配动态数组
//#include <iostream>
//using namespace std;
//const int SIZE = 70;
//struct William_Wingate
//{// char logo[SIZE];
// float zhijing;
// float weight;
//};
//int main()
//{// William_Wingate *ptr = new William_Wingate[3];
// strcpy_s(ptr[0].logo, "huawei1");
// ptr[0].zhijing = 1.2;
// ptr[0].weight = 1.234;
// strcpy_s(ptr[1].logo, "huawei2");
// ptr[1].zhijing = 2.2;
// ptr[1].weight = 2.234;
// strcpy_s(ptr[2].logo, "huawei3");
// ptr[2].zhijing = 3.2;
// ptr[2].weight = 3.234;
// cout << "#1:" << endl;
// cout << ptr[0].logo << endl
//  << ptr[0].zhijing << endl
//  << ptr[0].weight << endl;
// cout << "#2:" << endl;
// cout << ptr[1].logo << endl
//  << ptr[1].zhijing << endl
//  << ptr[1].weight << endl;
// cout << "#3:" << endl;
// cout << ptr[2].logo << endl
//  << ptr[2].zhijing << endl
//  << ptr[2].weight << endl;
// system("pause");
// return 0;
//}
//eg.10输入三次成绩,显示次数和平均成绩,array存储
//#include <iostream>
//#include <array>
//using namespace std;
//int main()
//{// array<double, 3> t40;
// cout << "输入第一个人的成绩:";
// cin >> t40[0];
// cout << "输入第二个人的成绩:";
// cin >> t40[1];
// cout << "输入第三个人的成绩:";
// cin >> t40[2];
// cout << "#1:" << t40[0] << endl
//  << "#2:" << t40[1] << endl
//  << "#3:" << t40[2] << endl;
// cout << "平均数是:" << (t40[0] + t40[1] + t40[2]) / 3 << endl;
// system("pause");
// return 0;
//}

C++primer plus第四章编程练习自编程序相关推荐

  1. C++ Primer Plus第四章课后编程

    C++ Primer Plus第四章课后编程 4.12 复习题* 4.13 编程练习* 三句话,希望读者可以先看* 4.12 复习题* #include<iostream> #includ ...

  2. c语言第六版第四章答案,C primer plus 第六版 第6版 004章 第四章 编程 练习 答案 中文...

    第四章 编程练习 1.编写一个程序,提示用户输入名和姓,然后以『名,姓』的格式打印出来. char name[40]; char family[40]; printf("请输入名和姓:\n& ...

  3. C++ Primer Plus 第七章编程题练习

    C++ Primer Plus 第七章编程题练习 第一题 题目描述 编写一个程序,不断要求用户输入两个数,直到其中的一个为0.对于每两个数,程序将使用一个 函数来计算它们的调和平均数,并将结果返回给m ...

  4. c++primer plus 第13章 编程题第2题

    c++primer plus 第13章 编程题第2题 #pragma once #ifndef CD_H_ #define CD_H_ //base classclass Cd { private:c ...

  5. c++primer plus 第11章 编程题第7题

    c++primer plus 第11章 编程题第7题 #pragma once #ifndef COMPLEX0_H_ #define COMPLEX0_H_ #include<iostream ...

  6. C primer plus 第四章课后编程练习答案笔记解释整理

    第四章的编程练习: 1.编写一个程序,提示用户输入名和姓,然后以"名,姓"的格式打印. 编程分析: 程序功能是读取用户输入的字符串,并且重新格式化输出.应该针对名和姓分别定义对应的 ...

  7. C Primer Plus学习_8第四章编程练习(略带解释 )

    第四章就这样结束了,下面我们来做书后习题. 如果你愿意练习,请不要看答案. 每个程序之后可能会有一些解释,都是我做的时候遇到的问题和是如何解决的,如果你还有其他疑问,评论区见,一起探讨. ------ ...

  8. c primer plus 第五章编程练习

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 目录 文章目录 前言 ##1.编写一个程序,把用分钟表示的时间转换成用小时和分钟表示的时间.使用#define或const创 ...

  9. C Primer Plus 第五章 编程练习

    前言 C Primer Plus 第六版,作者:史蒂芬.普拉塔   中国工信出版社 1.编写一个程序,把用分钟表示的时间转换成用小时和分钟表示的时间.使用#define或const创建一个表示60的符 ...

最新文章

  1. C#计算两个日期的相隔天数
  2. eeglab教程系列(7)-数据叠加平均{1}(Data averaging)
  3. WEB 进程的查看和关闭(kill)
  4. java怎么捕捉除数异常_Java异常的捕获及处理---小总结
  5. LeetCode Gray Code 格雷码
  6. Redis学习之Sentinel(四)
  7. OpenShift Express:部署Java EE应用程序(支持AS7)
  8. 命名空间跟作用域是什么关系_魏如萱许光汉首次合唱新歌《什么跟什么有什么关系》_娱乐频道...
  9. 喜欢独自喝茶的人是什么样的人
  10. 博客园五月纪念日——去你的写博无用论
  11. 瑞利衰落条件下扩频通信系统误码率仿真
  12. (翻译)折叠菜单(Accordion Menu)
  13. clion msys2 Mingw 未找到
  14. jhu研究生录取 计算机,背景一般获约翰霍普金斯大学JHU信息安全硕士录取
  15. RK1126从入门到放弃:番外篇(二)Win10 WSL系统下编译buildroot报错不支持SYSV IPC,导致fakeroot无法正常工作
  16. 【MobileNet V2】《MobileNetV2:Inverted Residuals and Linear Bottlenecks》
  17. 2019 My excel
  18. python上市公司_Python批量下载上交所上市公司报告
  19. ChatGPT入门必知必会
  20. 二维数组应用——扫雷

热门文章

  1. 股市利好不断 楼市迎来政策回暖
  2. 微信小程序--动画animation
  3. shell以分号结尾_一个shell脚本引发的对于分号的使用说明
  4. golang 向上取整小技巧
  5. 联想征服者有JAVA_联想发布2020款拯救者系列游戏本:素质过硬,价格良心
  6. 性格决定喜好 12星座最中意的沪上楼盘盘点
  7. ticktock卖给oracle,ticktock第三章怎么过 ticktock第三章玩家一通关攻略
  8. html中垂直线,如何在HTML中创建一条垂直线
  9. Solid-state revolution: in-depth on how SSDs really work
  10. CopyOnWrite线程安全集合