我是编程新手,目前我遇到了问题。我目前仍然坚持如何在传递Tasklist类后保存要保存在向量中的输入值。
课程任务
class{void Task::description(){
string descrip;
cout<< "How would you describe this task" <<endl;
getline(cin, descrip);
cin.ignore();
}
void Task::deadline(){
int due;
cout<< "In how many days is task due?"<<endl;
cin >> due;
}
class EventTask
void EventTask::locatioin(){
string location;
cout<< "Where is the event taking place?"<<endl;
getline(cin,location);
cin.ignore();
}
void EventTask::time(){
string time;
cout<< "What time is the event?"<<endl;
getline(cin,time);
cin.ignore();
}
类TaskList
void Tasklist::Add_Task()
{
string add_cmd;
cout<< "What type of Task is this? [G: Generic, E: Event]"<<endl;
cin>> add_cmd;
if (add_cmd == "g"){
Task t;
t.deadline();
t.description();
}
if (add_cmd == "e"){
EventTask et;
et.deadline();
et.description();
et.locatioin();
et.time();
}
main.cpp
int main(){
Tasklist tl;
tl.Add_Task();}
我的主要问题是如何将输入值保存到矢量中,然后输出矢量中包含的内容。
答案 0 :(得分:0)
您可以使用C ++类继承功能并将字符串定义为Task类的私有变量,如下所示:
class Task{
private:
string location;
string add_cmd;
string description;
public:
//.... functions to set and get variable's value plus other functions
like description(), location() and Add_Task() ....
}
class EventTask: public Task {
...
}
class TaskList: public Task {
....
}
int main() {
...
}