Advertisement
Guest User

maincode1

a guest
Dec 7th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string.h>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. class menu {
  9. private:
  10.         int optn;
  11. public:
  12.     void menuOptn () {
  13.  
  14.         // ........................................menu start......................................................................//
  15.         cout<<endl;
  16.         cout<<endl;
  17.         cout<<endl;
  18.         cout<<"              "<<"***********************************************************************************"<<endl;
  19.         cout<<"              "<<"* "<<"                                                                                *"<<endl;
  20.         cout<<"              "<<"*                           "<<"1. Enter new user"<<"                                     *"<<endl;
  21.         cout<<"              "<<"* "<<"                                                                                *"<<endl;
  22.         cout<<"              "<<"*                           "<<"2. search user from ID"<<"                                *"<<endl;
  23.         cout<<"              "<<"* "<<"                                                                                *"<<endl;
  24.         cout<<"              "<<"*                           "<<"3. print all user data"<<"                                *"<<endl;
  25.         cout<<"              "<<"* "<<"                                                                                *"<<endl;
  26.         cout<<"              "<<"*                           "<<"4. delete user by ID"<<"                                  *"<<endl;
  27.         cout<<"              "<<"* "<<"                                                                                *"<<endl;
  28.         cout<<"              "<<"*                           "<<"5. close program"<<"                                      *"<<endl;
  29.         cout<<"              "<<"* "<<"                                                                                *"<<endl;
  30.         cout<<"              "<<"***********************************************************************************"<<endl;
  31.         // ........................................menu end.....................................................................//
  32.     }
  33.  
  34.  
  35. };
  36.  
  37. class employee {
  38.  
  39. protected:
  40.    vector<int> empId;
  41.    vector<string>empName;
  42.    vector<string>empPost;
  43.    vector<string>empSalary;
  44.  
  45. public:
  46.    void setVectorInitialValue () {
  47.         string nameArr[4] = {"C111","C112","C113","C114"};
  48.         string postArr[4] = {"A111","A112","A113","A114"};
  49.         string salaryArr[4]= {"B111","B112","B113","B114"};
  50.         int idArr[4] = {111, 112,113,114};
  51.  
  52.         empId.assign(idArr, idArr+4);
  53.         empName.assign(nameArr, nameArr+4);
  54.         empPost.assign(postArr, postArr+4);
  55.         empSalary.assign(salaryArr, salaryArr+4);
  56.    }
  57.    void setEmpId (int id) {
  58.         empId.push_back(id);
  59.    }
  60.    void setEmpName (string name) {
  61.         empName.push_back(name);
  62.    }
  63.    void setEmpPOst (string post) {
  64.         empPost.push_back(post);
  65.    }
  66.    void setEmpSalary (string salary) {
  67.         empSalary.push_back(salary);
  68.     }
  69.  
  70.      void display() {
  71.         int sIze = empId.size();
  72.  
  73.         for (int i=0; i<sIze ;i++) {
  74.             cout<<"ID: "<<empId[i]<<" "<<"NAME: "<<" "<<empName[i]<<" "<<"POST: "<<" "<<empPost[i]<<" "<<"SALARY: "<<empSalary[i]<<endl;
  75.         }
  76.  
  77.     }
  78.     void test () {
  79.         cout << empId[1];
  80.     }
  81.  
  82. };
  83.  
  84. /* class searchEmp:public employee {
  85. private:
  86.    int usrID;
  87.  
  88. public:
  89.     void setUsrId ( int m_usrId) {
  90.         usrID = m_usrId;
  91.     }
  92.  
  93.     void display()  {
  94.  
  95.         cout<<empName[1];
  96.         int sIze = empId.size();
  97.  
  98.         for (int i=0; i<sIze ;i++) {
  99.  
  100.           if (usrID == empId[i])
  101.             cout<<"ID: "<<empId[i]<<" "<<"NAME: "<<" "<<empName[i]<<" "<<"POST: "<<" "<<empPost[i]<<" "<<"SALARY: "<<empSalary[i]<<endl;
  102.             //break;
  103.         }
  104.     }
  105.  
  106.  
  107.  
  108. };
  109.  
  110. class fireEmp:public employee {
  111. private:
  112.     int usrID;
  113. public:
  114.     void setUsrID (int m_usrid) {
  115.         usrID = m_usrid;
  116.     }
  117.  
  118.     void display()  {
  119.         int sIze = empId.size();
  120.         for (int i=0; i<sIze ;i++) {
  121.  
  122.             if (empId[i]==usrID) {
  123.                 empId.erase(empId.begin() +i);
  124.                 empName.erase(empName.begin() +i);
  125.                 empPost.erase(empPost.begin() +i);
  126.                 empSalary.erase(empSalary.begin() +i);
  127.                 break;
  128.             }
  129.         }
  130.     }
  131. };
  132. */
  133. int getUsrChoice () {
  134.     int usrChoice;
  135.     cout<< "ENTER THE NUMBER OF THE OPTION YOU WANT TO PICK: "<<endl;
  136.     cin>> usrChoice;
  137.     return usrChoice;
  138. }
  139.  
  140. int main () {
  141.  
  142.      int tempId; string tempName; string tempPost; string tempSalary;
  143.  
  144.  
  145.     menu m1; employee *e1, e2;
  146.  
  147.     //searchEmp s1; fireEmp f1;
  148.  
  149.  
  150.     e2.setVectorInitialValue();
  151.     m1.menuOptn();
  152.     //--------  user choice -------//
  153.  
  154.     if(getUsrChoice()== 1) {
  155.         cout<<"ID: "; cin >> tempId;
  156.         cout<<"NAME: "; cin >>tempName;
  157.         cout<<"POST: "; cin >> tempPost;
  158.         cout<<"SALARY: "; cin >> tempSalary; cout<<endl;
  159.  
  160.         e2.setEmpId(tempId);
  161.         e2.setEmpName(tempName);
  162.         e2.setEmpPOst(tempPost);
  163.         e2.setEmpSalary(tempSalary);
  164.     }
  165.  
  166.  
  167.      if (getUsrChoice() == 2) {
  168.         cout<<"ENTER USER ID: "; cin >> tempId;
  169.         //s1.setUsrId(tempId);
  170.         //s1.display();
  171.         e2.display();
  172.  
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement