I am using codeblocks so I don't need a imp.cpp.. |
But you should though. You should have
main.cpp ,
Sales.hpp,
Sales.cpp. I use
hpp because it means a header file with c++ code inside. CodeBlocks has good options for creating the class and it's associated files for you.
You don't really need
setSales
nor
setSalary
, just use the constructor you have. Set functions are only needed if the state is going to change
after the object has been created.
The concept of using
-1
and the infinite loop on line 16 is wrong here. If you have multiple values then you should be using a container like
std::vector
. Try to avoid infinite loops if you can, they are only needed if there are multiple dependent ways of terminating the loop.
Edit:
Salary is not a good name for the class. The clue is that you have employee in the variable names, so
Employee
is a good name for the class, with salary and sales as member variables. Naming is important in OOP design - wrong names can lead to bad design.
The reason why it is evil to put code into header files, is that they can be included multiple times. You should always have header guards and / or
#pragma once
, but really the compiler only needs the declaration of the class. It uses that to go find the definition of class functions - it's not good to put them both together. An
#include
directive basically does a copy/paste of that file, so one can see how that is bad if the file is
#include
d in multiple files.