【6.9】c++ primer plus 课后编程答案
来源:互联网 发布:国内熟女网络视频 编辑:程序博客网 时间:2024/06/05 03:55
C++ PRIMER PLUS 课后答案
使用IDE为window7系统下的VS2010
#include <iostream>#include <Windows.h>#include <cctype>#include <fstream>#include <string>#include <iomanip>using namespace std;const int money_limit=10000;const int fsize=20;struct patrons{ charname[fsize]; doublemoney;}; int main(){ int size; //标志 bool flag=true; int read_flag=0; //逐行读取标志位 char* m=new char [15]; //数字缓冲区 char* filename=new char [fsize]; ifstream infile; cout<<"pleaseinput file's name : "; cin.getline(filename,fsize); infile.open(filename); if(!infile.is_open()) { cout<<"can'topen this file!"<<endl; system("pause"); exit(1); } infile.getline(m,15,'\n'); //逐行读取,已\n结束 size=atoi(m); //atoi 将字符串转换成整形 patrons * p =new patrons[size]; while((infile.good())&&(!infile.eof())&&(read_flag<size)) { infile.getline(p[read_flag].name,fsize,'\n'); infile.getline(m,15,'\n'); p[read_flag].money=atof(m); read_flag++; } delete[]filename; deletem; cout<<left<<setw(30)<<"Grandpatrons"<<setw(15)<<"money"<<endl; //setw 占用多少位再<iomanip>中 for(int i=0;i<size;i++) { if(p[i].money>money_limit) { cout<<left<<setw(30)<<p[i].name<<setw(15)<<p[i].money<<endl; flag=false; } } if(flag) cout<<endl<<right<<setw(22)<<"!!None!!"<<endl<<endl; else{ flag=true; } cout<<endl<<left<<setw(30)<<"patrons"<<setw(15)<<"money"<<endl; for(int i=0;i<size;i++) { if(p[i].money<=money_limit) { cout<<left<<setw(30)<<p[i].name<<setw(15)<<p[i].money<<endl; flag=false; } } if(flag) cout<<endl<<right<<setw(22)<<"!!None!!"<<endl<<endl; delete[]p; system("pause"); return 0;}
阅读全文
0 0
- C++primer plus第六版课后编程题答案 6.9
- C++primer plus第六版课后编程练习答案6.9
- 【6.9】c++ primer plus 课后编程答案
- C++PRIMER PLUS第六版课后编程答案 4.1-4.5
- C++PRIMER PLUS第六版课后编程答案 4.6-4.10
- C++PRIMER PLUS第六版课后编程答案 5.1-5.5
- C++PRIMER PLUS第六版课后编程答案 5.6-510
- C++primer plus第六版课后编程题答案 6.1
- C++primer plus第六版课后编程题答案 6.2
- C++primer plus第六版课后编程题答案 6.3
- C++primer plus第六版课后编程题答案 6.4
- C++primer plus第六版课后编程题答案 6.5
- C++primer plus第六版课后编程题答案 6.6
- C++primer plus第六版课后编程题答案 6.7
- C++primer plus第六版课后编程题答案 6.8
- C++primer plus第六版课后编程题答案7.1
- C++primer plus第六版课后编程题答案7.2
- C++primer plus第六版课后编程题答案7.3
- JAVA文件名命名规范
- bzoj1727 [Usaco2006 Open]The Milk Queue 挤奶队列 贪心
- POJ 1731 Orders 笔记
- hibernate5的初体验
- 分水岭算法的概念及原理
- 【6.9】c++ primer plus 课后编程答案
- (二叉树的层次遍历)LeetCode#102. Binary Tree Level Order Traversal
- 文档收藏夹
- keras可视化遇到pydot&graphviz无法导入问题
- 倒水
- 【Tensorflow】报错:FailedPreconditionError: Attempting to use uninitialized value keep_prob_7
- Python 中文编码问题
- VC维的来龙去脉
- 并发世界的2个重要定律Amdahl、Gustafson定律