1.编写一个程序,读取键盘输入,知道遇到@符号为止,并显示输入,同时将大写字符转化为小写字符,将小写转化为大写。

#include <iostream>
#include <cctype>
using namespace std;
int main()
{cout << "please enter zifu ,zhi dao @ break";char ch;cin.get(ch);while (ch !=' @'){if (isupper(ch)){cout << char(ch + 'a' - 'A');}if (islower(ch)){cout << char(ch + 'A' - 'a');}if (isspace(ch)){cout << ch;}cin.get(ch);}system("pause");return 0;
}

2.编写一个程序,最多将10个donation值读入到一个double数组中。程序遇到非数字输入是将结束输入,并报告这些数字的平均值以及数组中有多少数字大于平均值。

#include <iostream>
#include <cctype>
#include <array>
using namespace std;
int main()
{cout << "please enter 10 donation : ";array<double, 10>kk;double sum=0,ave;int i;for (i = 0; i < 10; i++){cin >> kk[i]; cin.get();sum = sum + kk[i];if (isdigit(kk[i])){break;}   }ave = sum / i;cout << "ping jun zhi wei :" << ave << endl;cout << "da yu zhi de you :";for (int j = 0; j <= i; j++){if (kk[j]>ave){cout << kk[j] << " ";}}system("pause");return 0;
}

3.编写一个菜单驱动程序的雏形。该程序显示一个提供4个选项——每个选项用一个字母标记。如果用户使用有效选项外的字母进行响应,程序将提示用户输入一个有效的字母,直到用户这样子做为止。然后,该程序使用一条switch语句,根据用户选择执行一个简单的操作。该程序的运行情况为:

#include <iostream>
using namespace std;
int main()
{cout << "please enter one of the following chioces: " << endl;cout << "c) carnivore   p)pianist" << endl;cout << "t) tree   g)game" << endl;cout << "please enter a c,p,t,g: ";char j;while (1){cin >> j;switch (j){case 'c':cout << "A maple is a carnivore "; break;case 'p':cout << "A maple is a pianist "; break;case 't':cout << "A maple is a tree"; break;case 'g':cout << "A maple is a game"; break;default:cout << "please enter a c,p,t,g: ";break;}if (j != 'c'&&j != 'p'&&j != 't'&&j != 'g'){continue;}elsebreak;}system("pause");return 0;
}

4.加入Benevolent Order of Programmer 后,在BOP大会上,人们便可以通过加入者的真实姓名,头衔或者密码BOP姓名来了解他,请编写一个程序,可以使用真实姓名,头衔,秘密姓名或者成员偏好来列出成员。编写该程序时,使用结构函数。

#include <iostream>
#define strsize 100
using namespace std;
struct bop
{char fullname[strsize];char title[strsize];char bopname[strsize];int preference;
};
int main()
{cout << "Benevlent Order of Programmers Report" << endl;cout << "a. display by name      b.display by title" << endl;cout << "c.display by bopname    d.display by preference" << endl;cout << "q.quit" << endl;cout << "Enter your choice :";bop *usre = new bop[4];usre[0] = { "Winm Macho", "Winm Macho","Winm Macho", 0};usre[1] = { "Raki Rhodes", "Raki Rhodes", "Raki Rhodes", 1 };usre[2] = { "Celia Laiter", "Celia Laiter", "Celia Laiter", 2 };usre[3] = { "Pat Hand", "Pat Hand", "Pat Hand", 3 };char kk;while (1){cin >> kk;for (int i = 0; i < 4; i++){switch (kk){case 'a':case 'b':case 'c':cout << usre[i].fullname; break;case 'd':cout << usre[i].preference; break;default:break;}}cout << "Next choice ";if (kk == 'q'){cout << "Bye!";break;}}system("pause");return 0;
}

5.在Neutronia王国,货币单位是tvarp,收入税计算为。
5000以下:不收税
5001-15000:收超过部分10%
15001-35000:收上一级全部和超过15000部分的15%
35000以上:收上一级全部超过35000部分的20%

