C++primer plus第六章编程练习
来源:互联网 发布:pdf编辑软件绿色版 编辑:程序博客网 时间:2024/06/11 04:25
6、
#include "stdafx.h"#include<iostream>using namespace std;const int ArSize = 40;struct information{char name[ArSize];double fund;};int main(){cout << "please enter the number of donor:";int number;cin >> number;information *s = new information[number];for (int i = 0; i < number; i++){cout << "please enter the " << i + 1 << "th donor's name: ";cin.sync();cin.getline(s[i].name,ArSize);cout << "please enter the " << i + 1 << "th donor's fund: ";cin >> s[i].fund;}int temp = 0;cout << "Grand Patrons:\n";for (int i = 0; i < number; i++){if (s[i].fund > 10000){cout << s[i].name << " " << s[i].fund << endl;temp++;}}if (temp == 0)cout << "none\n";temp = 0;cout << "Patrons:\n";for (int i = 0; i < number; i++){if (s[i].fund <= 10000){cout << s[i].name << endl;temp++;}}if (temp == 0)cout << "none\n";delete [] s;return 0;}
7、
#include "stdafx.h"#include<iostream>#include<string>#include<cctype>using namespace std;int main(){cout << "Enter words(q to quit):\n";string word;int vowel = 0;int consonant = 0;int others = 0;getline(cin, word);while (word != "q"){if (isalpha(word[0])){switch (word[0]){case 'a':case'A':case 'e':case'E':case 'i':case'I':case 'o':case'O':case 'u':case'U':vowel++; break;default:consonant++; break;}}elseothers++;//cin.sync();getline(cin, word);}cout << vowel << " words beginning with vowels\n";cout << consonant << " words beginning with consonants\n";cout << others << " others\n";return 0;}8、
#include "stdafx.h"#include<fstream>#include<iostream>#include<string>#include<cstdlib>using namespace std;int main(){ifstream inFile;string filename;cout << "please enter filenamde:";cin>>filename;inFile.open(filename+".txt");if (!inFile.is_open()){cout << "could not open the file" << filename << endl;cout << "program terminating.\n";exit(EXIT_FAILURE);}char ch;int count = 0;inFile >> ch;while (inFile.good()){count++;inFile >> ch;}if (inFile.eof())cout << "End of file reached.\n";else if (inFile.fail())cout << "Input terminated by data mismatch.\n";else cout << "Input terminated for unkown reason.\n";if (count == 0)cout << "No data processed.\n";else cout << "The file have " << count << " chars";return 0;}
9、
#include "stdafx.h"#include<iostream>#include<fstream>#include<cstdlib>#include<string>using namespace std;const int ArSize = 40;struct information{char name[ArSize];double fund;};int main(){//读取文件中内容ifstream inFile;string filename;cout << "please enter filenamde:";cin >> filename;inFile.open(filename + ".txt");if (!inFile.is_open()){cout << "could not open the file" << filename << endl;cout << "program terminating.\n";exit(EXIT_FAILURE);}int number;inFile >> number;cout << "number:" << number << endl;information *s = new information[number];int i;for (i = 0; i < number; i++){inFile.get();inFile.getline(s[i].name, ArSize);inFile >> s[i].fund;}inFile.close();//显示if (number == 0)cout << "No data processed.\n";else{int temp = 0;//显示重要捐款者cout << "Grand Patrons:\n";for (int i = 0; i < number; i++){if (s[i].fund > 10000){cout << s[i].name << " " << s[i].fund << endl;temp++;}}if (temp == 0)cout << "none\n";temp = 0;//显示其他捐款者cout << "Patrons:\n";for (int i = 0; i < number; i++){if (s[i].fund <= 10000){cout << s[i].name << endl;temp++;}}if (temp == 0)cout << "none\n";}delete[]s;return 0;}
0 0
- C++primer plus第六章编程练习
- C.Primer.Plus(第六版)第六章编程练习
- C ++ Primer Plus 第六版 第六章编程练习答案
- 《c primer plus》编程练习回顾-第六章
- C primer plus(第五版)编程练习第六章
- c++.primer.plus第五版第六章编程练习答案
- C primer plus 第六章 循环 编程练习
- C Primer Plus 第六章 编程练习 1-8题
- C Primer Plus 第六章 编程练习 9-16题
- C.Primer.Plus(第六版)第五章编程练习
- C.Primer.Plus(第六版)第七章 编程练习
- C.Primer.Plus(第六版)第八章 编程练习
- C.Primer.Plus(第六版)第九章 编程练习
- C.Primer.Plus(第六版)第10章 编程练习
- C ++ Primer Plus 第六版 第七章编程练习答案
- C.Primer.Plus(第六版)第11章 编程练习
- C ++ Primer Plus 第六版 第八章编程练习答案
- C.Primer.Plus(第六版)第12章 编程练习
- 数据结构与算法之整体有序数组的查找
- 【强连通分量】nyoj120 校园网络(模板题)
- 329. Longest Increasing Path in a Matrix
- C++与Java中new关键字的区别
- 关于我的一些事情
- C++primer plus第六章编程练习
- 关于已知两点经纬度求球面最短距离的公式推导
- [BZOJ 3631][JLOI2014]松鼠的新家 dfs
- Burst Balloons
- 关于UTF-8
- Day4 循环和关系表达式
- redis和memcache的区别
- C++之STL--queue模板类
- 《Objective-C编程全解》 读书笔记 第二章