8-12.cpp

来自「为C++学习者」· C++ 代码 · 共 56 行

CPP
56
字号
#include<iostream.h>
#include<iomanip.h>
class classroom
{
private:
  float longedge;
  float shortedge;
public:
  classroom(){}
  classroom(float loge,float shge)
  {
    longedge=loge;
	shortedge=shge;
  }
  void getlength()
  {
    cout<<"Input large edge:";
    cin>>longedge;
    cout<<"Input small edge:";
    cin>>shortedge;
  }
  void showsquare()
  {  
    cout<<setprecision(3)
        <<longedge*shortedge<<endl;
  }
  void addsquare(classroom r1,classroom r2);
  void addedge(classroom r1,classroom r2);
};
void classroom::addsquare(classroom r1,classroom r2)
{
  longedge=r1.longedge+r2.longedge;
  shortedge=r1.shortedge+r2.shortedge;
  cout<<"\n Total of classroom square:"
      <<r1.longedge*r1.shortedge+r2.longedge*r2.shortedge;
}
void classroom::addedge(classroom r1,classroom r2)
{
  longedge=r1.longedge+r2.longedge;
  shortedge=r1.shortedge+r2.shortedge;
  cout<<"\n Toatal of classroom length:"
      <<setprecision(3)<<(longedge+shortedge)*2;
}
main()
{
  classroom room1(15.5,6.5);
  classroom room2,room3;
  room2.getlength();
  cout<<"Square of room1 classroom is:";
  room1.showsquare();
  cout<<"square of room2 classroom is:";
  room2.showsquare();
  room3.addsquare(room1,room2);
  room3.addedge(room1,room2);
  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?