this is my program----------
the code compiles and all but whenever i display the values for the new rectangle, it doesnt work. like ill enter 5 and 5 for rect2, but itll display like 37365978 and 792654973. can anyone tell me why this/how to fix it?Code:#include <iostream> #include <cstdlib> class rectangle { public: rectangle(); rectangle(int length, int width); ~rectangle() {} int getlength() const {return itslength;} int getwidth() const {return itswidth;} private: int itslength; int itswidth; }; rectangle::rectangle() { itswidth=10; itslength=5; } rectangle::rectangle(int length, int width) { int itslength=length; int itswidth=width; } int main() { rectangle rect1; cout<<"rect1's length is "<<rect1.getlength()<<endl; cout<<"rect1's width is "<<rect1.getwidth()<<endl; int alength; int awidth; cout<<"\n\nNow enter a value for a new rectangle's length:"; cin>>alength; cout<<"\nAnd now a value for its width:"; cin>>awidth; rectangle rect2(alength, awidth); cout<<"The new rectangle's values are:\n"; cout<<"length = "<<rect2.getlength()<<endl; cout<<"width = "<<rect2.getwidth()<<endl; system("PAUSE") return 0; }



LinkBack URL
About LinkBacks


