Clean and rebuild.
Printable View
Clean and rebuild.
That is normal output. Nothing wrong there.
You should be looking at the black console window that pops up.
What does redefine mean in this context?Quote:
But I do have a program related question. I am supposed to redefine two of the objects and then print their outputs. How do I redefine an object. I have what I tried in comment brackets on my main.cpp and received an error when trying that.
I have my 5 objects and I should print the length, width, area, and perimeter. Then I should set new parameter to object one and four and then print their values.
And to the black window comment, nothing shows on it not even "..."
@LearnOnTheFly
Please make sure you "paste as text" when copy/pasting things from your IDE.
Your pastes are full of whatever passes for HTML, and it confuses the hell out of the board to make a decent presentation of it.
Ok, thanks iMalc.
I'm still struggling to solve how redefine objects. I have the five in man and then print their values. How can I set new parameters to the 2 of the objects after displaying the values, then display the new values?
By calling appropriate member functions on the objects! You know the Rectangle is supposed to work, right?
Got it. Sorry, it's taken a bit for object-oriented to soak in. Is there anyway to declare the object name in the print function. I know I can use a cout in main with each object name before calling the print function but I am supposed to use the print function for all display is possible.
Also, how would you take the result from the boolean function and print "This is a square" if the result of the boolean function was true in the print the function. I know I can call the function but not sure how to write a cout statement based on the result. I have looked for examples with no luck.
Ok, I have my boolean function working in print but when I set new values to object 1 from no parameters to length = 5.4 and width = 10.5 it says its still a square
Code:
int
main()
{
Rectangle object1;
Rectangle object2 (7.1, 3.5);
Rectangle object3 (6.3);
Rectangle object4 (21, 22);
Rectangle object5 = object2;
object1.printData();
object2.printData();
object3.printData();
object4.printData();
object5.printData();
object1.setLength(5.4);
object1.setWidth(10.5);
object4.setLength(15.6);
object4.setWidth(15.6);
object1.printData();
object4.printData();
int c;
while((c = getchar()) != '\n' && c != EOF);
}
Code:
Rectangle::squareTest(double L, double W) const
{
if (L-W < .0001){
return true;
}
else{
return false;
}
}
void Rectangle:printData()
{
cout<< "\nLength: " << length;
cout<< "\nWidth: "<< width;
cout<< "\nArea: " << calcArea();
cout<"\nPerimeter: " << calcPerimeter();
if (squareTest(length, width)){
cout<<"\nThis is a square";
}
else{
cout<<"\nThis is a rectangle";
}
Mmm, now would be an excellent time to try out the debugger.
See if you can spot the error. Will do you good practice.