【发布时间】:2014-02-03 07:06:20
【问题描述】:
我得到了以下代码来开发我自己的约会簿应用程序:
#include<iostream>
#include<string>
#include<vector>
#include "Appointment.h"
#include "OneTime.h"
#include "Daily.h"
#include "Monthly.h"
#include "Yearly.h"
using namespace std;
void checkAppointments(vector<Appointment*>& apptbook){
// STATEMENTS
}
void addAppointment(vector<Appointment*>& apptbook){
// STATEMENTS
}
int main(){
vector<Appointment*> apptbook;
char option;
do {
cout << "********** Appointment Book Application ************" << endl<< endl;
cout << "(a) See all appointments on a given day." << endl;
cout << "(b) Add an appointment." << endl << endl;
cout << "Enter an option or 'q' to quit: ";
cin >> option;
switch(option){
case 'a':
checkAppointments(apptbook);
break;
case 'b':
addAppointment(apptbook);
break;
case 'q':
break;
default:
cout << "You entered an invalid option. Try again!";
}
cout << endl;
}
while(option != 'q');
// Cleaning up
for(int i = 0; i < apptbook.size(); i++){
delete apptbook[i];
}
apptbook.clear();
system("PAUSE");
return 0;
}
我被要求使用下面指定的Appointment 构造函数的一些参数来构造date 成员它包含在Appointment 文件中的Appointment 类:
Appointment(string description, int month, int day, int yr, int hr, int min)
这是我到目前为止在Appointment.h vis-a-vis 中所做的,以请求的方式定义构造函数:
#ifndef APPOINTMENT_H
#define APPOINTMENT_H
#include<string>
#include<sstream>
#include "Date.h"
using namespace std;
class Appointment{
public:
Appointment(string description, int month, int day, int yr, int hr, int min);
Date date;
private:
int hour;
int minute;
string convertInt( int number ) const;
};
Appointment(string description, int month, int day, int yr, int hr, int min) : public date(month, day, yr)
{
this->description = description;
}
string Appointment::convertInt( int number ) const
{
stringstream ss;
ss << number;
return ss.str();
}
#endif
我想我的问题是这样的:“如何使用Appointment 的一些参数来构造日期成员及其初始化列表?”这个概念对我来说是新的,我遇到了一些麻烦。这是Date.h 和Date.cpp:
日期.h
#ifndef DATE_H
#define DATE_H
#include<string>
using namespace std;
class Date{
public:
Date(int month, int day, int year);
int getMonth() const;
int getDay() const;
int getYear() const;
private:
int month;
int day;
int year;
};
#endif
日期.cpp
#include "Date.h"
#include<string>
using namespace std;
Date::Date(int month, int day, int year) {
this->month = month;
this->day = day;
this->year = year;
}
int Date::getMonth() const{
return month;
}
int Date::getDay() const{
return day;
}
int Date::getYear() const{
return year;
}
【问题讨论】:
标签: c++ class c++11 virtual header-files