網頁文章 網頁文章

#include <stdio.h>
#include <stdlib.h>


class rectangle
{
private:
    int length;
    int width;
public:

rectangle(int x, int y)
{
    length=x; width=y;
}

int area()
{
    return(length*width);
}

void setlength (int a)
{
    length=a;
}
void setwidth (int b)
{
    width=b;
}

};

 

 


int main()
{

rectangle r4(20,30); // 產生物件
printf(" This is used to compute r4 area % d \n", r4.area());

// Reset length, width for r4

r4.setlength(200);
r4.setwidth(200);

printf(" This is used to recompute r4 area % d \n", r4.area());

system("pause");
return 0;
}