c++ primer plus 第六章 课后题答案

时间:2022-09-23 10:40:32

c++ primer plus 第六章 课后题答案

#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");
}

c++ primer plus 第六章 课后题答案

#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");
}

c++ primer plus 第六章 课后题答案

#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");
}

c++ primer plus 第六章 课后题答案

c++ primer plus 第六章 课后题答案

#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");
}

c++ primer plus 第六章 课后题答案

c++ primer plus 第六章 课后题答案

#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;
}

c++ primer plus 第六章 课后题答案

#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");
}

c++ primer plus 第六章 课后题答案

#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");
}

c++ primer plus 第六章 课后题答案

#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");
}

c++ primer plus 第六章 课后题答案

#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&plus;&plus; primer plus 第七章 课后题答案

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

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

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

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

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

  4. c&plus;&plus; 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&plus;&plus; 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. &lbrack;LeetCode&rsqb; Paint House 粉刷房子

    There are a row of n houses, each house can be painted with one of the three colors: red, blue or gr ...

  2. 《理解 ES6》阅读整理:函数(Functions)(七)Block-Level Functions

    块级函数(Block-Level Functions) 在ES3及以前,在块内声明一个函数会报语法错误,但是所有的浏览器都支持块级函数.不幸的是,每个浏览器在支持块级函数方面都有一些细微的不同的行为. ...

  3. RADOS工作原理

    转:http://www.csdn.net/article/2014-04-08/2819192-ceph-swift-on-openstack-m/2 Ceph的工作原理及流程 本节将对Ceph的工 ...

  4. Ubuntu下开发环境搭建

    安装基础开发包,主要gcc,g++等 sudo apt-get install build-essential 未完待续

  5. typings 命令使用注意

    1.如果要查询一些库 typings search xxx 2.安装jquery node 这样的库要这样 typings dt~node --global --save   一定要dt~xxx ,然 ...

  6. 菜鸟之旅——学习线程(Task)

    前面两篇回顾线程和线程池的使用方法,微软在.NET4.5推出了新的线程模型-Task.本篇将简单的介绍Task的使用方法. Task与线程 Task与线程或者说线程池关系紧密,可以说是基于线程池实现的 ...

  7. 《HelloGitHub月刊》第 08 期

    <HelloGitHub>第 08 期 兴趣是最好的老师,<HelloGitHub>就是帮你找到兴趣! 简介 最开始我只是想把自己在浏览GitHub过程中,发现的有意思.高质量 ...

  8. 雷林鹏分享:jQuery EasyUI 数据网格 - 设置冻结列

    jQuery EasyUI 数据网格 - 设置冻结列 本实例演示如何冻结一些列,当用户在网格上移动水平滚动条时,冻结列不能滚动到视图的外部. 为了冻结列,您需要定义 frozenColumns 属性. ...

  9. 戴尔服务器H330阵列卡取消磁盘阵列教程

    一:服务器开机看到ctrl+R提示,按ctrl+r进入阵列卡配置界面 二:按ctrl+N 转到PD Mgmt查看硬盘信息,确认硬盘状态:Ready 三:光标移到需配置硬盘上,按F2,选择 conver ...

  10. MySql详解(六)

    MySql详解(六) MySql事务 一.含义 事务:一条或多条sql语句组成一个执行单位,一组sql语句要么都执行要么都不执行 二.特点(ACID) A 原子性:一个事务是不可再分割的整体,要么都执 ...