Welcome to OMG boards community!
Community of friends where we talk about daily life, offtopic stuff, and what keeps us busy.

You are currently viewing our community forums as a guest user. Sign up or
Having an account grants you additional privileges, such as creating and participating in discussions.

(C++ Console) Person Management

Discussion in 'Tech Talk & Web Things' started by Toby_offtopica, Dec 4, 2014.

  1. Toby_offtopica

    Toby_offtopica OMG Member

    Messages:
    650
    Likes Received:
    0
    Trophy Points:
    75
    I made a small program where you can add people and give them characteristics like a first and last name, age, etc. Then you can view them. I'm working on being able to remove people, but I don't think it's possible when the elements are a part of a struct.


    So don't use the remove tool.


    Souce:




    Code:
    
    
    #include 
    
    
    #include 
    
    
    #include 
    
    
    #include 
    
    
    
    
    using namespace std;
    
    
    
    
    struct person
    
    
    {
    
    
       string first_name;
    
    
       string last_name;
    
    
       int age;
    
    
       int height;
    
    
       int weight;
    
    
       int id;
    
    
    };
    
    
    
    
    int choice;
    
    
    string text;
    
    
    
    
    int main()
    
    
    {
    
    
    
    
    vector Person;
    
    
    int totalpeople = -1;
    
    
    int idid = 0;
    
    
    
    
    mmenu:
    
    
    system("CLS");
    
    
    cout << "Peeps management:\n\n1) Add Someone\n2) View peeps\n4) Remove someone\n> ";
    
    
    cin >> choice;
    
    
    if(choice == 1)
    
    
    {
    
    
    
    
    system("CLS");
    
    
    totalpeople = totalpeople+1;
    
    
    idid = idid + 1;
    
    
    
    
    
    
    Person.push_back(person());
    
    
    
    
    
    
    cout << "First Name: ";
    
    
    cin  >> text;
    
    
    Person[totalpeople].first_name = text;
    
    
    Person[totalpeople].id = idid;
    
    
    
    
    cout << "\nLast Name: ";
    
    
    cin >> text;
    
    
    Person[totalpeople].last_name = text;
    
    
    
    
    cout << "\nAge: ";
    
    
    cin >> choice;
    
    
    Person[totalpeople].age = choice;
    
    
    
    
    cout << "\nHeight: ";
    
    
    cin >> choice;
    
    
    Person[totalpeople].height = choice;
    
    
    
    
    cout << "\nWeight: ";
    
    
    cin >> choice;
    
    
    Person[totalpeople].weight = choice;
    
    
    
    
    system("CLS");
    
    
    cout << "Person added!";
    
    
    Sleep(1700);
    
    
    goto mmenu;
    
    
    
    
    }
    
    
    
    
    if(choice == 2)
    
    
    {
    
    
       system("CLS");
    
    
       for(vector::size_type i = 0; i < totalpeople + 1; i++)
    
    
       {
    
    
           cout << "First: " << Person[i].first_name;
    
    
           cout << "\nLast: " << Person[i].last_name;
    
    
           cout << "\nAge: " << Person[i].age;
    
    
           cout << "\nHeight: " << Person[i].height;
    
    
           cout << "\nWeight: " << Person[i].weight;
    
    
           cout << "\nID: " << Person[i].id;
    
    
           cout << "\n----------\n";
    
    
       }
    
    
    
    
       cin.get();
    
    
       cin.get();
    
    
       goto mmenu;
    
    
    }
    
    
    
    
    if(choice == 4)
    
    
    {
    
    
    
    
    
    
       system("CLS");
    
    
       cout << "Enter ID of person to remove (-1 = back): ";
    
    
       cin >> choice;
    
    
    
    
       if(choice == -1)
    
    
       {
    
    
       goto mmenu;
    
    
    
    
       }
    
    
    
    
       cout << "Removing " << Person[choice].first_name << "!";
    
    
       Sleep(1600);
    
    
       Person.erase(Person.begin()+choice);
    
    
    
    
       cout << "\n\nPerson removed!";
    
    
       Sleep(1600);
    
    
       goto mmenu;
    
    
    
    
    }
    
    
    
    
    
    
    }
    
    
    
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice