Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the program below add the following a. This program must input only years

ID: 3537694 • Letter: U

Question

Using the program below add the following

a. This program must input only years between 1900 and 2050 (including these two years).

You must use a loop so that the user will be prompted again and again if it does not fit this

criteria.

b. The program must have two value returning functions and one void function. The function

prototypes are given here.


void printMessage();


The message printed by this function is as shown here.

int inputYear();


This must prompt the input for the year from the user and store it in an int variable. This

value returning function must return the integer to main function when called.

string chineseZodiac(int year);

This value returning function takes year, an integer as parameter and returns a string.

Save the modified file as Finals1.cpp. Your program must have a comment header and internal

comments. Please note that you must follow the specification and the function must do only

the job it is assigned.


The final output should look like below.


Explanation / Answer

Please rate


// Zodiac.h


#include "stdafx.h" // Use this in case you are working with visual studio


#ifndef _ZODIAC_H

#define _ZODIAC_H

#include <string>

using namespace std;

class Zodiac {

public:

void printMessage();

int inputYear();

string chineseZodiac(int year);

};

#endif


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Zodiac.cpp


#include "stdafx.h" // Use this in case you are working with visual studio


#include "Zodiac.h"

#include <string>

#include <iostream>


using namespace std;


void Zodiac::printMessage()

{

cout<<"This program will get the year from user and first check to see if it is between 1900 and 2050. If it is then it will print the chinese zodiac for the entered. If not, it will prompt the user again for the year. "<<endl;

}


int Zodiac::inputYear()

{

int n;

cout<<"Enter the year for which you want the chinee zodiac: ";

cin>>n;

return n;

}


string Zodiac::chineseZodiac(int year)

{

string zyears[] = {"rat","ox","tiger","rabbit","dragon","snake","horse","goat","monkey","rooster","dog","pig"};

return zyears[(year-1900)%12];

}


int main()

{

Zodiac z;

int n;

z.printMessage();

while(1)

{

n = z.inputYear();

if(n>=1900&&n<=2050)

break;

}

cout<<"The Chinese Zodiac for the year "<<n<<" is "<<z.chineseZodiac(n);

//system("pause");

}