十一月二十九日作业

#include "rect.h"
#include  
using namespace  std;
int main()
{
    int h=0,w=0;
    cout << "请输入高度" << endl;
    cin  >> h;
    cout << "请输入宽度"  << endl;
    cin >> w;
    Rect R1;
    R1.init(w,h);
    R1.show();
    return 0;
}
#include "rect.h"
#include  
using namespace  std;

void Rect::init(int w,int h)
{
    width=w;
    height=h;
}
void  Rect::set_w(int w)
{
    width=w;
}
void  Rect::set_h(int h)
{
     height=h;
}
int area(int a,int b)
{
    return  a*b;
}
int peri(int a,int b)
{
    return  (2*a+2*b);
}
void Rect::show()
{
    int a = area(height,width) ;
    int b = peri(height,width);
    cout  << "面积=" << a <<  endl;
    cout   << "周长=" <<  b  << endl;
}

头文件

#ifndef RECT_H
#define RECT_H


class Rect
{
private:
    int width;
    int height;
public:
    void init(int w,int h);
     void set_w(int w);
     void set_h(int h);
    void show();
};
int area(int a,int b);

#endif // RECT_H

十一月二十九日作业_第1张图片

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