c++day2

c++day2_第1张图片

计算矩形的面积

#include 
using namespace std;
class Rect
{
   int width;
   int heigh;
public:
   void init(int w, int h)
   {
       width = w;
       heigh = h;
   }
   void set_w(int w)
   {
       width = w;
   }
   void set_h(int h)
   {
       heigh = h;
   }
   void show()
   {
       cout << "该矩形面积:" << width*heigh << endl;
   }
};
int main()
{
    int h=0;
    int w=0;
    Rect s;
    s.init(h,w);
    cout << "请输入宽度:" ;
    cin >> w ;
    cout << "请输入高度:" ;
    cin >> h;
    s.set_h(h);
    s.set_w(w);
    s.show();
    return 0;
}

c++day2_第2张图片

你可能感兴趣的:(c++)