Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <string>
- using namespace std;
- class Month {
- public :
- Month();
- void setName(istream& name);
- void setDays(istream& days);
- void setHolidays(string* holidays);
- string getName();
- unsigned int getDays();
- string* getHolidays();
- private :
- string name;
- unsigned int days;
- string* holidays;
- };
- void addDetail(Month& m) {
- cout << "Input the name: ";
- m.setName(cin);
- cout << "Input the total day: ";
- m.setDays(cin);
- cout << "How many holiday: ";
- int num;
- cin >> num;
- string* holidays = new string[num];
- for (int f = 0 ; f < num ; f++) {
- cout << "Name of " << f+1 << " holiday: ";
- string h;
- cin >> h;
- holidays[f] = h;
- }
- m.setHolidays(holidays);
- cout << "------------------------" << endl;
- }
- void printDetail(Month m) {
- cout << "Name: " << m.getName() << "\tDays: " << m.getDays() << "\tHolidays: " << m.getHolidays()[0];
- for (int q = 1 ; q < sizeof(m.getHolidays()) / sizeof(m.getHolidays()[1]) ; q++) {
- cout << ", " << m.getHolidays()[q];
- }
- cout << endl;
- }
- int main() {
- // Initialize Months
- vector<Month> month;
- // Ask for input
- char c;
- while (c != 'q') {
- Month m;
- addDetail(m);
- month.push_back(m);
- cout << "Add(a) or Exit(q): ";
- cin >> c;
- }
- //Ask for output
- cout << "Do you want to see output? (Y/n): ";
- cin >> c;
- if (c == 'Y') {
- //Output the detail of each month
- for_each(month.begin(), month.end(), printDetail);
- }
- return 0;
- }
- Month::Month() {
- name = "";
- days = 0;
- holidays = NULL;
- }
- void Month::setName(istream& name) {
- name >> this->name;
- }
- void Month::setDays(istream& days) {
- days >> this->days;
- }
- void Month::setHolidays(string* holidays) {
- this->holidays = holidays;
- }
- string Month::getName() {
- return this->name;
- }
- unsigned int Month::getDays() {
- return this->days;
- }
- string* Month::getHolidays() {
- return this->holidays;
- }
- // Author : Sirawat Ngarmphandisorn
- // ID : 57130500220
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement