Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include<iostream>
- #include<string>
- using namespace std;
- struct Repair
- {
- string code;
- string name;
- double price;
- int days;
- };
- Repair repairments[30];
- void EnterDataForRepairments(Repair cars[], int &n);
- void outputMostExpensiveRepair(int n);
- void outputRepairmentsInAscendingOrder(int n);
- void main()
- {
- int n = 0;
- int choice;
- while (true)
- {
- cout << "\t \t Menu:" << endl;
- cout << "1. Vavezdane na danni za remont." << endl;
- cout << "2. Izvezdane na danni za naj-skapiq remont.." << endl;
- cout << "3. Izveznade na remontite sortirani po vahodqsht red otnosno dni" << endl;
- cout << "4. Izhod." << endl;
- do
- {
- cout << "\nVashiq izbor: ";
- cin >> choice;
- } while (choice < 1 || choice > 4);
- switch (choice)
- {
- case 1:
- EnterDataForRepairments(repairments, n);
- break;
- case 2:
- outputMostExpensiveRepair(n);
- break;
- case 3:
- outputRepairmentsInAscendingOrder(n);
- break;
- case 4:
- return;
- default: cout << "Nevaliden izbor." << endl;
- break;
- }
- }
- }
- void EnterDataForRepairments(Repair repaiments[], int &n)
- {
- string code;
- string name;
- double price;
- int days;
- cout << "Broj remonti:";
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- cout << "* * * * * * * * * * * * *" << endl;
- cout << "Vavedete danni za remont " << i + 1 << ":" << endl;
- cout << "Kod: ";
- cin >> code;
- repaiments[i].code = code;
- cout << "Ime: ";
- cin >> name;
- repaiments[i].name = name;
- cout << "Cena: ";
- cin >> price;
- repaiments[i].price = price;
- cout << "Dni: ";
- cin >> days;
- repaiments[i].days = days;
- }
- }
- void outputMostExpensiveRepair(int n)
- {
- Repair mostExpensive = repairments[0];
- for (int i = 0; i < n; i++)
- {
- if (mostExpensive.price < repairments[i].price)
- {
- mostExpensive = repairments[i];
- }
- }
- cout << "Danni za naj-skapiq remont" << endl;
- cout << "Kod: " << mostExpensive.code << endl;
- cout << "Ime: " << mostExpensive.name << endl;
- cout << "Cena: " << mostExpensive.price << endl;
- cout << "Dni: " << mostExpensive.days << endl;
- }
- void outputRepairmentsInAscendingOrder(int n)
- {
- //sort ascenfing:
- for (int j = 1; j < n; j++)
- {
- if (repairments[j - 1].days > repairments[j].days)
- {
- Repair temp = repairments[j];
- repairments[j] = repairments[j - 1];
- repairments[j - 1] = temp;
- }
- }
- //print:
- for (int i = 0; i < n; i++)
- {
- cout << "* * * * * * * * * * * * *" << endl;
- cout << "Remont " << i + 1 << ":" << endl;
- cout << "Kod: " << repairments[i].code << endl;
- cout << "Ime: " << repairments[i].name << endl;
- cout << "Cena: " << repairments[i].price << endl;
- cout << "Dni: " << repairments[i].days << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment