C++primer plus第六版課後程式設計練習答案10.7
阿新 • • 發佈:2019-02-09
標頭檔案
#ifndef PLORG_H_
#define PLORG_H_
const int limit=19;
class plorg
{
private:
char name[limit];
int CI;
public:
plorg(const char *str="Plorga");
void setCI(int n);
void showplorg()const;
};
#endif
#include<iostream> #include "plorg.h" using namespace std; plorg::plorg(const char *str) { strcpy(name,str); CI=50; } void plorg::setCI(int n) { CI=n; } void plorg::showplorg()const { cout<<"name="<<name<<endl; cout<<"CI="<<CI<<endl; }
#include<iostream>
#include "plorg.h"
using namespace std;
void main()
{
plorg a;
a.showplorg();
plorg b("sun");
b.showplorg();
b.setCI(30);
b.showplorg();
}