Hello jsbd29,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
Your program did compile, but after some checking I did find some problems.
In main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
int d{}, p{}, n{}; // <--- Good practice to initialize your variables.
//declare the class object
dayType obj;
//Prompt and read the input day
std::cout << " Enter the number:\n 1 - Monday " // <--- Added "\n". Monday should be on its own line.
<< "\n 2 - Tuesday" // <--- Formatting needs to be consistent.
<< "\n 3 - Wednesday"
<< "\n 4 - Thursday"
<< "\n 5 - Friday"
<< "\n 6 - Saturday"
<< "\n 7 - Sunday \n"; // <--- Added second "\n".
// <--- Needs an option to quit.
//prompt the input day
std::cout << " Enter day: ";
std::cin >> d;
// <--- Needs check here to end the program.
|
Still looking into the rest of main, but some parts d not seem right.
In the header file:
Header files are in the wrong place. They should be in the main file with "main".
"using namespace std;" should never be in a header file.
http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/ good reading.
For the class this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
class dayType
{
public: int presday;
int prevday;
int nextday;
//Constructor
dayType()
{
presday = 0;
nextday = 0;
prevday = 0;
}
//Member function declarations
void set(int day);
void print(int day);
int Next_day(int pres);
int Add_Next_days(int day);
int day();
int Prev_day(int pres);
};
|
Should be this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
//Class declaration
class dayType
{
public:
//Constructor
dayType()
{
presday = 0;
nextday = 0;
prevday = 0;
}
//Member function declarations
void set(int day);
void print(int day);
int Next_day(int pres);
int Add_Next_days(int day);
int day();
int Prev_day(int pres);
private:
int presday;
int prevday;
int nextday;
};
|
Otherwise you defeat the purpose of the class.
In the "void dayType::print(int d)" function:
Each cout statement would look better if it ended with a "\n"
You are missing
if (d == 5)
, so "Friday" always prints.
After that I will point out that you include "<iomanip>, but never make use of all that is available. Some of the print calls use a "\t" in the previous cout and spacing is not always the best with a tab. The use of "std::setw()" wuld work better.
Hope that helps,
Andy