#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. Leetcode: Binary Tree Inorder Transversal

    Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tr ...

  2. java调用存储过程mysql

    在java中调用带返回值的存储过程的实现 直接上代码: DELIMITER $$ CREATE /*[DEFINER = { user | CURRENT_USER }]*/ PROCEDURE `t ...

  3. Linux命令: 结束命令

    1)ctrl+c,退出命令 2)q,退出文件

  4. Hive 常用语句(持续更新中)

    1)按包含关键字在指定库中查找表名:show tables in dw '*_fab_*';   2)查看和删除自己hdfs系统所用的空间和文件(与shell命令合用):hive命令行下: --查看仓 ...

  5. Linux基础命令---chmod

    chmod 改变文件或者目录的权限,可以用数字或者字母来标识权限.在数字模式下:0,代表没有权限:1,代表可执行:2,代表可读:4,代表可写:多个权限可以相加.在字符模式下:x,代表执行:r,代表读: ...

  6. 用rewrite把旧域名直接跳转到新域名的nginx配置

    用rewrite把旧域名直接跳转到新域名的nginx配置 把下面代码保存到daziran.com.conf 放在nginx配置目录下 /etc/nginx/conf.d/ #把旧域名zdz8207直接 ...

  7. Oracle和sql server中复制表结构和表数据的sql语句

    在Oracle和sql server中,如何从一个已知的旧表,来复制新生成一个新的表,如果要复制旧表结构和表数据,对应的sql语句该如何写呢?刚好阿堂这两天用到了,就顺便把它收集汇总一下,供朋友们参考 ...

  8. 【手把手教你树莓派3 (二)】 启动wifi模块

    概述 树莓派3内置了wifi和蓝牙模块,我们不用像以前的版本那样,再去购买一个外接的模块练到raspberry上. 当我们第一次启动了树莓派的时候,必然使用了网线,但是之后的每一次使用,我们当然更希望 ...

  9. LabVIEW如何方便地调用DLL文件

    转自:http://bbs.elecfans.com/jishu_469502_1_1.html   LabVIEW调用DLL文件 LabVIEW支持通过调用DLL文件的方式与其它编程语言混合使用.比 ...

  10. web前端----JavaScript(JS)简单介绍

    JavaScript(JS) 一.JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名ScriptEa ...