火上房!求一c++程序

来源:百度知道 编辑:UC知道 时间:2024/07/15 17:08:54
设计内容
(一)运用C++语言描述实际的类,类中包含数据成员和成员函数。需要正确地选择函数类型与其参数传递方式。根据测试程序及其输出结果,设计一个满足要求的类。
1.测试程序:
Void main()
{ welcome we;
welcome you(we);
you.Display();
you.Set(“Thank you.”);
cout<<you.Get()<<endl;
you.talk();
you.Display();
}
2.测试程序的输出结果
测试程序的输出结果如下:
Welcome!
Thank you.
输入:how are you?
输出:how are you?
输入:Fine,thank you.
输出:Fine,thank you.
输入:OK
All right!
Goodbye!
OK
Goodbye!
Goodbye!
3.对类的要求
要求按如下原则设计Welcome类:
(1)在头文件cpp1.h中声明类
(2)在cpp1.cpp中实现类
(3)使用字符串、指针、String类等设计类,自己任选一种方法即可。

#include "string.h"
class welcome{
string s;
public:
welcome();
welcome(string);
string get(void);
void set(string);
void talk(void);
void display(void);
}
welcome(string str){
s=str;
}
void welcome::display(){
if (s!="Goodbye!")
cout<<"Welcome!"<<endl;
else cout<<s<<endl;
}
void welcome::set(string str){
cout<<str<<endl;
s=str;
}
void welcome::get(string str){
string s1;
do{
cin>>s1;
cout<<s1<<endl;
}while(s1!="OK");
cout<<"All right!"<<endl;
cout<<"Goodbye!"<<endl;
}
void welcome::talk(string str){
cout<<"OK"<<endl;
cout<<"Goodbye!"<<endl;
s="Goodbye!";
}

void main()
{ welcome we;
welcome you(