Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication7.cpp : Ten plik zawiera funkcję „main”. W nim rozpoczyna się i kończy wykonywanie programu.
- //
- #include "pch.h"
- #include <iostream>
- #include<cstdlib>
- #include<string>
- using namespace std;
- const int Max_Size = 100;
- int nr;
- int CarNumber= 5;
- struct Auto
- {
- string nazwa;
- double cena;
- int wyroznienie;
- char status;
- }; Auto M[Max_Size];
- void menu();
- void AddCar();
- void ChangeStatus();
- void CountPrice();
- void WypelnianieTablicy() {
- M[0].nazwa = "Ford Focus 2";
- M[0].cena = 12200;
- M[0].status = 's';
- M[0].wyroznienie = 0;
- M[1].nazwa = "Volkswagen Golf IV";
- M[1].cena = 99900.50;
- M[1].status = 'r';
- M[1].wyroznienie = 2;
- M[2].nazwa="Fiat Multipla";
- M[2].cena = 1000.4;
- M[2].status = 's';
- M[2].wyroznienie = 1;
- M[3].nazwa = "Honda Civic";
- M[3].cena = 45000;
- M[3].status = 'z';
- M[3].wyroznienie = 1;
- M[4].nazwa = "Ford Mustang";
- M[4].cena = 5555;
- M[4].status = 'z';
- M[4].wyroznienie = 2;
- }
- void AddCar() {
- cout << endl <<"Podaj nazwe: ";
- cin>> M[CarNumber].nazwa;
- cout << endl << " podaj cene: ";
- cin >> M[CarNumber].cena;
- cout << endl << "podaj wyronznienie: ";
- cin >> M[CarNumber].wyroznienie;
- M[CarNumber].status = 's';
- CarNumber++;
- menu();
- }
- void ShowList()
- {
- int a=2;
- for (int i = 0; i < CarNumber; i++)
- {
- for (int j = 0; j < CarNumber; j++)
- {
- if (M[j].wyroznienie == a)
- {
- cout << M[j].nazwa << endl;
- cout << M[j].cena << endl;
- cout << M[j].status << endl;
- cout << M[j].wyroznienie << endl;
- }
- }
- a--;
- }
- menu();
- }
- void ChangeStatus()
- {
- string name;
- cout << "podaj nazwe auta: ";
- char sat;
- cin.ignore();
- getline(cin, name);
- for (int i = 0; i < CarNumber; i++)
- {
- if (M[i].nazwa == name)
- {
- cout << "podaj nowy status: ";
- cin >> sat;
- if (sat == 'r' || sat == 'z' || sat == 's')
- {
- M[i].status = sat;
- cout << M[i].status;
- menu();
- return;
- }
- else cout << " nie mozna uzyc takiego statusu" << endl;
- menu();
- return;
- }
- }
- cout << " nie ma auta o takiej nazwie" << endl;
- menu();
- }
- void CountPrice()
- {
- double suma=0;
- char s;
- cout << "podaj status: ";
- cin >> s;
- for (int i = 0; i < CarNumber; i++)
- {
- if (M[i].status == s)
- {
- suma += M[i].cena;
- }
- }
- cout << "cena aut ze statusem " << s << " jest rowna: " << suma;
- menu();
- }
- void menu() {
- cout << "1- dodanie samochodu" << endl;
- cout << "2- wypisanie samochodow" << endl;
- cout << "3- zmiana statusu" << endl;
- cout << "4- wyliczenie sumarycznej ceny" << endl;
- cout << "5- koniec programu" << endl;
- cin >> nr;
- switch (nr)
- {
- case(1): {
- AddCar(); break;
- }
- case(2): {
- ShowList(); break;
- }
- case(3):
- ChangeStatus();
- break;
- case(4): {
- CountPrice(); break;
- }
- case(5): {
- system("pause"); break;
- }
- default:
- break;
- }
- }
- int main()
- {
- WypelnianieTablicy();
- menu();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement