CS201 Assignment #5 Solution
#include <iostream.h>
#include<conio.h>
#include<math.h>
class CRectangle
{
int width, height;
public:
void set_values (int, int);
int area (void)
{
return (width * height);
}
};
void CRectangle::set_values (int a, int b)
{
width = a;
height = b;
}
int main ()
{
CRectangle a, *b, *c;
CRectangle * d = new CRectangle[2];
b= new CRectangle;
c= &a;
a.set_values (2,4);
b->set_values (6,8);
d->set_values (10,12);
d[1].set_values (14,16);
cout<<"a area: " <<a.area()<<endl<<endl;
cout<<"*b area: " <<b->area()<<endl<<endl;
cout<<"*c area: " <<c->area()<<endl<<endl;
cout<<"d[0] area: "<<d[0].area()<<endl<<endl;
cout<< "d[1] area: " <<d[1].area()<<endl<<endl;
getch();
return 0;
}
#include<conio.h>
#include<math.h>
class CRectangle
{
int width, height;
public:
void set_values (int, int);
int area (void)
{
return (width * height);
}
};
void CRectangle::set_values (int a, int b)
{
width = a;
height = b;
}
int main ()
{
CRectangle a, *b, *c;
CRectangle * d = new CRectangle[2];
b= new CRectangle;
c= &a;
a.set_values (2,4);
b->set_values (6,8);
d->set_values (10,12);
d[1].set_values (14,16);
cout<<"a area: " <<a.area()<<endl<<endl;
cout<<"*b area: " <<b->area()<<endl<<endl;
cout<<"*c area: " <<c->area()<<endl<<endl;
cout<<"d[0] area: "<<d[0].area()<<endl<<endl;
cout<< "d[1] area: " <<d[1].area()<<endl<<endl;
getch();
return 0;
}
No comments:
Post a Comment