#include<iostream>
#include <iomanip>
using namespace std;
class Time
{
private:
int hh,mm;
public:
void getTime(void);
void displayTime(void);
};
void Time::getTime(void)
{
cout << "Enter time:" << endl;
cout << "Hours? "; cin >> hh;
cout << "Minutes? "; cin >> mm;
}
void Time::displayTime(void)
{
cout << "The time is = " << setw(2) << setfill('0') << hh << ":"
<< setw(2) << setfill('0') << mm ;
}
int main()
{
int in;
char event_title[40];
cout<<"Welcome Message"<<endl;
cout<<"***Main Menu***"<<endl;
cout<<"[1] Add one event"<<endl;
cout<<"[2] Delete one event"<<endl;
cout<<"[3] Add events in batch"<<endl;
cout<<"[4] Show events"<<endl;
cout<<"[5] Credits"<<endl;
cout<<"[6] Exit"<<endl;
cout<<"******************"<<endl;
cout<<"Option (1-6):"<<endl;
cout<<"Select options from Main Menu"<<endl;
cin>>in;
switch(in)
{
case 1: cout<<"Enter the following information:"<<endl;
int dd,mm,yyyy,et;
cout<<"Event Title"<<endl;
cin>>event_title;
cout<<"Event Date"<<endl;
cin>>dd>>mm>>yyyy;
if(yyyy>=1900 && yyyy<=9999) //check year
{
//check month
if(mm>=1 && mm<=12)
{
//check days
if((dd>=1 && dd<=31) && (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12))
cout<<dd<<"-"<<mm<<"-"<<yyyy<<endl;
else if((dd>=1 && dd<=30) && (mm==4 || mm==6 || mm==9 || mm==11))
cout<<dd<<"-"<<mm<<"-"<<yyyy<<endl;
else if((dd>=1 && dd<=28) && (mm==2))
cout<<dd<<"-"<<mm<<"-"<<yyyy<<endl;
else if(dd==29 && mm==2 && (yyyy%400==0 ||(yyyy%4==0 && yyyy%100!=0)))
cout<<dd<<"-"<<mm<<"-"<<yyyy<<endl;
else
cout<<"date is invalid"<<endl;
}
else
{
printf("Month is not valid.\n");
}
}
else
{
printf("Year is not valid.\n");
}
cout<<"Event Start time"<<endl;
Time T; //creating objects
T.getTime();
T.displayTime();
cout<<endl;
cout<<"Event End time"<<endl;
T.getTime();
T.displayTime();
cout<<endl;
cout<<"Event Type"<<endl;//Value should be between 1 and 4;
cin>>et; //(1)Home (2)Work (3) Study (4) Play
main();
break;
case 2 : cout<<"Enter the date of event that you want to be deleted"<<endl;
cin>>dd>>mm>>yyyy;
if(yyyy>=1900 && yyyy<=9999) //check year
{
//check month
if(mm>=1 && mm<=12)
{
//check days
if((dd>=1 && dd<=31) && (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12))
cout<<"Event is deleted"<<endl;
else if((dd>=1 && dd<=30) && (mm==4 || mm==6 || mm==9 || mm==11))
cout<<"Event is deleted"<<endl;
else if((dd>=1 && dd<=28) && (mm==2))
cout<<"Event is deleted"<<endl;
else if(dd==29 && mm==2 && (yyyy%400==0 ||(yyyy%4==0 && yyyy%100!=0)))
cout<<"Event is deleted"<<endl;
else
cout<<"date is invalid"<<endl;
}
else
{
printf("Month is not valid.\n");
}
}
else
{
printf("Year is not valid.\n");
}
main();
case 3 : cout<<"Add events in the batch"<<endl;
// Format of one event is DD-MM-YYYY/hh-mm/hh-mm/Event Title/X
cout<<"Event Date"<<endl;
cin>>dd>>mm>>yyyy;
if(yyyy>=1900 && yyyy<=9999) //check year
{
//check month
if(mm>=1 && mm<=12)
{
//check days
if((dd>=1 && dd<=31) && (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12))
cout<<dd<<"-"<<mm<<"-"<<yyyy<<endl;
else if((dd>=1 && dd<=30) && (mm==4 || mm==6 || mm==9 || mm==11))
cout<<dd<<"-"<<mm<<"-"<<yyyy<<endl;
else if((dd>=1 && dd<=28) && (mm==2))
cout<<dd<<"-"<<mm<<"-"<<yyyy<<endl;
else if(dd==29 && mm==2 && (yyyy%400==0 ||(yyyy%4==0 && yyyy%100!=0)))
cout<<dd<<"-"<<mm<<"-"<<yyyy<<endl;
else
cout<<"date is invalid"<<endl;
}
else
{
printf("Month is not valid.\n");
}
}
else
{
printf("Year is not valid.\n");
}
cout<<"Event Start time"<<endl;
T.getTime();
//T.displayTime();
cout<<endl;
cout<<"Event End time"<<endl;
T.getTime();
//T.displayTime();
cout<<endl;
cout<<"Event Type"<<endl;//Value should be between 1 and 4;
cin>>et; //(1)Home (2)Work (3) Study (4) Play
cout<<dd<<"-"<<mm<<"-"<<yyyy<<"/"<<et<<endl;//You can also display time here using displayTime() method;
main();
default : cout<<"Invalid input"<<endl;
break;
case 4:{int option;
do {
cout << "***** Show Event Menu *****\n";
cout << "[1] Show all events\n";
cout << "[2] Show events (list view)\n";
cout << "[3] Show events (calendar view)\n";
cout << "[4] Return to Main Menu\n";
cout << "***************************\n";
cout << "Option (1 - 4): ";
cin >> option;
switch (option) {
case 1:break;
case 2: break;
case 3: break;
case 4: break;
default: cout << "No such option. Please enter again.\n";
;
break;
}
} while (option != 4);
main();
break;
};
return 0;
}
是要做能輸入 一個活動的資料(包括時間(HH:MM)、日期(DD-MM-YYYY)、主題、型別(1,2,3,4)括號內的是指定需要輸入的格式)
現在不知道如何將輸入的資料存盤在一個地方,然后讓它能夠在case4那里被顯示出來
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/71267.html
標籤:C++ 語言
上一篇:C++ 單例模式
下一篇:求大佬
