一开学就是大做业,我方了。学习数据结构呢其实跟以前学习C的时候感受没多大差异,最主要的就是从C换成了C++,虽然并无学过C++,可是还有百度(可还行)。不会就查,查多了,也就懂得多了,毕竟C++跟C差很少。最主要得是,C++真的比C要少写好多行代码。目前学的知识呢,还比较简单,不过接下来要更加努力,别再像上学期那样到课设的时候,还有知识点不会去查书。
ADT Date{ 数据对象:D={year,month,day|year,month,day属于ElemType类型} 数据关系:R={<year,month>,<month,day>} 数据操做: Status InitDate(Date &date, ElemType year, ElemType month,ElemType day); //初始化日期 //操做结果:构造三元组date,元素year、month、day分别为年、月、日 string ExpDate(Date date); //初始条件:三元组date存在 //操做结果:以字符串的形式输出日期 Status IsLeapyear(ElemType year); //初始条件:三元组date存在 //操做结果:如果闰年则返回TRUE,不然返回FALSE string Week(Date date); //初始条件:三元组date存在 //操做结果:返回这个日期是星期几 string MonthInEnglish(Date date); //初始条件:三元组date存在 //操做结果:返回月份英文名 void AddDate(Date &date, ElemType days); //初始条件:三元组date存在 //操做结果:返回当前日期增长days天的日期 char CompareDate(Date date,Date OtherDate); //初始条件:三元组date存在 //操做结果:比较当前日期与OtherDate的逻辑关系 }ADT Date
分配动态内存,构造三元组,并判断日期是否合法
ios
以字符串的形式输出日期
数据结构
按照公式判断该日期是年份否是闰年,是返回TRUE,反之返回FALSE
函数
根据公式判断该日期所在的星期,并返回该星期
学习
输入所加的天数,并返回增长改天数以后的日期
设计
判断输入日期与原日期之间的逻辑关系
3d
int main() { Date date;//定义一个date的三元组 int year, month, day; int days; string newDate; //增长days天后的日期 Date otherDate; string strDate; string strWeek; string str; char op; ifstream infile; infile.open("input.txt", ios::in); ofstream outfile; outfile.open("output.txt", ios::out); while (!infile.eof()) { infile >> year >> month >> day; if (!InitDate(date, year, month, day)) { strDate = ExpDate(date); cout << strDate << "不是合法日期" << endl << endl; outfile << strDate << "不是合法日期" << endl << endl; continue; } strDate = ExpDate(date); cout << strDate << endl; outfile << strDate << endl; if (IsLeapyear(year)) { cout << year << "是闰年" << endl; outfile << year << "是闰年" << endl; } else { cout << year << "不是闰年" << endl; outfile << year << "不是闰年" << endl; } strWeek = Week(date); cout << strDate << strWeek << endl; outfile << strDate << strWeek << endl; str = MonthInEnglish(date); cout << strDate << "月份是" << str << endl; outfile << strDate << "月份是" << str << endl; cout << "请输入增长天数:"; cin >> days; AddDate(date, days); newDate = ExpDate(date); cout << strDate << '+' << days << "是" << newDate << endl; outfile << strDate << '+' << days << "是" << newDate << endl; cout << "请输入与当前日期相比较的日期:"; /*cin >> year >> month >> day; while (!InitDate(otherDate, year, month, day)); { cout << "请输入正确的日期:" << endl; cin >> year >> month >> day; }*/ while (1) { cin >> year >> month >> day; if (!InitDate(otherDate, year, month, day)) { cout << "请输入正确的日期:" << endl; continue; } else break; } newDate = ExpDate(otherDate); op = CompareDate(date, otherDate); cout << strDate << op << newDate << endl<<endl; outfile << strDate << op << newDate << endl<<endl; } infile.close(); outfile.close(); system("pause"); }