C++正在考试 在线等答案 急!!!!! 帮忙各位

来源:百度知道 编辑:UC知道 时间:2024/05/30 14:22:53
二、 编程题
写一个C++程序,声明一个sailboat(帆船类);其私有成员包括制造商、船名、长度、宽度和吃水深度。其set成员函数给所有数据成员进行赋值。Writeinfo函数将船所有数据打印到屏幕上,并重载“〉”操作符用于船对象进行比较,如果一艘船船体较长,则较大。如果长度相同,则宽度大的船较大。
要求:在mian程序要建立有5个元素的sailboat数组。把 sailboat数组5个元素数据显示出来,并把船从小到大的排序结果打印到屏幕上。

#include<iostream>
#include<string>
using namespace std;
class sailboat
{
private:
string creater;//制造商
string name;//船名
double lenth;
double width;
double depth;
public:
void set()
{
cout<<"输入制造商:";
cin>>creater;
cout<<"输入船名:";
cin>>name;
cout<<"输入长度:";
cin>>lenth;
cout<<"输入宽度:";
cin>>width;
cout<<"输入吃水深度:";
cin>>depth;
cout<<endl;
}
void Writeinfo()
{
cout<<"制造商:\t"<<creater<<endl;
cout<<"船名:\t"<<name<<endl;
cout<<"长度:\t"<<lenth<<endl;
cout<<"宽度:\t"<<width<<endl;
cout<<"吃水深度:"<<depth<<endl;
cout<<endl;