#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. CUDA从入门到精通 - Augusdi的专栏 - 博客频道 - CSDN.NET

    http://blog.csdn.net/augusdi/article/details/12833235 CUDA从入门到精通 - Augusdi的专栏 - 博客频道 - CSDN.NET CUDA ...

  2. ajax response 系统错误时responseText出现一堆代码

    在后期维护webform的一个项目时遇到个比较大的坑,前台ajax请求,失败时弹出后台自定义的错误信息responsetext.结果在本地运行时能正常弹出“验证码错误”,而发布到服务器上respons ...

  3. python 使用for循环简单爬取图片(1)

    现在的网站大多做了反爬处理,找一个能爬的网站还真不容易. 下面开始一步步实现: 1.简单爬录目图片 import urllib.request import re def gethtml(url): ...

  4. Trove系列(三)—Trove的功能管理功能介绍

    Trove的功能管理功能Trove的功能管理功能包括给各种不同的版本的 datastore 安装不同的 功能. 本管理功能只适用于激活/去活全系统的功能.唯一例外的是数据存储功能列表功能,该功能对所有 ...

  5. Object-C-内存管理 对象生命周期

    autoreleasepool 池子被销毁的时候被标记 autorelease 的对象调用一次release Person *p2=[[[Person alloc]init]autorelease]; ...

  6. Java8函数接口实现回调及Groovy闭包的代码示例

    本文适用于想要了解Java8 Function接口编程及闭包表达式的筒鞋. 概述 在实际开发中,常常遇到使用模板模式的场景: 主体流程是不变的,变的只是其中要调用的具体方法. 其特征是:   Begi ...

  7. python excel操作 练习:#生成一个excel文件,生成3个sheet,每个sheet的a1写一下sheet的名称。每个sheet有个底色

    练习:#生成一个excel文件,生成3个sheet,每个sheet的a1写一下sheet的名称.每个sheet有个底色 #coding=utf-8 from openpyxl import Workb ...

  8. 设置(更改)Mysql 自增ID的起始值

    SELECT * FROM segwords WHERE id>790511 DELETE FROM segwords WHERE id>790511 #下面这句是设置的 ALTER TA ...

  9. jenkins 安装 + maven + git部署

    1. 安装JDK 2. 安装maven 3. 安装git 4. 安装tomcat tar zxvf apache-tomcat-8.5.14.tar.gz 找到tomcat-->config-- ...

  10. 20145321 《网络对抗技术》 MSF基础应用

    20145321 <网络对抗技术> MSF基础应用 实验内容 掌握metasploit的基本应用方式以及常用的三种攻击方式的思路 主动攻击,即对系统的攻击,不需要被攻击方配合,这里以ms0 ...