date class HELP!!!
Nov 11, 2015 at 11:23pm UTC
I'm trying to implement class to represent Date has :
Attributes:
- Day: int
- Month: int
- Year:int
Methods:
- Constructor Date(string date): takes string in format “dd/mm/yyyy”
- Constructor Date(int day ,int month ,int year)
- Setters/getters -for all member variables
and this is what i can go far
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
//header file
#ifndef DATE_H
#define DATE_H
#include <string>
#include <iostream>
using namespace std;
class Date
{
private :
int day, month, year;
public :
//Constructors
// Date(string date);
Date();
Date (int d, int m , int y);
//Setters
void setDay (int x);
void setMonth (int x);
void setYear (int x);
//Getters
void getDate ();
};
#endif // DATE_H
// Date.cpp
#include "Date.h"
#include <iostream>
using namespace std;
Date::Date()
{
day = 11;
month = 2;
year = 1996;
}
Date::Date (int d , int m , int y)
{
day = d;
month = m;
year = y;
}
/***********************************************/
void Date::setDay(int x)
{
day = x;
}
void Date::setMonth(int x)
{
month = x;
}
void Date::setYear(int x)
{
year = x;
}
/*********************************************/
void Date::getDate()
{
cout <<day<<"-" <<month<<"-" <<year<<endl;
}
/**********************************************/
// main.cpp
#include <iostream>
#include "Date.h"
using namespace std;
int main()
{
Date test;
test.setDay(1);
test.setMonth(1);
test.setYear(2021);
test.getDate();
return 0;
}
but it doesn't run why
Can anyone help pls????
and it's not complete yet i just want to check the part of code i've reached till now
Last edited on Nov 12, 2015 at 12:48am UTC
Nov 12, 2015 at 12:06am UTC
What kind of error u have?
Put here for us.
Nov 12, 2015 at 12:47am UTC
sorry for this mistake but it's not an error , it's don't run anything just the console screen and returned 0 (as the program finish )
Nov 12, 2015 at 1:38am UTC
make line 89
system("pause" );
After a slight change to comment out the date #includes, this is what you get on the shell here:
1-1-2021
Exit code: 0 (normal program termination)
Last edited on Nov 12, 2015 at 1:42am UTC
Topic archived. No new replies allowed.