|
Go to Page... |
Post Reply |
Tweet | Thread Tools |
#1
|
|||
|
|||
![]()
maaf ganggu nih gan ane ada program tentang hari, nentuin hari apa kemarin dan hari apa besok, ane dah buat programnya tapi ane stack di saat ane mau buat user bisa inputin data di program ini. bagaimana yah gan, minta saran aja, bukan jawaban langsung soalnya ane harus belajar sendiri, kasih aje clue-cluenya agar bisa merubah dikit biar user bisa input name harinya. sumpah gan ane betul-betul stack ngak bisa mikir lagi, udah gunain semua yg dikepala ane, malah errornya tambah banyak. ngak lulus2 ane klo g bisa jawab. untuk bantuin ni soalannya gan. Spoiler for buka: A) Design and implement a class dayType that implements the day of the week in a program. The class dayType should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type dayType: a. Set the day b. Print the day c. Return the day d. Return the next day e. Return the previous day f. Calculate and return the day by adding certain days to the current day. For example if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday. g. Add the appropriate constructors. nih program yang ane dah buat. Spoiler for buka aja: #include #include #include using namespace std; class DayType { private: static const int DAYS = 7; static string weekDays[DAYS]; string weekDay; public: DayType(string const & day = weekDays[0]); // Accessor and Mutator string getDay() const; void setDay(string const & ); // Services void print() const; string nextDay() const; string prevDay() const; string addDay(int) const; private: size_t getDayNumber(void) const; // translate day name to day number // private use only }; //end header file string DayType::weekDays[DayType:: DAYS] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; DayType:: DayType(string const & day) { setDay(day); // assure that day is valid } string DayType:: getDay() const { return weekDay; } void DayType:: setDay(string const & day) { assert ( day == weekDays[0] || day == weekDays[1] || day == weekDays[2] || day == weekDays[3] || day == weekDays[4] || day == weekDays[5] || day == weekDays[6]); // assure that day is valid weekDay = day; } void DayType:: print() const { cout Terkait:
|
Sponsored Links | |
Space available |
Post Reply |
|