【发布时间】:2019-12-03 14:41:38
【问题描述】:
main() 函数应该显示一个适当的 如果为任何一个输入非数字或负值,则抛出错误消息 数据成员。
谁能帮我写main函数
这是我的代码
#include <iostream>
using namespace std;
class RealEstate
{
private:
int price;
int bedroomNumb;
int bathsNumb;
public:
RealEstate(int p, int bed, int bath)
{
price = p;
bedroomNumb = bed;
bathsNumb = bath;
}
friend ostream &operator<<(ostream &out, const RealEstate &r);
friend istream &operator>>(istream &in, RealEstate &r);
};
istream &operator>>(istream &in, RealEstate &r)
{
cout << "Enter Real Estate Price: ";
in >> r.price;
cout << "Enter Numbers of Bedroom: ";
in >> r.bedroomNumb;
cout << "Enter Numbers of Baths: ";
in >> r.bathsNumb;
return in;
}
ostream &operator<<(ostream &out, const RealEstate &r)
{
out << "Price: " << r.price << endl;
out << "Bedroom: " << r.bedroomNumb << endl;
out << "Baths: " << r.bathsNumb << endl;
return out;
}
int main()
{
}
【问题讨论】:
-
你的代码没有抛出任何东西?
-
在发生异常情况并在调用堆栈(或没有)的某个地方捕获异常时抛出异常。仅修改
main以引发异常在这里并没有真正意义。是否有可能其他代码应该抛出您应该在main中捕获的异常? -
有一些功能添加到我的代码?我的意思是会被抛出的函数?