V
vgame64
Hi, I have been struggling with writing a program for a few hours. The
requirements are that: """You will be writing a program which will
determine whether a date is valid in
terms of days in that month. We are assuming that the year will be
valid 4 digit integer.
So you don't have to think much about that(in terms of validation)
except for the month
of February. If the month is February, then you have to check whether
that year is Leap
year or not before checking the date.
Create a class called Date. Include three private variables : date,
month and year
(declare as int type). Include following member functions:
1. A constructor Date(month. date, year)which will initialize the date,
month and
year of the object with user specified values.
2. valid_Date(): which will determine whether the date is valid or
not."""
That and we have to use a switch statement for the month validation.
I have the following:
"Date.h"
#include<iostream>
class Date
{
public:
Date(int,int,int);
void valid_Date();
private:
int month,date,year;
};
"Date.cpp"
#include <iostream>
#include<string>
using namespace std;
#include "Date.h"
Date:ate(int n1,int n2, int n3)
{
if ( n1 > 0 && n1 <= 12 )
month = n1;
else {
month = 1;
cout << "Month " << n1 << " invalid.";
}
date = n2;
year = n3;
cout << endl;
}
void Date::valid_Date()
{
if (month = 02)
{
if (year%2 == 0)
cout << "Your date is " << month << date << year << endl;
}
else
cout << "Your date is invalid!" << endl;
}
int main(void)
{
int m, d, y;
char ch;
cout << "Input a date as dd/mm/yy: ";
cin >> d >> ch >> m >> ch >> y;
switch (month) {
case 1: cout << "January"; break;
case 2: cout << "February"; break;
case 3: cout << "March"; break;
case 4: cout << "April"; break;
case 5: cout << "May"; break;
case 6: cout << "June"; break;
case 7: cout << "July"; break;
case 8: cout << "August"; break;
case 9: cout << "September";break;
case 10: cout << "October"; break;
case 11: cout << "November"; break;
case 12: cout << "December"; break;
}
return 0;
}
My mind wandered and tried multiple different approaches..and I ended
up with that crap...can some1 help me make the program work to the reqs
placed above..thanks!
requirements are that: """You will be writing a program which will
determine whether a date is valid in
terms of days in that month. We are assuming that the year will be
valid 4 digit integer.
So you don't have to think much about that(in terms of validation)
except for the month
of February. If the month is February, then you have to check whether
that year is Leap
year or not before checking the date.
Create a class called Date. Include three private variables : date,
month and year
(declare as int type). Include following member functions:
1. A constructor Date(month. date, year)which will initialize the date,
month and
year of the object with user specified values.
2. valid_Date(): which will determine whether the date is valid or
not."""
That and we have to use a switch statement for the month validation.
I have the following:
"Date.h"
#include<iostream>
class Date
{
public:
Date(int,int,int);
void valid_Date();
private:
int month,date,year;
};
"Date.cpp"
#include <iostream>
#include<string>
using namespace std;
#include "Date.h"
Date:ate(int n1,int n2, int n3)
{
if ( n1 > 0 && n1 <= 12 )
month = n1;
else {
month = 1;
cout << "Month " << n1 << " invalid.";
}
date = n2;
year = n3;
cout << endl;
}
void Date::valid_Date()
{
if (month = 02)
{
if (year%2 == 0)
cout << "Your date is " << month << date << year << endl;
}
else
cout << "Your date is invalid!" << endl;
}
int main(void)
{
int m, d, y;
char ch;
cout << "Input a date as dd/mm/yy: ";
cin >> d >> ch >> m >> ch >> y;
switch (month) {
case 1: cout << "January"; break;
case 2: cout << "February"; break;
case 3: cout << "March"; break;
case 4: cout << "April"; break;
case 5: cout << "May"; break;
case 6: cout << "June"; break;
case 7: cout << "July"; break;
case 8: cout << "August"; break;
case 9: cout << "September";break;
case 10: cout << "October"; break;
case 11: cout << "November"; break;
case 12: cout << "December"; break;
}
return 0;
}
My mind wandered and tried multiple different approaches..and I ended
up with that crap...can some1 help me make the program work to the reqs
placed above..thanks!