#include <iostream>
#include <cctype>
using namespace std; int main()
{
char in_put; do
{
cout << "Please enter the letters (enter @ exit):";
cin >> in_put; if (islower(in_put))
cout << "The uppercase of the letter " << in_put << " is " << char (toupper(in_put)) << ".\n";
else if (isupper(in_put))
cout << "The lowercase of the letter " << in_put << " is " << char (tolower(in_put)) << ".\n";
else if (in_put != '@')
cout << "Please enter the letters!\n";
} while (in_put != '@'); cout << "Exit!\n"; system("pause");
}

#include <iostream>
using namespace std;
const int MAX = ; int main()
{
double in_put[MAX];
double avg = ;
int sum; cout << "Please enter no more than " << MAX << " digits.\n";
for (int i = ; i < MAX; ++i)
{
cout << "The " << i + << "th digit is: ";
if (cin >> in_put[i])
avg += in_put[i];
else
{
cout << "Not digit! Exit!\n";
sum = i;
break;
}
} avg = avg / sum;
int num_a=, num_b=;
for (int i = ; i < sum; ++i)
{
if (in_put[i] > avg)
num_a += ;
else
num_b += ;
} cout << "The average of these numbers is: " << avg << ".\n"
<< "There are " << num_a << " numbers larger than the average value.\nAnd "
<< num_b << " numbers not larger than the average value.\n"; system("pause");
}

#include <iostream>
using namespace std;
int show(char); int show(char ch)
{
int flag = ;
cout << "A maple is a ";
switch(ch)
{
case 'c':
cout << "carnivore.\n";
break;
case 'p':
cout << "pianist.\n";
break;
case 't':
cout << "tree.\n";
break;
case 'g':
cout << "game.\n";
break;
default:
cout << "Please enter c,p,t,g :";
flag = ;
}
return flag;
} int main()
{
char ch;
int flag; cout << "Please enter one of the following choices:\n"
<< "c) carnivore\t" << "p) pianist\n"
<< "t) tree\t\t" << "g) game\n"; do
{
cin >> ch;
flag=show(ch);
} while (flag == ); system("pause");
}

#include <iostream>
using namespace std;
const int strsize = ;
const int MAX = ; struct bop
{
char fullname[strsize];
char title[strsize];
char bopname[strsize];
int preference;
}; int show(char ch, bop mmm[MAX])
{
int flag = ;
switch (ch)
{
case 'a':
for (int i = ; i < MAX; ++i)
{
cout << mmm[i].fullname<<endl;
}
break;
case 'b':
for (int i = ; i < MAX; ++i)
{
cout << mmm[i].title << endl;
}
break;
case 'c':
for (int i = ; i < MAX; ++i)
{
cout << mmm[i].bopname << endl;
}
break;
case 'd':
for (int i = ; i < MAX; ++i)
{
switch(mmm[i].preference)
{
case :cout << mmm[i].fullname << endl;
break;
case :cout << mmm[i].title << endl;
break;
case :cout << mmm[i].bopname << endl;
break;
}
}
break;
case 'q':
flag = ;
break;
default:
cout << "Please enter a,b,c,d,q!\n";
}
return flag;
} int main()
{
bop all_peo[MAX] =
{
{ "QQQ","NiCai","qqq", },
{ "WWW","BuCai","www", },
{ "EEE","CaiBuCai","eee", },
{ "RRR","JiuBuCai","rrr", },
{ "TTT","LaDao","ttt", }
}; char ch;
int flag; cout << "Benevolent Order of Programmers Report\n"
<< "a. display by name\t" << "b. display by title\n"
<< "c. display by bopname\t" << "d. display by preference\n"
<< "q. quit\n"; cout << "Enter your choice:";
cin >> ch; flag = show(ch, all_peo); while (flag == )
{
cout << "Next choice: ";
cin >> ch;
flag=show(ch, all_peo);
}
cout << "Bye!\n"; system("pause");
}

