# c++primer plus 第六章习题

#include<iostream>
#include<stdlib.h>
//第六章习题
using namespace std;
int main()
{
char ch;
cin.get(ch);
while (ch != '@')
{
if (isalpha(ch))
{
if (islower(ch))
cout << char(ch - 32);
else if (isupper(ch))
cout << char(ch + 32);

}
else if(!(isdight(ch)))
cout << ch;
cin.get(ch);
}
system("pause");
return 0;
}

#include<iostream>
#include<stdlib.h>
//第六章习题
using namespace std;
int main()
{
double donation[10];
double average=0,sum=0;
int i=0,num=0;
while (i<10&&cin>>donation[i])
{
sum += donation[i];
i++;
}
average = sum / i;
cout << "平均值：" <<average << endl;
for (int j = 0; j < i; j++)
{
if (donation[j]>average)
{
num++;
}
}
cout << "超过平均值的数字个数：" << num << endl;
system("pause");
return 0;
}

#include<iostream>
#include<stdlib.h>
//第六章习题
using namespace std;
int main()
{
char choice;

while (cin>>choice&&choice!= 'c' && choice != 'p' && choice != 't' && choice != 'g')
{
cout << "Please enter c p t g :";
}
switch (choice)
{
case 'c': cout << "I love you!\n"; break;
case 'p':cout << "I hate you!\n"; break;
case't':cout << "I miss you!\n"; break;
case'g':cout << "oh my gald!\n"; break;
}
system("pause");
return 0;
}
{
cout << "Please enter c p t g :\n"
"c) carnivore          p) pianist\n"
"t) tree               g) game\n";
}

#include<iostream>
#include<stdlib.h>
//第六章习题
using namespace std;
int main()
{
char choice;
cin >> choice;
while (choice != 'q')
{
switch (choice)
{
case 'a': cout << "I love you!\n"; break;
case 'b':cout << "I hate you!\n"; break;
case'c':cout << "I miss you!\n"; break;
case'd':cout << "oh my gald!\n"; break;
}
cout << "Enter your choice:";
cin >> choice;
}

system("pause");
return 0;
}
{
cout << "Please enter a b c d q :\n"
"a) carnivore          b) pianist\n"
"c) tree               c) game\n"
"q) quit\n"
}

#include<iostream>
#include<stdlib.h>
//第六章习题
using namespace std;
int main()
{
int choice;
double tax;
cout << "Enter your salary:";
while (cin >> choice)
{
if (choice < 0)
break;
else if (choice <= 5000)
{
tax = 0;
cout << "Tax:" << tax << endl;
}
else if (choice>5000&&choice<=15000)
{
tax = (choice-5000)*0.1;
cout << "Tax:" << tax << endl;
}
else if (choice>15000 && choice <= 35000)
{
tax = (choice-15000)*0.15 + 10000 * 0.1;
cout << "Tax:" << tax << endl;
}
else
{
tax = (choice-35000)*0.2 + 20000 * 0.15 + 10000 * 0.1;
cout << "Tax:" << tax << endl;
}
cout << "Enter your salary:";
}

system("pause");
return 0;
}

#include<iostream>
#include<stdlib.h>
#include<string>
#include<cstring>
//第六章习题
using namespace std;
struct donate
{
string  name;
double  money;
};
int main()
{

int num;
cout << "Please enter donate numbers:";
cin >> num;
cin.get();
donate *d1 = new donate[num];
for (int i = 0; i < num; i++)
{
cout << "Please enter name:";
getline(cin,d1[i].name);
cout << "Please enter money:";
cin >> d1[i].money;
cin.get();
}
cout << "Grand Patrons:";
int counter=0;
for (int i = 0; i < num; i++)
{
if (d1[i].money>10000)
{
cout << d1[i].name << '\t'; counter++;
}

}
if (counter == 0)
{
cout << "None !" << endl;
}
cout << '\n';
counter = 0;
cout << "Patrons:";
for (int i = 0; i < num; i++)
{
if (d1[i].money < 10000)
{
cout << d1[i].name << '\t'; counter++;
}
}
cout << "\n";
if (counter == 0)
{
cout << "None !" << endl;
}
delete[]d1;
system("pause");
return 0;
}

#include<iostream>
#include<stdlib.h>
#include<string>
#include<cstring>
//第六章习题
using namespace std;

int main()
{
cout << "Enter words(q to quit):";
string s;
int counter=0,i=0,j=0;
while (cin >> s)
{
if (s[0] == 'q' || s[0] == 'Q')
break;
else if (s[0] == 'a' || s[0] == 'A' || s[0] == 'e' || s[0] == 'E' ||
s[0] == 'i' || s[0] == 'I')
counter++;
else if (s[0] == 'b' || s[0] == 'c')
i++;
else
j++;
}
cout << counter << "words begin with vowels" << endl;
cout << i << "words begin with constants" << endl;
cout << j << "words begin with others" << endl;
system("pause");
return 0;
}

#include<iostream>
#include<stdlib.h>
#include<fstream>
//第六章习题
using namespace std;

int main()
{
ifstream infile;
int count=0;
infile.open("1.txt");
char s;
infile >> s;
while (infile.good())
{
++count;
infile >> s;
}
cout << count << " Items!\n";
infile.close();
system("pause");
return 0;
}

#include<iostream>
#include<stdlib.h>
#include<string>
#include<cstring>
//第六章习题
using namespace std;
struct donate
{
string  name;
double  money;
};
int main()
{

int num;
cout << "Please enter donate numbers:";
cin >> num;
cin.get();
donate *d1 = new donate[num];
for (int i = 0; i < num; i++)
{
cout << "Please enter name:";
getline(cin,d1[i].name);
cout << "Please enter money:";
cin >> d1[i].money;
cin.get();
}
for (int i = 0; i < num; i++)
{
cout <<"Name:"<< d1[i].name <<endl;
cout <<"Money:"<< d1[i].money << endl;
}
delete[]d1;
system("pause");
return 0;
}


• 本文已收录于以下专栏：

## c++ Primer Plus（第六版）第六章习题，写代码之路

c++ Primer Plus（第六版）习题，写代码之路

## C Primer Plus 第六章部分习题

1 时间转换： 代码： void time_change() { while (1) { float min = 0; printf("请输入分钟数:"); scanf_s("%f"...

## C++ Primer Plus（中文版）第六章答案（纯手打）

• 2015-04-11 15:16
• 24KB
• 下载

## 《C++ Primer Plus第6版中文版》学习笔记（第一 ~第六章）

• 2015-12-16 03:03
• 3.30MB
• 下载

## 《C++ Primer Plus（第六版）》（8）（第六章 分支语句和逻辑运算符 笔记和答案）

1.字符函数库头文件     isalnum()    字母或数字     isalpha()    字母     iscntr()     控制字符   &...

## c++_primer_plus(第六版)第二至第六章课后编程练习全部答案

• 2014-06-13 20:46
• 110KB
• 下载

## C++ Primer Plus第6版中文版》学习笔记（至第六章结束）

• 2015-12-15 18:01
• 3.30MB
• 下载

## c++ primer plus(第6版)中文版 第六章编程练习答案

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)