Assuming that a year has 365 days, write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string consisting of the month followed by day of the month. For example,
Day 2 would be January 2
Day 32 would be February 1
Day 365 would be December 31
The constructor for the class should take as parameter an integer representing the day of the year, and the class should have a member function print() that prints the day in the month-day format. The class should have an integer member variable to represent the day, and should have static member variables of type string to assist in the translation from the integer format to the month-day format.
Test your class by inputting various integers representing days and printing out their representation in the month-day format.
This is the only error message I received: \dayofyear.cpp(52): error C2660: 'DayOfYear::print' : function does not take 1 arguments
#include<iostream>
#include<iomanip>
using namespace std;
// Class declaration
class DayOfYear
{
private:
int day;
public:
static const int MonthDays[];
static const string MonthName[];
void print();
};
int main()
{
// Define array for consecutive days
const int MonthDays[] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
// Define array for strings with name of month
const string MonthName[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int day;
// Get user input
cout << "\nEnter a number you would like to convert into a month and day";
cin >> day;
// Validation - do not allow a negative number or a number > 365
if(day <= 0 || day > 365)
{
cout << "You must enter a valid number (1 thru 365)" << endl;
}
// Send entered day number to the print() function
DayOfYear::print(day);
system("Pause");
return 0;
}

New Topic/Question
Reply




MultiQuote



|