#include <iostream>
#include <cctype>
using namespace std;
int main()
{double k=0;cout << "enter your shou ru:";cin >> k;double j;while ( k >= 0){if (k <= 5000)j = 0;if (k > 5000 && k <= 15000)j = (k - 5000) *0.1  ;if (k > 15000 && k < 35000)j = 1000 + (k + 15000)*0.15;if (k>35000)j = 3250 + (k - 35000)*0.2;cout << "your de shui shou wei : " << j;cout << "enter your shou ru: ";cin >> k;if (cin.fail())//判断是否输入非数字break;}system("pause");return 0;
}

6.编写一个程序记录捐助给“维护合法权利团队”的资金。该程序要求用户输入捐献者数目,然后要求用户输入每一个捐献者的姓名和款项。这些信息被储存在一个动态分配的结构数组中。每个结构有两个成员:用于储存姓名的字符数组和用于存储款项的double成员。读取所有数据后,程序将显示所有捐款超过10000的捐款者的姓名极其捐款数额。该列表前应包含一个标题,指出下面的捐款者是重要的捐款者(Grand Patrons)。然后程序将列出其他的捐款者,该列表要以Patrons开头。如果某种类别没有捐款者,则程序将打印单词“none”。该程序只显示这两种类别,而不进行排序。

#include <iostream>
#include <string>
using namespace std;
struct MyStruct
{string name;double momey;
};
int main()
{cout << "please enter ren shu";int k, j = 0;cin >> k;cin.get();MyStruct *qq = new MyStruct[k];for (int i = 0; i < k; i++){getline(cin, qq[i].name);cin >> qq[i].momey;cin.get();}cout << "Grand Patrons" << endl;for (int i = 0; i < k; i++){if (qq[i].momey >= 10000){cout << qq[i].name << "   " << qq[i].momey << endl;j++;}}if (j == 0)cout << "none" << endl;for (int i = 0; i < j; i++){}cout << "Patrons" << endl;if (j == k)cout << "none" << endl;if (j != k){for (int i = 0; i < k; i++){if (qq[i].momey < 10000)cout << qq[i].name << "   " << qq[i].momey << endl;}}system("pause");return 0;
}

7.编写一个程序,它每次读取一个单词,直到用户只输入q。然后,该程序指出有多少单词以元音大头,有多少单词以辅音打头,还有多少个单词不属于这两类,为此,方法之一是,使用isalpha()来区分以字母和其他字符打头的单词,然后对于通过了usalpha()测试的单词,使用if或switch语句来确定哪些以元音打头。

#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{cout << "Enter words (q to quit):" << endl;int yuan=0, fu=0, other=0;string k;cin >> k;while (k [0]!= 'q'){if (isalpha(k[0])){if (k[0] == 'a' || k[0] == 'e' || k[0] == 'i' || k[0] == 'o' || k[0] == 'u'){yuan++;}else fu++;}else{other++;}cin >> k;}cout << "yuan yin :" << yuan << "  fu yin :" << fu << "  other :" << other;system("pause");return 0;
}

8.编写一个程序,它打开一个文本文件,逐个字符地读取该文件,直到到达文件末尾,然后指出该文件包含多少个字符。

#include <iostream>
#include <fstream>
using namespace std;
int main()
{ifstream infile;char fine[30];cout << "enter your name ";cin.getline(fine, 30);//输入项目文件夹下面的相对位置的文件名,带后缀。infile.open(fine);if (!infile.is_open()){exit(EXIT_FAILURE);}int count = 0;char str;infile >> str;while (infile.good()){count++;infile >> str;}if (infile.eof()){cout << "end";infile.close();cout << count << endl;}system("pause");return 0;
}

9.完成编写练习6,但从文件中读取所需的信息。该文件的第一项应为捐款人数,余下的内容应为成对的行。在每一对,第一行为捐款人姓名,第二行为捐款数额。既该文件类似于下面:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct MyStruct
{char name[20];double k;
};
int main()
{ifstream infile;cout << "please enter your wenjian name: ";string wenname;getline(cin, wenname);//输入文件名字infile.open(wenname);if (!infile.is_open()){exit(EXIT_FAILURE);}int num;infile >> num;infile.get();//数字的换行符string wname;double momey;MyStruct *p = new MyStruct[num];for (int i = 0; i < num; i++){infile.getline( p[i].name,20);infile >> p[i].k;infile.get();}int j = 0;cout << "Grand Patrons" << endl;for (int i = 0; i < num; i++){if (p[i].k >= 10000){cout << p[i].name << "   " << p[i].k << endl;j++;}}if (j == 0)cout << "none" << endl;for (int i = 0; i < j; i++){}cout << "Patrons" << endl;if (j == num)cout << "none" << endl;if (j != num){for (int i = 0; i < num; i++){if (p[i].k < 10000)cout << p[i].name << "   " << p[i].k << endl;}}system("pause");return 0;
}