#include <iostream>
using namespace std;
const float Tax_1 = 0.1;
const float Tax_2 = 0.15;
const float Tax_3 = 0.2;
const int Tax_come1 = ;
const int Tax_come2 = ;
const int Tax_come3 = ; double Tax(double); int main()
{
double income; cout << "Please enter income(enter a negative or non-numeric exit): ";
while (cin >> income)
{
if (income < )
break;
double tax;
tax=Tax(income);
cout << "Income tax: " << tax << "\nNext enter: ";
}
cout << "Bye!\n"; system("pause");
} double Tax(double income)
{
double tax;
double num1 = income - Tax_come3;
double num2 = income - Tax_come2;
double num3 = income - Tax_come1;
if (num1 > )
tax =(Tax_come2 - Tax_come1)*Tax_1 + (Tax_come3 - Tax_come2)*Tax_2 + num1 * Tax_3;
else
{
if (num2 > )
tax =(Tax_come2 - Tax_come1)*Tax_1 + num2 *Tax_2;
else
{
if (num3 > )
tax = num3 * Tax_1;
else
tax = ;
}
} return tax;
}

#include <iostream>
#include <string>
using namespace std; struct potron
{
string name;
double money;
}; int main()
{
int num;
cout << "Please enter the number of donors: ";
cin >> num; potron *potrons = new potron[num];
for (int i = ; i < num; ++i)
{
cout << "Please enter the " << i + << "th donor name:";
cin.ignore();
getline(cin,potrons[i].name);
cout << "Please enter the number of " << i + << "th donor contributions:";
cin >> potrons[i].money;
} int flag1 = , flag2 = ;
cout << "Grand Potrons\n";
for (int i = ; i < num; ++i)
{
if (potrons[i].money > )
{
cout << potrons[i].name << " : " << potrons[i].money << endl;
flag1 = ;
}
}
if (flag1 == )
cout << "None!\n"; cout << "Potrons\n";
for (int i = ; i < num; ++i)
{
if (!(potrons[i].money > ))
{
cout << potrons[i].name << " : " << potrons[i].money << endl;
flag2 = ;
}
}
if (flag2 == )
cout << "None!\n"; system("pause");
}

#include <iostream>
#include <cctype>
using namespace std;
const int MAX = ; int main()
{
char words[MAX][];
char ch;
int num_y = , num_f = , num_o = ; cout << "Enter words (q to quit):\n";
for (int i = ; i < MAX; ++i)
{
cin >> words[i];
ch = words[i][];
if (ch == 'q')
break;
if (isalpha(ch))
{
switch (ch)
{
case 'a':;
case 'e':;
case 'i':;
case 'o':;
case 'u':
num_y += ;
break;
default:
num_f += ;
break;
}
}
else
num_o += ;
} cout << num_y << " beginning with vowels\n";
cout << num_f << " beginning with consonants\n";
cout << num_o << " others\n";
system("pause");
}

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
const int SIZE = ; int main()
{
char filename[SIZE];
ifstream infile;
cout << "Enter name of data file: ";
cin.getline(filename, SIZE);
infile.open(filename);
if (!infile.is_open())
{
cout << "Could not open the file " << filename << endl;
cout << "Program terminating.\n";
exit(EXIT_FAILURE);
} int count=;
char ch; infile >> ch;
while (infile.good())
{
++count;
// ch= infile.get();//读取空白字符
infile >> ch;//不读取空白字符
} cout << "The number of characters in the file is: " << count << endl; system("pause");
}

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
const int SIZE = ; struct potron
{
string name;
double money;
}; int main()
{
char filename[SIZE];
ifstream infile;
cout << "Enter name of data file: ";
cin.getline(filename, SIZE);
infile.open(filename);
if (!infile.is_open())
{
cout << "Could not open the file " << filename << endl;
cout << "Program terminating.\n";
exit(EXIT_FAILURE);
} int num;
infile >> num; potron *potrons = new potron[num];
for (int i = ; i < num; ++i)
{
infile.ignore();
getline(infile, potrons[i].name);
infile >> potrons[i].money;
} int flag1 = , flag2 = ;
cout << "Grand Potrons\n";
for (int i = ; i < num; ++i)
{
if (potrons[i].money > )
{
cout << potrons[i].name << " : " << potrons[i].money << endl;
flag1 = ;
}
}
if (flag1 == )
cout << "None!\n"; cout << "Potrons\n";
for (int i = ; i < num; ++i)
{
if (!(potrons[i].money > ))
{
cout << potrons[i].name << " : " << potrons[i].money << endl;
flag2 = ;
}
}
if (flag2 == )
cout << "None!\n"; system("pause");
}

