2017-03-18 15 views
-3

すべてのファミリ関数を削除して表示するには、疑似コードの助けが必要です。 これは、(1)家族を追加する(1または2の親と0以上の子供を持つ)2)姓でファミリーを削除する(3)姓で検索するファミリーを表示する、および(4)すべてのファミリーのリストを表示すること。ご意見やご提案ありがとうございます!ここ は、私が持っているものです。配列とベクトルの操作

HEADER:

using namespace std; 

struct Person{ 
    char* FN; char* LN; int age; 
}; 

class Family { 
    private: 
    char* name; 
    Person parent[2]; 
    Person children[10]; 
    public: 
    void setName(char* n); 
    char * getName(); 
    void setParent(char FN[], char LN[], int a, int i); 
    void setChildren(char FN[], char LN[], int a, int i); 

};

ファミリークラス:名前空間stdを使用して

void Family::setName(char n[]){ 
    name = n; 
} 

char* Family::getName(){ 
    return name; 
} 
void Family::setParent(char FN[], char LN[], int a, int i){ 
    parent[i].FN = FN; 
    parent[i].LN = LN; 
    parent[i].age = a; 
} 
void Family::setChildren(char FN[], char LN[], int a, int i){ 
    children[i].FN = FN; 
    children[i].LN = LN; 
    children[i].age = a; 
} 

char printMenu(); 
void addFamily(std::list<Family*> list); 
void printAll(std::list<Family*> list); 
void prinFamily(std::list<Family*> list,char * n); 
void deleteFamily(std::list<Family*> list,char * n); 

MAIN

void printMenu(); 
int getInput(); 
int main() 
{ 
    vector<Family*> mylist; 
    bool fin = false; 
    int selection; 

    do 
    { 
     printMenu(); 
     selection = getInput(); 

     switch (selection) 
     { 
     case 1: 
      addFamily(mylist); 
      break; 


     case 2: 
      char* name; 
      cout << "Enter the Name to Delete: "; 
      cin >> name; 
      deleteFamily(myList, name); 
      break; 

     case 3: 
      char* name; 
      cout << "Enter Family Last name: "; 
      cin >> name; 
      printFamily(mylist, name); 
      break; 

     case 4: 
      printAll(mylist); 
      break; 

     case 5: 
      if (!myList.empty()) 
      { 
       cout << myList[0].getName() << " says bye!\n"; 
      } 
      fin = true; 
      break; 
     } 

     return 0; 
    } 

void printAll(vector<Family*> list) { 
    for (size_t i = 0; i < myList.size(); i++) 
    { 
     cout << "\nFamily #: " << i; 
     cout << "\nName: " << myList[i].getName(); 
     cout << "\nAge: " << myList[i].getAge() << endl << endl; 
    } 

} 
void printFamily(vector <Family*> list, char * n) { 


      cout << "Name: " << (*it)->getName() << endl; 


    //if wrong name 
    cout << "Not found" << endl; 

void deleteFamily(vector <Family*> list, char * n) { 


    myList.erase(myList.begin() + name); 


    cout << "Not found" << endl; 
} 
void addFamily(vector <Family*> list) { 

    Person* p = new Person; 
    Family* f = new Family; 
    char* name; 
    int numOfP; 
    cout << "Enter Name :"; 
    cin >> name; 
    f->setName(name); 
    cout << "Enter Number of Parent :"; 
    cin >> numOfP; 
    for (int i = 0;i<numOfP;i++) { 
     char* fname; 
     char* lname; 
     int age; 
     cout << "Enter Parent First Name :"; 
     cin >> fname; 
     cout << "Enter Parent Last Name :"; 
     cin >> lname; 
     cout << "Enter Parent Age :"; 
     cin >> age; 
     f->setParent(fname, lname, age, i); 
    } 
    cout << "Enter Number of Child :"; 
    cin >> numOfP; 
    for (int i = 0;i<numOfP;i++) { 
     char* fname; 
     char* lname; 
     int age; 
     cout << "Enter Child First Name :"; 
     cin >> fname; 
     cout << "Enter Child Last Name :"; 
     cin >> lname; 
     cout << "Enter Child Age :"; 
     cin >> age; 
     f->setChildren(fname, lname, age, i); 
    } 
    myList.push_back(f); //not sure if this is right 
} 

void printMenu() { 

    cout << "\n 1.Add Family " << endl; 
    cout << " 2. Delete Family By Last Name " << endl; 
    cout << " 3. Display Families " << endl; 
    cout << " 4. Display All Famillies " << endl; 
    cout << " 5. Quit" << endl; 

} 

int getInput() 
{ 
    int choice; 
    cout << "\nEnter a number to select an option. \n"; 
    cin >> choice; 
    return choice; 
} 
+0

あなたは[std :: vector](http://en.cppreference.com/w/cpp/container/vector)を検討しましたか? –

答えて

0

std::listは、二重リンクリストを実装し、データを格納するために本当に重くて遅い方法です。 代わりにstd::vectorを使用することを検討してください。これは連続的なダイナミックアレイで、より良い性能を提供します。

+0

私はベクトルで編集しました – Miraclefruit