第三周任务2

来源:互联网 发布:python抓取app数据 编辑:程序博客网 时间:2024/04/29 13:08
#include <iostream>

using namespace std;

class Subject
{
public:
 void set_subject();
 void show_subject();
private:
 bool is_subject(double, double, double);
 double length;
    double width;
 double height;
};

int main()
{
 Subject s1, s2, s3;
 s1.set_subject();
 s1.show_subject();
 s2.set_subject();
 s2.show_subject();
 s3.set_subject();
 s3.show_subject();
 
 return 0;
}

void Subject::set_subject()
{
 cout << "请输入所求长方柱的长,宽,高: ";
 while(1)
 {
  cin >> length >> width >> height;
        if(!is_subject(length, width, height))
      cout << "输入的数据非法,请重新输入:" << endl;
  else
   break;
 }
}

void Subject::show_subject()
{
 double S, V;
 S = length * width + length * height + width * height;
 V = length * width * height;
 cout << "所求长方柱的表面积为: " << S << endl;
 cout << "所求长方柱的体积为: :"<< V << endl;
 cout << endl;
}
bool Subject::is_subject(double l, double w, double h)
{
 if(l < 0 || w < 0 || h < 0)
  return false;
 return true;
}

原创粉丝点击