Congrats man!
I am a beginner in C++ myself and I feel extremely happy when I get something to work.
And it really frustrating if I don't haha.
However, even though I am probably on the same level as you I can recommend a few things:
1.If you would like to set the private variables of a class, you can do so through
class constructors, that way you will save your time and not have to call multiple class member functions to set the values for your private variables. Class constructors go under
public:
and they have the same name as your class so your code would look like this -
1 2 3 4 5 6 7 8 9 10
|
class rectangle
{
public:
retangle(int width, int height);
// your get() methods
//now you can get rid of setWidth(), and setHeight()
private:
//your variables
};
| |
I just noticed that you are not using your set() methods to create an object but just to modify it so disregard this, unless you didn't know about it.
2.
Shorter, more concise code. It is generally a good idea to use repeatable code such as
functions, when you are outputting the table of rectangles.
For example, why not do this?
1 2 3 4 5 6 7 8 9 10 11 12
|
class rectangle
{
private:
//your stuff
public:
void show()
{
std::cout << "Height: " << height
<< "\nWidth: " << width
<< "\nArea: " << (height * width) << std::endl;
}
};
| |
That way in your main you could do:
1 2 3 4
|
std::cout << "Rectangle 1: " << std::endl;
one.show();
// you just saved 5 lines of code!
| |
The same would apply for your other functions, short more concise code = easier on the eyes = higher maintainability. I know we are noobs but we should pick up these good habits in order to become better at programming.