Advertisement
MatiG

Kolokwium 2

Nov 16th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1. // ConsoleApplication7.cpp : Ten plik zawiera funkcję „main”. W nim rozpoczyna się i kończy wykonywanie programu.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include<cstdlib>
  7. #include<string>
  8. using namespace std;
  9. const int Max_Size = 100;
  10. int nr;
  11.  
  12. int CarNumber= 5;
  13. struct Auto
  14. {
  15.     string nazwa;
  16.     double cena;
  17.     int wyroznienie;
  18.     char status;
  19. }; Auto M[Max_Size];
  20.  
  21. void menu();
  22. void AddCar();
  23. void ChangeStatus();
  24. void CountPrice();
  25. void WypelnianieTablicy() {
  26.     M[0].nazwa = "Ford Focus 2";
  27.     M[0].cena = 12200;
  28.     M[0].status = 's';
  29.     M[0].wyroznienie = 0;
  30.     M[1].nazwa = "Volkswagen Golf IV";
  31.     M[1].cena = 99900.50;
  32.     M[1].status = 'r';
  33.     M[1].wyroznienie = 2;
  34.     M[2].nazwa="Fiat Multipla";
  35.     M[2].cena = 1000.4;
  36.     M[2].status = 's';
  37.     M[2].wyroznienie = 1;
  38.     M[3].nazwa = "Honda Civic";
  39.     M[3].cena = 45000;
  40.     M[3].status = 'z';
  41.     M[3].wyroznienie = 1;
  42.     M[4].nazwa = "Ford Mustang";
  43.     M[4].cena = 5555;
  44.     M[4].status = 'z';
  45.     M[4].wyroznienie = 2;
  46. }
  47.  
  48. void AddCar() {
  49.    
  50.     cout << endl <<"Podaj nazwe: ";
  51.     cin>> M[CarNumber].nazwa;
  52.     cout << endl << " podaj cene: ";
  53.     cin >> M[CarNumber].cena;
  54.     cout << endl << "podaj wyronznienie: ";
  55.     cin >> M[CarNumber].wyroznienie;
  56.     M[CarNumber].status = 's';
  57.     CarNumber++;
  58.     menu();
  59. }
  60. void ShowList()
  61. {
  62.     int a=2;
  63.     for (int i = 0; i < CarNumber; i++)
  64.     {
  65.         for (int j = 0; j < CarNumber; j++)
  66.         {
  67.             if (M[j].wyroznienie == a)
  68.             {
  69.                 cout << M[j].nazwa << endl;
  70.                 cout << M[j].cena << endl;
  71.                 cout << M[j].status << endl;
  72.                 cout << M[j].wyroznienie << endl;
  73.             }
  74.         }
  75.         a--;
  76.         }
  77.     menu();
  78.     }
  79.  
  80.  
  81. void ChangeStatus()
  82. {
  83.     string name;
  84.     cout << "podaj nazwe auta: ";
  85.     char sat;
  86.     cin.ignore();
  87.     getline(cin, name);
  88.    
  89.     for (int i = 0; i < CarNumber; i++)
  90.     {
  91.         if (M[i].nazwa == name)
  92.         {
  93.            
  94.             cout << "podaj nowy status: ";
  95.             cin >> sat;
  96.             if (sat == 'r' || sat == 'z' || sat == 's')
  97.             {
  98.                 M[i].status = sat;
  99.                 cout << M[i].status;
  100.                 menu();
  101.                 return;
  102.             }
  103.             else cout << " nie mozna uzyc takiego statusu" << endl;
  104.             menu();
  105.             return;
  106.         }
  107.        
  108.     }
  109.     cout << " nie ma auta o takiej nazwie" << endl;
  110.     menu();
  111. }
  112. void CountPrice()
  113. {
  114.     double suma=0;
  115.     char s;
  116.     cout << "podaj status: ";
  117.     cin >> s;
  118.     for (int i = 0; i < CarNumber; i++)
  119.     {
  120.         if (M[i].status == s)
  121.         {
  122.             suma += M[i].cena;
  123.         }
  124.     }
  125.     cout << "cena aut ze statusem " << s << " jest rowna: " << suma;
  126.     menu();
  127. }
  128. void menu() {
  129.     cout << "1- dodanie samochodu" << endl;
  130.     cout << "2- wypisanie samochodow" << endl;
  131.     cout << "3- zmiana statusu" << endl;
  132.     cout << "4- wyliczenie sumarycznej ceny" << endl;
  133.     cout << "5- koniec programu" << endl;
  134.     cin >> nr;
  135.     switch (nr)
  136.     {
  137.     case(1): {
  138.         AddCar(); break;
  139.         }
  140.     case(2): {
  141.         ShowList(); break;
  142.         }
  143.     case(3):
  144.         ChangeStatus();
  145.         break;
  146.        
  147.     case(4): {
  148.         CountPrice(); break;
  149.         }
  150.     case(5): {
  151.         system("pause");  break;
  152.         }
  153.     default:
  154.         break;
  155.     }
  156. }
  157. int main()
  158. {
  159.     WypelnianieTablicy();
  160.     menu();
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement