c++primer plus 第六章习题
2016-05-05 22:07
537 查看
#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; cout << "please enter your number:"; while (i<10&&cin>>donation[i]) { cout << "please enter your number:"; 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; void menu(); int main() { menu(); 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; } void menu() { 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; void menu(); int main() { menu(); 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; } void menu() { cout << "Please enter a b c d q :\n" "a) carnivore b) pianist\n" "c) tree c) game\n" "q) quit\n" "Enter your choice:"; } #include<iostream> #include<stdlib.h> //第六章习题 using namespace std; void menu(); 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++课程 first work
- More Effective C++----(11)禁止异常信息传递到析构函数外
- c 语言 dll编译与使用
- C++ Circle
- c++ 内存分区
- C语言 A律压缩
- boost静态链接库和c++/clr不兼容问题:未能加载文件或程序集,不是有效的Win32应用程序。
- More Effective C++----(10)在构造函数中防止资源泄漏
- 【C++】VS2010生成的程序在安装了vc2010运行库的机器上提示“丢失MSVCR100D.dll”
- C++数组的二分法查找
- C语言中的移位操作
- leetcode 13 Roman to Integer C++
- 【C++】VS2010将写好的程序打包成安装文件发布
- 《高质量C++/C编程指南》代码规范笔记
- PAT (Advanced Level) Practise 1102 Invert a Binary Tree PAT 1102 坑点
- leetcode 92 Reverse Linked List II C++
- C语言内存分配方式
- More Effective C++----异常 & (9)使用析构函数防止资源泄漏
- C++中引用类型
- [Assignment] C++1