|
Write a program that contains a class that implements the days of the week. The program should be able to perform the following on an object of a class. 1. Set the day 2. Print the day to the computer monitor(not the printer) 3. Return the day
Create a new class called DayOfTheWeek. The class should have a data member that can store the day of the week such as Mon for Monday, Tues for Tuesday etc...
Create the necessary member functions that will perform the required operations outlined in the lab summary above.
Call these functions setDay, printDay and getDay.
Write a main program that will instantiate two objects of the class DayOfTheWeek. Use these objects to test the various operations on this class.
DayOfTheWeekHEA~1
#include <string> using std::string; class DayOfTheWeek { private: string day string hour public: void setday(string, string); void printday(); string getday(); };
DayOfTheWeekIMP #include <iostream> #include <string> #include "DayOfTheWeek.h"
using manespace std;
void DayOfTheWeek::setdayinfo(string day, string hour) { Monday = mon; Tuesday = tues; Wednesday = weds; Thursday = thurs; Friday = fri; Saturday = sat; Sunday = sun; } void DayOfTheWeek::printDay() { cout << "Day: " << day << endl; cout << "Hour: " << hour << endl; } string DayOfTheWeek::getday() { return day; }
This post has been edited by ITChief: 15 Mar, 2008 - 05:53 PM
|