c++ primer plus编程练习题参考第六章相关推荐

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

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

  2. c++ primer plus编程练习题参考第八章

    1.编写通常接受一个参数(字符串的地址),并打印该字符串的函数,然而提供了第二个参数(int类型)且该参数不为0,则该函数打印的次数将为该函数被调用的次数. #include <iostream ...

  3. 程序员编程艺术:第六章、求解500万以内的亲和数

    第六章.亲和数问题--求解500万以内的亲和数 作者:上善若水.July.yansha. 出处:http://blog.csdn.net/v_JULY_v . 前奏     本章陆续开始,除了继续保持 ...

  4. C++ Primer plus学习笔记-第十六章:string类和标准模板库

    第十六章:string类和标准模板库 前言:这一章已经相当靠近全书的后面部分了:这一章我们会深入探讨一些技术上的细节,比如string的具体构造函数,比如适用于string类的几个函数,比如我们还会介 ...

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

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

  6. C++primer(第五版)第六章编程题

    练习6.3 /******************************************************************************* 编写你自己的fact函数, ...

  7. python快速编程入门课本第六章_python编程快速上手第六章实践项目参考code

    代码如下: 题目的意思是通过一个函数将列表的列表显示在组织良好的表格中,每列右对齐 tableData = [['apples', 'oranges', 'cherries', 'banana'], ...

  8. 【编程珠玑】第六章 程序性能分析

    一,概述 如果要提高软件的性能,需要从下面几个方面入手: 1.算法与数据结构 2.算法调优 3.数据结构重组 4.与系统无关的代码的调优(float取代double). 5.与系统相关的调优,把经常使 ...

  9. 【笔记】面向对象编程--高级程序设计第六章个人总结

    面向对象的程序设计 一.创建对象及原型模式 1.不过,要明确的真正重要的一点就是,这个连接存在于实例与构造函数的原型对象之间,而不是存在于实例与构造函数之间. 2.Person 的每个实例--pers ...

  10. Linux shell编程学习笔记-----第六章变量和引用

    6.1变量 变量可分为本地变量(随着shell进程的消亡而消亡,类似于java C++ 中的局部变量),环境变量(适用于所有由登录进程产生的子进程),位置参数(用于向shell脚本传递参数,是只读的) ...

最新文章

  1. ubuntu 14.04设备OVS虚拟OpenFlow交换机配置汇总
  2. 虫洞协议和闪电网络如何混为一谈?
  3. 如何把一个java程序打包成exe文件,运行在没有java虚
  4. 3D电视,你知道多少?
  5. 企业实战_18_MyCat_ZK集群安装部署
  6. target html语言,html中a标签的target属性
  7. 计算机平面设计专业有哪些课程,计算机平面设计专业课程有哪些?
  8. C#LeetCode刷题之#206-反转链表(Reverse Linked List)
  9. npoi操作word书签_100份Word文档合并只需3分钟?不用复制粘贴,简单到一学就会...
  10. python100例详解-【学习笔记】python100例
  11. linux司机售票员问题
  12. datalist获取id传到下一个页面_如何在 Serverless 架构下优雅上传文件?
  13. Java编码安全规范
  14. 再谈Radmin——对“自己丰衣足食”一文的补充
  15. java linux路径带括号,java执行linux命令 括号
  16. matlab的死区环节,基于SIMULINK对非线性系统死区环节进行仿真
  17. 51单片机教程__模块化编程
  18. win10怎么开启aptx_Soomal作品 - Windows与OSX 操作系统对aptX支持的验证测试报告 [Soomal]...
  19. 吃透Java并发:AQS结构详解及其CLH变种、CLH、MCS
  20. 2021年小组年会总结

热门文章

  1. JMM中的happen-before原则你知道么?
  2. lync2013持久聊天服务器如何修复,部署企业版lync2013之四:持久聊天
  3. CryEngine 渲染流程
  4. SSM的小说网站含前后台-JAVA【数据库设计、源码、开题报告】
  5. 如何在Mac OS X上创建一个Service服务进程
  6. 知乎高赞:哪些事坚持做3个月就会有巨大改变?
  7. python爬取海量PPT模板,再也不用辛苦地找模板了
  8. MySQL数据库getdate_MySQL数据库 DateTime 默认值是不是用getdate
  9. 微信公众号开发python库_轻松实现python搭建微信公众平台
  10. 网络附加存储(NAS)