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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include "stdafx.h"
#include <iostream>
int main() {
using namespace std;
void testMenu(); //post-condition is displayed for user to choose
bool isLeapYear(int year);
int getCenturyValue(int year);
int getYearValue(int year);
int getMonthValue(int year, int month);
int dayOfWeek(int year, int month, int day);
int choice;
int day, month, year;
do {
testMenu();
cout << "Please choose from the menu: ";
cin >> choice;
switch (choice) {
case 1: //check if a given year is a leap year
cout << "Please enter a year: ";
cin >> year;
if (isLeapYear(year))
cout << "Year " << year << " is a leap year." << endl;
else
cout << "Year " << year << " is NOT a leap year." << endl;
break;
case 2: // calculate the century value of a given year
cout << "Please enter a year: ";
cin >> year;
cout << "The century value is: " << getCenturyValue(year) << endl;
break;
case 3: //calculate the year value of a given year
cout << "Please enter a year: ";
cin >> year;
cout << "The year value is: " << getYearValue(year) << endl;
break;
case 4: // calculate the month value of a given month in a given year
cout << "Please enter a year and month: ";
cin >> year >> month;
cout << "The month value is: " << getMonthValue(year, month) << endl;
break;
case 5: // calculate the day of the week of a given date
cout << "Please enter a year, a month, and a day: ";
cin >> year >> month >> day;
cout << "The day of the week is: " << dayOfWeek(year, month, day) << endl;
break;
case 6: // print out the name of a given day of the week
cout << "Please enter a day of the week (0 for Sunday, 1 for Monday, 2 for Tuesday, etc): ";
cin >> day;
cout << "The name of the day of the week is: " << dayOfWeek(day) << endl;
break;
case 7: // ask user if they tested all functions
cout << "Did you test all of the functions? If not, then please rerun the program and do so.\n";
break;
default:
cout << "Wrong option. Please choose from the menu.\n";
break;
}
system("pause");
} while (choice != 7);
}
void testMenu()
{
cout << " \t\t**********Test Menu**********" << endl;
cout << "* 1) isLeapYear *" << endl;
cout << "* 2) getCenturyValue *" << endl;
cout << "* 3) getYearValue *" << endl;
cout << "* 4) getMonthValue *" << endl;
cout << "* 5) dayOfWeek (year, month, day) *" << endl;
cout << "* 6) dayOfWeek (day) *" << endl;
cout << "* 7) Quit *" << endl;
}
bool isLeapYear(int year)
{
if ((year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0) ))
return true;
else
return false;
}
int getCenturyValue(int year)
{
year = year / 100;
year = year % 4;
year = 3 - year;
return year * 2;
}
int getYearValue(int year)
{
int tempyear;
year = year % 100;
tempyear = year / 4;
return year + tempyear;
}
int getMonthValue(int year, int month) // not sure on this section or below
{
}
int dayOfWeek(int year, month, day) //here
{
}
int std::string dayOfWeek(int day); // or here
{
}
|