Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with writting the following programs -Create the program lab_main.cp

ID: 3862922 • Letter: I

Question

I need help with writting the following programs -Create the program lab_main.cpp which uses the class Family to Implement the following a. The program will allow the user to 1. Add families a. With one or two parents b. With zero or more children 2. Delete Families search by last name (should use the same search function from item 3 below. 3. Display Families searching by last name 4. Display a list of all families 4. On exit print the following text to the screen; “So long from the family!” where is the first family in the list (if the list is empty just print “Bye Bye”). home / study / engineering / computer science / questions and answers / family.h header file #pragma once #ifndef family_h ... Question: Family.h header file #pragma once #ifndef family_h... Bookmark family.h header file #pragma once #ifndef family_h #define family_h #endif struct person { char FN[30]; char LN[30]; int age; }; class Family { private: char name[30]; person parent[2]; person children[10]; public: void setName(char* n[30]); char * getName(); void setParent(char FN[], char LN[], int, int); void setChildren(char FN[], char LN[], int, int); };

*** IF YOU DO NOT KNOW PLEASE DO NOT SIMPLY ANSWER ***

Explanation / Answer

#include <iostream>
#include <list>
#include <vector>
#include <string.h>
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);
};

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);
int main()
{
    std::list<Family*> mylist;
    std::list<Family*>::iterator it;
    cout << "" << endl;
    char c = '*';
    while(c != 'Q'){
        c = printMenu();
        if(c=='A'||c=='a'){
           addFamily(mylist);
        }
        if(c=='D'||c=='d'){
            char* name;
            cout << "Enter Name to Delete :";
            cin >>name;
            deleteFamily(mylist,name);
        }
        if(c=='P'||c=='p'){
            char* name;
            cout << "Enter Name :";
            cin >>name;
            prinFamily(mylist,name);
        }
        if(c=='L'||c=='l'){
           printAll(mylist);
        }
        if(c=='q'){
            c ='Q';
        }
    }
    return 0;
}

void printAll(std::list<Family*> list){
    std::list<Family*>::iterator it;
    for (it = list.begin(); it!=list.end(); it++) {
        cout << "Name: "<<(*it)->getName()<<endl;
    }
}
void prinFamily(std::list<Family*> list,char * n){
    std::list<Family*>::iterator it;
    for (it = list.begin(); it!=list.end(); it++) {
        char* name = (*it)->getName();
        if(strcmp(name,n)==0){
            cout << "Name: "<<(*it)->getName()<<endl;
            break;
        }
    }
    cout << "Not found"<<endl;
}
void deleteFamily(std::list<Family*> list,char * n){
    std::list<Family*>::iterator it;
    for (it = list.begin(); it!=list.end(); it++) {
        char* name = (*it)->getName();
        if(strcmp(name,n)==0){
            delete *it;
            break;
        }
    }
    cout << "Not found"<<endl;
}
void addFamily(std::list<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);
    }
    list.push_front(f);
}

char printMenu(){
    char choice;
    cout << " [A] Add Family "<< endl;
    cout << " [D] Delete Family "<< endl;
    cout << " [P] Display By Name "<< endl;
    cout << " [L] Display all "<< endl;
    cout << " [Q] Quit"<< endl;
    cout << "Choose an option :";
    cin >> choice;
    return choice;
}