练习基本语法

#include<iostream>
using namespace std;
class rect
{
public:
int len,wid;
rect(int l,int w)
{
len=l;
wid=w;
}
int area()
{
return len*wid;
}

};
void main()
{
rect r1(10,5),*p;
p=&r1;
cout<<(*p).len<<endl;
cout<<p->wid<<endl;
cout<<p->area()<<endl;
}

 

#include<iostream>
using namespace std;
class rect
{
public:
rect(int l=10,int w=5);
int area();
private:
int len;
int wid;
};
rect::rect(int l,int w)
{
len=l;
wid=w;
}
int rect::area()
{
return len*wid;
}
void main()
{
rect r1;
cout<<r1.area()<<endl;
}

posted @ 2023-05-19 10:57  八千里路云和月色  阅读(11)  评论(0)    收藏  举报