7.Betelgeusean plorg 有这些特征。
数据:
●plorg 的名称不超过19个字符;
●plorg 有满意指数(CI),这是一个整数。
操作:
●新的 plorg 将有名称,其 CI值为50;
●plorg 的 CI可以修改;
●plorg 可以报告其名称和 CI:
●plorg 的默认名称为“Plorga”
请编写一个Plorg 类声明(包括数据成员和成员函数原型)来表示 plorg,并编写成员函数的函数定义。
然后编写一个小程序,以演示 Plorg 类的所有特性。
原文链接:https://blog.youkuaiyun.com/zhyjhacker/article/details/139219979
#ifndef LIST_H_
#define LIST_H_
#include<iostream>
class BetelGeusean
{
public:
BetelGeusean(const char* name = "Plorg");
void setCi(const unsigned ci);
void showPlorg(void)const;
private:
static const int LEN = 20;
char chname[LEN];
unsigned ciIdx;
};
#endif // !LIST_H_
函数的实现
#include<iostream>
#include"list.h"
BetelGeusean::BetelGeusean(const char* name)
{
this->ciIdx = 50;
strcpy_s(this->chname, strlen(name) + 1, name);
}
void
BetelGeusean::setCi(const unsigned ci)
{
this->ciIdx = ci;
}
void
BetelGeusean::showPlorg(void)const
{
std::cout << this->chname << " " << this->ciIdx;
}
测试程序
#pragma region 练习7
////程序清单
//xxx.cpp -- xxx
#if 1
#include <iostream>
#include"list.h"
int main()
{
//using namespace std;
BetelGeusean p1;
p1.showPlorg();
std::cout << "\n";
p1.setCi(14);
p1.showPlorg();
return 0;
}
#endif
#pragma endregion
1996

被折叠的 条评论
为什么被折叠?