c++ primer plus 第六章 课后题答案的更多相关文章

  1. c++ primer plus 第七章 课后题答案

    #include <iostream> using namespace std; double HAR_AVG(double, double); void TEST(bool); int ...

  2. c++ primer plus 第五章 课后题答案

    #include <iostream> using namespace std; int main() { ; cout << "Please enter two n ...

  3. c++ primer plus 第四章 课后题答案

    #include<iostream> #include<string> using namespace std; int main() { string first_name; ...

  4. c++ primer plus 第三章 课后题答案

    #include<iostream> using namespace std; int main() { ; int shen_gao; cout <<"Please ...

  5. python 核心编程第六章课后题自己做的答案

    6–6. 字符串.创建一个 string.strip()的替代函数:接受一个字符串,去掉它前面和后面的 空格(如果使用 string.*strip()函数那本练习就没有意义了) 'Take a str ...

  6. c++ primer plus 第二章 课后题答案

    #include<iostream> using namespace std; int main() { cout << "My name is Jiantong C ...

  7. python核心编程第5章课后题答案

    5-8Geometry import math def sqcube(): s = float(raw_input('enter length of one side: ')) print 'the ...

  8. python核心编程第4章课后题答案(第二版75页)

    4-1Python objects All Python objects have three attributes:type,ID,and value. All are readonly with ...

  9. python核心编程第3章课后题答案(第二版55页)

    3-4Statements Ues ; 3-5Statements Use\(unless part of a comma-separated sequence in which case \ is ...

随机推荐

  1. iOS 网易彩票-5设置模块二

    产品推荐 产品推荐使用的是UICollectionView控件,UICollectionView 和 UICollectionViewController 类是iOS6 新引进的API,用于展示集合视 ...

  2. servlet07

    1.session验证 可以防止非登录的用户,通过在地址栏中输入地址,访问受保护的页面 step1.在用户登录成功之后,将用户的信息保存到session中 step2.在访问受保护的页面时,校验ses ...

  3. MyBatis学习笔记(八)——Mybatis3.x与Spring4.x整合

    转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn arc ...

  4. Python2 和Python3 的差异总结

    一.基本语法差异 1.1 核心类差异 Python3对Unicode字符的原生支持 Python2中使用 ASCII 码作为默认编码方式导致string有两种类型str和unicode,Python3 ...

  5. linux centos系统下升级python版本

    本文参考资料:https://www.cnblogs.com/leon-zyl/p/8422699.html,https://blog.csdn.net/tpc1990519/article/deta ...

  6. 删除对象的属性 delete的用法

    Javascript的变量 实际上JavaScript中,变量 = 对象属性,这是因为 Javascript 在执行脚本之前会创建一个Global对象,所有的全局变量都是这个Global对象的属性,执 ...

  7. python-随机数的产生random模块

    random模块用来产生随机数: 查看random模块的方法: import random random.__dir__ Out[39]: <function __dir__> rando ...

  8. Linux 系统版本信息

    1.# uname -a   (Linux查看版本当前操作系统内核信息) 2.# cat /proc/version (Linux查看当前操作系统版本信息) 3.# cat /etc/issue  或 ...

  9. PHP进程及进程间通信

    一.引言 进程是一个具有独立功能的程序关于某个数据集合的一次运行活动.换句话说就是,在系统调度多个cpu的时候,一个程序的基本单元.进程对于大多数的语言都不是一个陌生的概念,作为"世界上最好 ...

  10. 08: 查看Linux系统基本信息和硬盘CPU等

    目录: 1.1 查看Linux系统基本信息 1.2 查看三秒内的平均CPU 1.3 查看内存使用情况 1.4 查看当前系统负载 1.1 查看Linux系统基本信息返回顶部 1.查看Linux系统uui ...