hi for every one this is my Q and after it you will see my code (i know that its simple but i want to know more so please help me
my Q :
rite a declaration of the above class in the specification file named “geometry.h”
v Implement all member functions of Rectangle class outside the class
..................................
v In the client file “Main.cpp”:
o Include the “geometry.h” file
o Declare a Rectangle objects r1, r2, r3 (Using the default values)
o Print the length and width of r1
o Read from user a length and a width
o Change r2 length and width according to entered values
o Print the area and perimeter of r2.
o Change r3 length and width such that its length equals to r1 length and its width equals to r2 width, then print r3 width and length.
----
o Write the assignment statement “r1=r2”
§ Print out r1 length and width
§ What does the above assignment statement do?
§ What condition should be present for the statement to be valid?
§ Try to access private data members of r1 (Can you?)
-----
o Array of objects
§ Declare an array of 10 Rectangles
§ Ask user to input the width and length for 5 rectangles, save them in the array.
§ Print out on screen the Perimeter for the 5 rectangles.
§ Print the Area for the largest rectangle.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
# include<iostream>
# include"geomtry.h"
geomtry::geomtry()
{
width=0;
length=0;
}
void geomtry:: GetLength()
{
return length;
}
void geomtry:: Getwidth()
{
return width;
}
void geomtry::PutWidth ()
{
width=a;
}
void geomtry::Getlength()
{
length=b;
}
int geomtry::area (int,int)
{
return (width*length));
}
int geomtry::Perimeter( int,int)
{
return (2(width+length));
}
// main
# include<iostream>
#include"geomtry.h"
using namespace std;
int main()
{
geomtry r1,r2,r3;
cout<<" the length and width of r1:"<<r1.Getlength()<<endl;
cout<<" the length and width of r1:"<<r1.Getwidth()<<endl;
cout<<" enter length and width \n";
cin>>r1>>r2>>r3;
cout<<" to change the value of r2:"<<endl;
cout<<r2.Getlength()<<r2.Getwidth();
cout<<" print the area ="<<r2.area()<<endl;
cout<<"print the perimeter= "<<r2.Perimeter()<<endl;
r3.Getlength=r1.Getlength;
r3.Getwidth=r2.Getwidth;
cout<<r3.Getlength()<<" "<<r3.Getwidth();
r1=r2;
cout<<r1.Getlength()<<endl;
cout<<r1.Getwidth()<<endl;
return 0;
}
// spesc.
class geomtry {
int width, height;
public:
geomtry();
geomtry (int a,int b);
int area (int,int);
void PutLength();
void Getwidth();
void PutWidth ();
void Getlength();
int Perimeter( int,int);
};
|
with best wishes