第六章 编程练习(6-9)
来源:互联网 发布:差评师淘宝怎么处理 编辑:程序博客网 时间:2024/06/05 16:33
编程练习 6
#include <iostream>#include <string>using namespace std;struct donation { string donor; double amount;};int main(){ cout << "Enter the number of donor: "; int num; cin >> num; if (num == 0) cout << "No donor recorded"; else { cin.get(); donation *arrDonation = new donation[num]; donation *arrDonation2 = arrDonation ; cout << "Enter the detail of eacy donor: " << endl; for (int i=0; i< num; i++) { cout << "Donor #" << i+1 << " : "; getline(cin,arrDonation2->donor); cout << "Donor #" << i+1 << " donated: "; cin >> arrDonation2->amount; arrDonation2 ++; } arrDonation2 = arrDonation; // reset the pointer // display Grand Patrons, both name and amount cout << "The list below shows the Grand Patrons: " << endl; int numGrand = 0; for (int i=0; i< num; i++) { if (arrDonation2->amount > 10000) { cout << arrDonation2->donor << "\t" << arrDonation2->amount << endl; numGrand++; } arrDonation2++; } if (numGrand ==0) cout << "None" << endl; arrDonation2 = arrDonation; // reset the pointer // display Grand Patrons, both name and amount cout << "The list below shows the name of Patrons: " << endl; int numPatrons = 0; for (int i=0; i< num; i++) { if (arrDonation2->amount <= 10000) { cout << arrDonation2->donor << endl; numPatrons++; } arrDonation2++; } if (numPatrons ==0) cout << "None" << endl; cin.get(); //delete [] arrDonation; //delete [] arrDonation2; } system("pause"); return 0;}
编程练习 7
#include <iostream>#include <cctype>using namespace std;const int Size = 20;int main(){ int vowels = 0; int consonants = 0; int others = 0; char word[Size]; char ch; cout << "Enter words (q to quit):" << endl; cin >> word; while(strcmp(word,"q")) { //cin >> word; ch = word[0]; if(!isalpha(ch)) others++; else if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') vowels++; else consonants++; cin>>word; } cout << vowels << " words beginning with vowels" << endl; cout << consonants << " words beinning with consonants" << endl; cout << others << " others" << endl; system("pause"); return 0;}
编程练习 8
#include<iostream> #include<fstream> using namespace std; int main() { ifstream inFile; ifstream fin; int count=0; inFile.open("file.txt"); if(!inFile.is_open()) { cout<<"Open Failed!"<<endl; } char ch; inFile>>ch; while(inFile.good()) { count++; inFile>>ch; } if(inFile.eof()) { cout<<"count="<<count<<endl; } system("pause"); return 0;}
编程练习 9 就是把练习6从用户输入改成文件读取了,没舍特别的,这里就偷个懒了
0 0
- 第六章 编程练习(6-9)
- (九十一)第六章编程练习
- 第六章 编程练习(1-5)
- 第六章 编程练习 6.1
- C Primer Plus 第六章 编程练习 9-16题
- python核心编程 第六章练习6-2
- C++ primer plus(sixth edition) 编程练习答案(answers for programing exercises)第六章(chapter 6) 5-9
- 【学习C++】C++ Primer Plus (第六版)第七章编程练习6-10
- 【学习C++】C++ Primer Plus (第六版)第十二章编程练习1-6
- Python核心编程 练习 第六章
- python核心编程--第六章 6.22 练习
- Python核心编程 练习 第六章
- 《Python核心编程》第六章练习解析
- Python 核心编程第六章练习
- Python核心编程 第六章练习
- python核心编程第六章练习
- C++primer plus第六章编程练习
- C++ Primer Plus (第六版)第六章编程练习参考答案
- pickle-泡菜技术
- 使用Visual Studio Code编写STM32程序
- putty通过ssh登录aws的ec2实例
- Win10 64位使用Xilinx ISE14.7点击Open Project崩溃的解决方法
- 【codevs 1023】GPA计算
- 第六章 编程练习(6-9)
- linux 命令终端显示-bash-4.2#解决方法
- 代码实现自定义dialog样式
- 11月12日 最近的学习状态
- Linux思考题
- 折线法与反射原理
- Android:学习AIDL,这一篇文章就够了(下)
- 【Hadoop】搭建完全分布式的hadoop
- RabbitMQ(一) Windows下的 HelloWorld