Advertisement
Waliul

TAMS(NEW)

Mar 25th, 2021
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. class NewTravelTrip
  7. {
  8. public:
  9.     NewTravelTrip();
  10.     NewTravelTrip(int m)
  11.     { }
  12.     void AddTrip();
  13.     string name;
  14.     string date;
  15.     string address;
  16.     string phoneno;
  17.     int invoice;
  18.     string email;
  19.     vector<string>tripdate;
  20.     void EditTrip();
  21.     void DeleteTrip();
  22.     //string date;
  23.     vector<string>startlocation;
  24.     vector<string>finaldestination;
  25.  
  26. };
  27.  
  28. vector<NewTravelTrip>trips;
  29. int inv;
  30.  
  31. class ShowAllUser
  32. {
  33. public:
  34.     void showUser();
  35.     int invoice;
  36.     string name;
  37.     string date;
  38.     string address;
  39.     string phoneno;
  40.     string email;
  41.     string tripdate;
  42.     string triplocation;
  43.  
  44.     void DeleteUser();
  45.     void EditUser();
  46.  
  47.  
  48. };
  49.  
  50. NewTravelTrip::NewTravelTrip()
  51. {
  52.     string t_date, s_loc, f_des;
  53.     invoice = inv;
  54.     cout << "\n\tInvoice ID: " << invoice ;
  55.     getline(cin,date);
  56.     cout << "\n\tEnter Date: " ;
  57.     getline(cin,date);
  58.     cout << "\tEnter User Name: " ;
  59.     getline(cin, name);
  60.     cout << "\tEnter User Address: " ;
  61.     getline(cin, address);
  62.     cout << "\tEnter User Phone No.: " ;
  63.     cin >> phoneno;
  64.     cout << "\tEnter User Email Address: " ;
  65.     cin >> email;
  66.     cout << "\tEnter Trip Date: " ;
  67.     cin >> t_date;
  68.     cout << "\tEnter Trip Location: \n" ;
  69.     getline(cin, s_loc);
  70.     cout <<"\t\tStart Location : ";
  71.     getline(cin, s_loc);
  72.     cout <<"\t\tFinal Location : ";
  73.     getline(cin, f_des);
  74.     tripdate.push_back(t_date);
  75.     startlocation.push_back(s_loc);
  76.     finaldestination.push_back(f_des);
  77.     inv++;
  78. }
  79.  
  80. void NewTravelTrip::AddTrip()
  81. {
  82.     int in_id, i, j;
  83.     cout<<"\n\tEnter Invoice ID : ";
  84.     cin>>in_id;
  85.     for(i = 0; i < trips.size(); i++)
  86.     {
  87.         if(trips[i].invoice == in_id)
  88.             j = i;
  89.     }
  90.     string t_date, s_loc, f_des;
  91.     cout << "\tEnter Trip Date: " ;
  92.     cin >> t_date;
  93.     cout << "\tEnter Trip Location: \n" ;
  94.     getline(cin, s_loc);
  95.     cout <<"\t\tStart Location : ";
  96.     getline(cin, s_loc);
  97.     cout <<"\t\tFinal Location : ";
  98.     getline(cin, f_des);
  99.     trips[j].tripdate.push_back(t_date);
  100.     trips[j].startlocation.push_back(s_loc);
  101.     trips[j].finaldestination.push_back(f_des);
  102. }
  103.  
  104. void NewTravelTrip::EditTrip()
  105. {
  106.     int in_id, i, j, x, y, z;
  107.     cout<<"\n\tEnter Invoice ID : ";
  108.     cin>>in_id;
  109.     for(i = 0; i < trips.size(); i++)
  110.     {
  111.         if(trips[i].invoice == in_id)
  112.             j = i;
  113.     }
  114.     for(x = 0; x < trips[j].tripdate.size(); x++)
  115.     {
  116.         cout<<"\tDo you want to edit this trip? Enter 'Y' for yes, 'N' for no."<<endl;
  117.         cout << "\tTrip Date: " <<trips[j].tripdate[x]<<endl;
  118.         cout << "\tTrip Location: "<<endl;
  119.         cout <<"\t\tStart Location : "<<trips[j].startlocation[x]<<endl;
  120.         cout <<"\t\tFinal Location : "<<trips[j].finaldestination[x]<<endl<<endl;
  121.         string inp;
  122.         cin>>inp;
  123.         if(inp == "Y")
  124.         {
  125.             string t_date, s_loc, f_des;
  126.             cout << "\n\tEnter Trip Date: " ;
  127.             cin >> t_date;
  128.             cout << "\tEnter Trip Location: \n" ;
  129.             getline(cin, s_loc);
  130.             cout <<"\t\tStart Location : ";
  131.             getline(cin, s_loc);
  132.             cout <<"\t\tFinal Location : ";
  133.             getline(cin, f_des);
  134.             trips[j].tripdate[x] = t_date;
  135.             trips[j].startlocation[x] = s_loc;
  136.             trips[j].finaldestination[x] = f_des;
  137.             break;
  138.         }
  139.     }
  140. }
  141.  
  142. void NewTravelTrip::DeleteTrip()
  143. {
  144.     int in_id, i, j, x, y, z;
  145.     cout<<"\n\tEnter Invoice ID : ";
  146.     cin>>in_id;
  147.     for(i = 0; i < trips.size(); i++)
  148.     {
  149.         if(trips[i].invoice == in_id)
  150.             j = i;
  151.     }
  152.     for(x = 0; x < trips[j].tripdate.size(); x++)
  153.     {
  154.         cout<<"\tDo you want to delete this trip? Enter 'Y' for yes, 'N' for no."<<endl;
  155.         cout << "\tTrip Date: " <<trips[j].tripdate[x]<<endl;
  156.         cout << "\tTrip Location: "<<endl;
  157.         cout <<"\t\tStart Location : "<<trips[j].startlocation[x]<<endl;
  158.         cout <<"\t\tFinal Location : "<<trips[j].finaldestination[x]<<endl<<endl;
  159.         string inp;
  160.         cin>>inp;
  161.         if(inp == "Y")
  162.         {
  163.             vector<string>::iterator it;
  164.  
  165.             it = trips[j].tripdate.begin();
  166.             for(y = 0; y < x; y++)
  167.                 it++;
  168.             trips[j].tripdate.erase(it);
  169.  
  170.             it = trips[j].startlocation.begin();
  171.             for(y = 0; y < x; y++)
  172.                 it++;
  173.             trips[j].startlocation.erase(it);
  174.  
  175.             it = trips[j].finaldestination.begin();
  176.             for(y = 0; y < x; y++)
  177.                 it++;
  178.             trips[j].finaldestination.erase(it);
  179.  
  180.             break;
  181.         }
  182.     }
  183. }
  184.  
  185. void ShowAllUser::showUser()
  186. {
  187.     int sz, i, j;
  188.     sz = trips.size();
  189.     for(i = 0; i < sz; i++)
  190.     {
  191.  
  192.         cout << "\n\tInvoice ID: " << trips[i].invoice<<endl ;
  193.         cout << "\tDate: " <<trips[i].date<<endl;
  194.         cout << "\tUser Name: " <<trips[i].name<<endl;
  195.         cout << "\tUser Address: " <<trips[i].address<<endl;
  196.         cout << "\tUser Phone No.: " <<trips[i].phoneno<<endl;
  197.         cout << "\tUser Email Address: " <<trips[i].email<<endl;
  198.         for(j = 0; j < trips[i].tripdate.size(); j++)
  199.         {
  200.             cout << "\tTrip Date: " <<trips[i].tripdate[j]<<endl;
  201.             cout << "\tTrip Location: "<<endl;
  202.             cout <<"\t\tStart Location : "<<trips[i].startlocation[j]<<endl;
  203.             cout <<"\t\tFinal Location : "<<trips[i].finaldestination[j]<<endl<<endl;
  204.         }
  205.         cout<<endl<<endl;
  206.     }
  207. }
  208.  
  209. void ShowAllUser::EditUser()
  210. {
  211.     int in_id, i, j, x, y, z;
  212.     string t_date, s_loc, f_des;
  213.     cout<<"\n\tEnter Invoice ID : ";
  214.     cin>>in_id;
  215.     for(i = 0; i < trips.size(); i++)
  216.     {
  217.         if(trips[i].invoice == in_id)
  218.             j = i;
  219.     }
  220.     getline(cin, trips[j].date);
  221.     cout << "\tEnter New Date: " ;
  222.     getline(cin, trips[j].date);
  223.     cout << "\tEnter New User Name: " ;
  224.     getline(cin, trips[j].name);
  225.     cout << "\tEnter New User Address: " ;
  226.     getline(cin, trips[j].address);
  227.     cout << "\tEnter New User Phone No.: " ;
  228.     cin >> trips[j].phoneno;
  229.     cout << "\tEnter User New Email Address: " ;
  230.     cin >> trips[j].email;
  231.  
  232.     trips[j].tripdate.clear();
  233.     trips[j].finaldestination.clear();
  234.     trips[j].startlocation.clear();
  235.  
  236.     getline(cin, t_date);
  237.     cout << "\tEnter New Trip Date: " ;
  238.     getline(cin, t_date);
  239.     cout << "\tEnter New Trip Location: \n" ;
  240.     cout <<"\t\tStart New Location : ";
  241.     getline(cin, s_loc);
  242.     cout <<"\t\tFinal New Location : ";
  243.     getline(cin, f_des);
  244.     trips[j].tripdate.push_back(t_date);
  245.     trips[j].startlocation.push_back(s_loc);
  246.     trips[j].finaldestination.push_back(f_des);
  247. }
  248.  
  249. void ShowAllUser::DeleteUser()
  250. {
  251.     int in_id, i, j, x, y, z;
  252.     string t_date, s_loc, f_des;
  253.     cout<<"Enter Invoice ID : ";
  254.     cin>>in_id;
  255.     for(i = 0; i < trips.size(); i++)
  256.     {
  257.         if(trips[i].invoice == in_id)
  258.             j = i;
  259.     }
  260.     vector<NewTravelTrip>::iterator it;
  261.     it = trips.begin();
  262.     for(i = 0; i < j; i++)
  263.         it++;
  264.     trips.erase(it);
  265. }
  266.  
  267. int main()
  268. {
  269.     int choice;
  270.     inv = 1;
  271.     while(1)
  272.     {
  273.         cout <<"Please, Choose Your Option:  "<<endl;
  274.         cout <<endl;
  275.         cout<<"     1. New Travel Trip. "<<endl;
  276.         cout<<"     2. Show All Users. "<<endl;
  277.         cout<<"     3. Edit User. "<<endl;
  278.         cout<<"     4. Delete User. "<<endl;
  279.         cout<<"     5. Add Trip. "<<endl;
  280.         cout<<"     6. Edit Trip. "<<endl;
  281.         cout<<"     7. Delete Trip. "<<endl;
  282.         cout<<endl;
  283.         cout<<"     Enter Your Choice: ";
  284.         cin>>choice;
  285.         if(choice == 1)
  286.         {
  287.             cout <<"\nYou have chosen New Travel Trip"<<endl;
  288.             NewTravelTrip ad;
  289.  
  290.             trips.push_back(ad);
  291.             cout <<"\nPress any key to go to the main menu";
  292.             getch();
  293.             cout<<endl<<endl;
  294.         }
  295.         if(choice == 2)
  296.         {
  297.             cout <<"\nYou have chosen Show All Users"<<endl;
  298.             ShowAllUser show;
  299.             show.showUser();
  300.             cout <<"\nPress any key to go to the main menu";
  301.             getch();
  302.             cout<<endl<<endl;
  303.         }
  304.         if(choice == 3)
  305.         {
  306.             cout <<"\nYou have chosen Edit User"<<endl;
  307.             ShowAllUser ed;
  308.             ed.EditUser();
  309.             cout <<"\nPress any key to go to the main menu";
  310.             getch();
  311.             cout<<endl<<endl;
  312.         }
  313.         if(choice == 4)
  314.         {
  315.             cout <<"\nYou have chosen Delete User"<<endl;
  316.             ShowAllUser ed;
  317.             ed.DeleteUser();
  318.             cout <<"\nPress any key to go to the main menu";
  319.             getch();
  320.             cout<<endl<<endl;
  321.         }
  322.         if(choice == 5)
  323.         {
  324.             cout <<"\nYou have chosen Add Trip"<<endl;
  325.             NewTravelTrip tp(0);
  326.             tp.AddTrip();
  327.             cout <<"\nPress any key to go to the main menu";
  328.             getch();
  329.             cout<<endl<<endl;
  330.         }
  331.         if(choice == 6)
  332.         {
  333.             cout <<"\nYou have chosen Edit Trip"<<endl;
  334.             NewTravelTrip tp(0);
  335.             tp.EditTrip();
  336.             cout <<"\nPress any key to go to the main menu";
  337.             getch();
  338.             cout<<endl<<endl;
  339.         }
  340.         if(choice == 7)
  341.         {
  342.             cout <<"\nYou have chosen Delete Trip"<<endl;
  343.             NewTravelTrip tp(0);
  344.             tp.DeleteTrip();
  345.             cout <<"\nPress any key to go to the main menu";
  346.             getch();
  347.             cout<<endl<<endl;
  348.         }
  349.         else
  350.         {
  351.             cout<<"\nWrong Input!Going back to Main Menu.\n\n";
  352.         }
  353.     }
  354.     return 0;
  355. }
  356.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement