【6.2】c++ primer plus 课后编程答案

来源:互联网 发布:国内熟女网络视频 编辑:程序博客网 时间:2024/06/05 03:26

C++ PRIMER PLUS 课后答案 
使用IDE为window7系统下的VS2010

#include <iostream>#include <Windows.h>#include <cctype>#include <array>#include <fstream>#include <string>using namespace std;const int size=10;const int fsize=20;int main(){  double vaul;  double sum=0.0,average=0.0;  int count=0;  int num_count=0;  char * filename=new char [fsize];  array<double,size>donation;  ifstream infile;  cout<<"please input filename:";  cin.getline(filename,fsize);  infile.open(filename);  if(!infile.is_open())  {    cout<<"cant open this file!";    system("pause");    delete [] filename;    return 0;  }  infile>>vaul;  while((infile.good())&&(count<10))  {    donation[count]=vaul;    sum+=vaul;    infile>>vaul;    count++;  }  if(infile.eof()){    cout<<"end of this file"<<endl;  }  average=sum/count;  for(int i=0;i<count;i++)  {    if(donation[i]>average)      num_count++;  }  cout<<"average="<<average<<endl;  cout<<"the big than average num count:"<<num_count<<endl;  delete [] filename;  system("pause");  return 0;}

原创粉丝点击