2016-11-06 9 views
0

私はプログラミングに新しいです、そして、私は現在問題に固執しています。私は現在、Tasklistクラスを通過した後にベクトルに保存される入力値を保存する方法に固執しています。以前のクラスの値をC++のベクトルに格納する方法は?

クラスタスク

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; 
} 

クラス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(); 
} 

クラスタスクリスト

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

をやあ、この質問は宿題のように見えます。私はもう少し研究をしたり、C++のチュートリアルを十分に学んだことはないと思います。 http://www.cprogramming.com/tutorial/stl/vector.html – iankits

+0

一般的なコメントとして、あなたの入力と出力を実際のクラスから分離します。 – QuinnFTW

答えて

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() { 
... 
} 
関連する問題