您的位置:首页 > 编程语言 > C语言/C++

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

2017-06-04 17:02 344 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: