IN C++ PLEASE>>> Design and code a class that represents a single month of the y
ID: 3797166 • Letter: I
Question
IN C++ PLEASE>>>
Design and code a class that represents a single month of the year. It should have a single integer-typed data member to represent the month. Make sure to provide proper construction, access, and mutation for this member as well as input and output methods. In addition, methods for comparing two months chronologically for ordering would be useful as would a method to advance to the next month (note that January follows December and begins the cycle anew) or previous month. In fact, thinking about it, it might be good to be able to advance to a month an arbitrary number of whole months in the future or past: January '+' 5 = June; March '-' 5 = November. Place your Month class in a library. Write a test application (driver) for your class. Oh, and the programmers who commissioned this class wanted to make sure it could handle not only integer-valued representation of a Month but also either whole-word names or three-letter abbreviations for the Months. That means that they should be able to construct a Month object from either an integer value or a string -- which could be either the whole month name or a 3-letter version there-of. Similarly, they'd like to be able to retrieve the Month's information as either an integer value or a string (of either form), mutate the Month by any of these means, display by any of the three forms, and even allow their user to enter any of the three forms at the console. But, to keep things as simple as possible, they'd not like a whole lot of different names to remember. Please use the following names for all functions that perform such tasks: set_month, get_month, input, output, advance, before, after, same. (There may be only one of some methods, but others may need at least two methods to offer all requested functionality.)
Explanation / Answer
###### main.cpp########
---------------------------------------
// Example program
#include <iostream>
#include <string>
using namespace std;
string ch;
string month;
string enteredInputMonth;
string monthNumber;
string fullMonthName;
string monthInThreeLetter;
int getMonthNumber(string fullMonthName){
int result;
if(fullMonthName == "January"){
result = 1;
}else if(fullMonthName == "Feburary"){
result = 2;
}else if(fullMonthName == "March"){
result = 3;
}else if(fullMonthName == "April"){
result = 4;
}else if(fullMonthName == "may"){
result = 5;
}else if(fullMonthName == "June"){
result = 6;
}else if(fullMonthName == "July"){
result = 7;
}else if(fullMonthName == "Augest"){
result = 8;
}else if(fullMonthName == "September"){
result = 9;
}else if(fullMonthName == "Octomber"){
result = 10;
}else if(fullMonthName == "November"){
result = 11;
}else if(fullMonthName == "Decemeber"){
result = 12;
}
return result;
}
string getMonthName(int fullMonthName){
string result;
if(fullMonthName == 1){
result = "January";
}else if(fullMonthName == 2){
result = "Feburary";
}else if(fullMonthName == 3){
result = "March";
}else if(fullMonthName == 4){
result = "April";
}else if(fullMonthName == 5){
result = "May";
}else if(fullMonthName == 6){
result = "June";
}else if(fullMonthName == 7){
result = "July";
}else if(fullMonthName == 8){
result = "Augest";
}else if(fullMonthName == 9){
result = "September";
}else if(fullMonthName == 10){
result = "Octomber";
}else if(fullMonthName == 11){
result = "November";
}else if(fullMonthName == 12){
result = "Decemeber";
}
return result;
}
void set_month(string monthArg){
month = monthArg;
}
string get_month(){
return month;
}
void input(){
std::cout << "Enter your choice from the following options ? ";
std::cout << "1 : Enter Months in digit ( i.e 1->januray, 3-> March ) ";
std::cout << "2 : Enter Full Month's name ( i.e Januray, March, June etc. ) ";
std::cout << "3 : Enter Months in 3 letter ( i.e JAN, JUN,NOV etc. ) ";
getline (std::cin, ch);
if(ch == "1"){
std::cout << "Enter Month ? ";
getline (std::cin, monthNumber);
set_month(monthNumber);
}else if(ch == "2"){
std::cout << "Enter Month ? ";
getline (std::cin, fullMonthName);
set_month(fullMonthName);
}else if(ch == "3"){
std::cout << "Enter Month ? ";
getline (std::cin, monthInThreeLetter);
set_month(monthInThreeLetter);
}else{
std::cout << "Sorry you have entered wrong choice" << "! ";
}
}
void output()
{
if(ch == "1"){
std::cout << "Entered month is : " << monthNumber << endl ;
}else if(ch == "2"){
std::cout << "Enter Month is : " << fullMonthName << endl ;
}else if(ch == "3"){
std::cout << "Enter Month is : " << monthInThreeLetter << endl ;
}
}
void before(){
if(ch == "1"){
std::cout << "Enter number of months for which you need to identify the before month's name ? "<< endl;
getline (std::cin,enteredInputMonth);
int actualMonth = stoi(monthNumber);
int result = actualMonth - stoi(enteredInputMonth);
int output;
if(result <= 0 ){
output = 12 - (-(result));
}else{
output = actualMonth - result;
}
cout << " Calculated before month is : " << output << endl;
}else if(ch == "2"){
int result = 0;
int output = 0;
std::cout << "Enter number of months for which you need to identify the before month's name i.e January , Augest etc. ? "<< endl;
getline (std::cin,enteredInputMonth);
int actualresult = getMonthNumber(fullMonthName);
result = actualresult - stoi(enteredInputMonth);
if(result <= 0 ) {
output = 12 - -(result);
cout << getMonthName(output) << endl;
}else{
output = actualresult - result;
cout << getMonthName(output) << endl;
}
}else if(ch == "3"){
// std::cout << "Enter Month ? " << monthInThreeLetter;
}
}
void after(){
if(ch == "1"){
std::cout << "Enter number of months for which you need to identify the future month's value ? "<< endl;
getline (std::cin,enteredInputMonth);
int actualMonth = stoi(monthNumber);
int result = actualMonth + stoi(enteredInputMonth);
int output;
if(result > 12 ){
output = result - 12 ;
}else{
output = actualMonth + result;
}
cout << " Calculated future month is : " << output << endl;
}else if(ch == "2"){
//std::cout << "Enter Month ? " << fullMonthName;
}else if(ch == "3"){
//std::cout << "Enter Month ? " << monthInThreeLetter;
}
}
int main()
{
input();
output();
before();
after();
//advance,
//before,
//,
//same
return 0;
}
####Sample Output #####
-------------------------------------
Enter your choice from the following options ?
1 : Enter Months in digit ( i.e 1->januray, 3-> March )
2 : Enter Full Month's name ( i.e Januray, March, June etc. )
3 : Enter Months in 3 letter ( i.e JAN, JUN,NOV etc. )
1
Enter Month ?
6 [ working of Input method.]
Entered month is : 6 [ Actual Month value Entered on which calculation will be made here is 6 or June month ]
Enter number of months for which you need to identify the before month's name ?
3
Calculated before month is : 3 [ Workig of before method or '-' here june is the actual month and wants to reach 3 months before so result is 3, it means march ]
Enter number of months for which you need to identify the future month's value ?
10
Calculated future month is : 4 [ Workig of after method or '+' here june is the actual month and wants to reach 10 months after so result is 4, it means April. ]
##### Sample output 2 ###############
-------------------------------------------------------------
Enter your choice from the following options ?
1 : Enter Months in digit ( i.e 1->januray, 3-> March )
2 : Enter Full Month's name ( i.e Januray, March, June etc. )
3 : Enter Months in 3 letter ( i.e JAN, JUN,NOV etc. )
2
Enter Month ?
April
Enter Month is : April
Enter number of months for which you need to identify the before month's name i.e January , Augest etc. ?
2
Feburary