Whitespace is ok, nothing bad. I would still include variable names in prototypes of functions, these are sometimes useful when you are reading function. You can understand function better(of course not always, but still :)
First off - you have already width and length of your square. So why use some other variables? Simply do this:
1 2 3 4 5 6 7 8
|
void square::area ()
{
cout << "Enter the width of the square:";
cin >> width;
cout << "Enter the length of the square:";
cin >> length;
cout << "The area of the square is " << length * width << endl;
}
|
Also, I would change this function if I were you:
|
cout << "The area of the square is " << length * width << endl;
|
Because it makes no sense to ask for width and height every time you want to calculate area of same square. You could simply make another function:
1 2 3 4 5
|
void square::ChangeSize(int w, int h)
{
width = w;
height = h;
}
|
Ideally, you wouldn't even use cout, because you may want to use area to some calculations. So you could do something like this:
1 2 3 4
|
int square::area()
{
return width*length;
}
|
Also, for correctness's sake - rectangle has same width and height. You are creating rectangle now :)
As for habits - I like Allman, so I won't comply :) However, instead of using
using namespace std
I would recommend putting
std::
before every std's object/function. It's safer(no name collisions), and considered better habit.
Cheers!