what is the prblem in this code????


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
r1=r2 assigns r2 to r1 using the default assignment operator. After the statement executes, r1 and r2 will be identical. I don't think that you did the assignment correctly though. You were supposed to change the values for R2 based on user input and then perform the assignment so that R1 will be identical to R2. Since you did not overload operator>> for the geometry class I am not sure how that code compiles. It looks like you are trying to set r1,r2, and r3 all at the same time with the same user input.
you mean that i have ti use over loading operator ???
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153





#include<iostream>

class geomtry {

private:

int width, length;

public:

geomtry();

geomtry (int a,int b);

int area ();

void PutLength(int);

int Getwidth();

void PutWidth (int);

int Getlength();

int Perimeter();

};



////////////////////////

geomtry::geomtry()

{

width=0;

length=0;

}



int geomtry::Getlength()

{

return length;

}



int geomtry:: Getwidth()

{

return width;

}



void geomtry::PutWidth (int a)

{

width=a;

}



void geomtry::PutLength(int b)

{

length=b;

}





int geomtry::area ()

{

return (width*length);

}



int geomtry::Perimeter()

{

return (2*(width+length));

}

//////////////////////////



using namespace std;

int main()

{



geomtry r[3];



cout<<" the length and width of r1:"<<r[0].Getlength()<<endl;

cout<<" the length and width of r1:"<<r[0].Getwidth()<<endl;

for(int i=0;i<3;i++)

{

	cout<<" enter length and width \n";

	int a;

	cout<<i+1<<" Width= ";

	cin>>a;

	r[i].PutWidth(a);

	cout<<i+1<<" Length= ";

	cin>>a;

	r[i].PutLength(a);

}

}



there is no errors but at the execution (enter width and length looped )
i hope to correct my code
Topic archived. No new replies allowed.