Question: C++ I have to create a calendar using classes, this is my code right now. It runs however the the function set is not running
C++
I have to create a calendar using classes, this is my code right now. It runs however the the function set is not running or being called I don't know why. So instead of running through this function it completely ignores it, and it doesn't print the information I need it to print. Any ideas of how I can fix this problem?
Here is my code:
#include
using namespace std;
/* * */
//Declare class TheDate class TheDate{ public: //Member function declaration void input(); void output(); void output1(); void output2(); void output3(); void output4(); void set(int newDay, int newMonth, int newYear); //Precondition: newMonth, newDay, and newYear form a possible date. void set(int newMonth); //Precondition: 1<= newMonth <= 12 //Postconditon: The date is set to the first day of the given month int getMonthNumber(); //Return 1 for January, 2 for February, etc. int getDay();// Return the day int getYear();// Return the year private: //Private members month day , year , symbol for "/" int month; int day; int year; char symbol; }; //Use string to call out the name of the month depending on the number inputed for month string monthName[12] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
int main() { // char variable to see if user wants to run program again. char runprogram; //while loop to allow the programmer to run program again if he/she wishes while (runprogram != 'n'){ TheDate today; cout << "The program displays a valid date in three different formats. " <<"Note: All junk data will be rejected! " <<"Enter a date (mm/dd/yyyy) or -1 to end: "; //call the input void function today.input(); cout<<"The Date: "; //call the output void function (US form) today.output(); cout<<" is valid "; //call the output1 void function (US Form) today.output1(); cout<< endl; //call the output2 void function (US Expanded Form) today.output2(); cout<< endl; //call the output3 void function (US Military Form) today.output3(); cout<< endl; //call the output4 void function (US International Form) today.output4();
cout< //Uses iostream and cstdlib: //void set function to calculate requirment for the inputed values void TheDate::set(int newDay, int newMonth, int newYear){ // if newmonth is between 1 and 12 establish variable from private month // Else the screen will prompt out that the month you displayed is invalid if((newMonth >=1) && (newMonth <=12)) month = newMonth; else{ cout << "Illegal month value! Program aborted. "; exit(1); } //switch statement to declare requirment for each month depending on the inputed switch (month){ case 1: //requirements for January if ((newDay >= 1) && (newDay <=31)){ day = newDay; } else cout < //Uses iostream and cstdlib: //void function were all the program will ask you to input the date // in a certain format of (mm/dd/yyyy) or -1 to end the program. void TheDate::input(){ cout<< "Enter a date (mm/dd/yyyy) or -1 to end: "; cin>> month; // if month was == -1 the program will exit if (month == -1) exit(1); cin>> symbol; cin>> day; cin>> symbol; cin >> year; //if month does not follow the requirment to be a valid date screen will output that there is a error // and ask you to try again if ((month < 1) || (month > 12) || (day < 1) || (day > 31) || (year<0)) { cout << "Error!!! The entered date is invalid! Re-Enter, Please! "; cout << "Enter a date (mm/dd/yyyy) or -1 to end: "; cin>> month; if (month == -1) exit(1); cin>> symbol; cin>> day; cin>> symbol; cin >> year; } } //output function for the US format Date void TheDate ::output(){ cout<
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
