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

来源:互联网 发布:网络购物狂欢节 编辑:程序博客网 时间:2024/05/29 19:19

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


/*user.h*/#ifndef USERSH_H_#define USERSH_H_#include <string>class Plorg{private:  enum{MAX=19};  char name[MAX];  int CI;public:  Plorg(char * p="Plorga",int I=50);  void change_CI(int q);  void show()const;};#endif



/*userfucntion.cpp*/#include "usersh.h"#include <iostream>using std::cout;using std::cin;Plorg::Plorg(char * p/* ="Plorga" */,int I/* =50 */){  int i=0;  for (;i<strlen(p);i++)  {    name[i]=p[i];  }  name[i]='\0';  CI=I;}void Plorg::change_CI(int q){  CI=q;}void Plorg::show()const{  cout<<"name:"<<name<<'\n';  cout<<"CI:"<<CI<<'\n';}


/*main*/#include <iostream>#include <Windows.h>#include "usersh.h"#include <string>#include <cctype>using std::cout;using std::cin;int main(){      Plorg car;  car.show();  Plorg money("ppppppp",20);  money.show();  car.change_CI(500);  car.show();  system("pause");  return 0;}