Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Strukturos 1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "iostream"
- #include "iomanip"
- #include "cstdlib"
- #include "string"
- #include "fstream"
- #include "cstring"
- using namespace std;
- struct Cars {
- int number; // cars number in the list
- string LicenzePlate; // cars licenze plate number
- string Model; // car model
- int Year; // year car was made
- string Color; // color
- string FuelType; // fuel type
- int Power; // car power in kw
- int FuelUsageC; // fuel usage in town
- int FuelUsageOC; // fuel usage outside of town
- string Chasy; //chasy type
- };
- Cars A[100] = { 0 };
- void read();
- void colorselected();
- void FuelPrice();
- void Oldcars();
- void AddingCars();
- void Sorting();
- void Print();
- void MainMenu();
- string name = "Read.txt";
- string color;
- string line;
- int NoOfCars;
- bool PrintFuel = false;
- int main() {
- cout << ("LD 1") << endl;
- cout << ("IF160016") << endl;
- cout << ("Mindaugas Jurgelenas") << endl;
- read();
- MainMenu();
- system("pause");
- return 0;
- }
- void MainMenu() {
- //constantly getting double menu in console?
- int selection;
- cout << ("================ MENU ===================") << endl;
- cout << ("Search car by color: 1") << endl;
- cout << ("Car Removing from the list: 2") << endl;
- cout << ("Car Adding to the list: 3") << endl;
- cout << ("Sorting list of cars: 4") << endl;
- cout << ("Fuel price calculation: 5") << endl;
- cout << ("Exit: 0") << endl;
- cin >> selection;
- if (selection == 1)
- colorselected();
- else if (selection == 2)
- Oldcars();
- else if (selection == 3)
- AddingCars();
- else if (selection == 4)
- Sorting();
- else if (selection == 5)
- FuelPrice();
- else
- return;
- }
- void read() {
- cout << ("Enter file name: ");
- cin >> name;
- ifstream file(name);
- if (!file) {
- cout << ("Error while openining file!") << endl;
- system("pause");
- }
- else {
- cout << ("Reading...") << endl;
- int i = 0;
- while (!file.eof()) {
- file >> A[i].number;
- file >> A[i].LicenzePlate;
- file >> A[i].Model;
- file >> A[i].Year;
- file >> A[i].Color;
- file >> A[i].FuelType;
- file >> A[i].Power;
- file >> A[i].FuelUsageC;
- file >> A[i].FuelUsageOC;
- file >> A[i].Chasy;
- i++;
- }
- NoOfCars = i;
- cout << ("NoOfCars: ") << NoOfCars << endl;
- }
- file.close();
- cout << ("Reading finnished!") << endl;
- Print();
- }
- void colorselected() {
- cout << endl;
- cout << ("Enter color of car your looking for: ");
- cin >> color;
- for (int i = 0; i < NoOfCars; i++) {
- if (color == A[i].Color) {
- cout << "=========== NAUJA EILUTE ================\n";
- cout << "Eil.nr --------- " << A[i].number << endl;
- cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
- cout << " Automobilio marke: " << A[i].Model << endl;
- cout << " Pagaminimo metai: " << A[i].Year << endl;
- cout << " Automobilio spalva: " << A[i].Color << endl;
- cout << " Kuro tipas: " << A[i].FuelType << endl;
- cout << " Automobilio galia: " << A[i].Power << endl;
- cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << endl;
- cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << endl;
- cout << " Kebulo tipas: " << A[i].Chasy << endl;
- }
- }
- MainMenu();
- }
- float Diesel;
- float Gasoline;
- float Gas;
- float Electricity;
- void FuelPrice() {
- cout << endl;
- cout << ("Enter price for 1 litre of diesel: ");
- cin >> Diesel;
- cout << ("Enter price for 1 litre of gasoline: ");
- cin >> Gasoline;
- cout << ("Enter price for 1 kubik litre of gas: ");
- cin >> Gas;
- cout << ("Enter price for 1 kw/h of electicity: ");
- cin >> Electricity;
- PrintFuel = true;
- Print();
- }
- void Oldcars() {
- int currentyear;
- cout << "kokie dabar metai ?" << endl;
- cin >> currentyear;
- for (int i = 0; i < NoOfCars; i++) {
- if ((currentyear - A[i].Year) >= 15) {
- for (int j = i; j < NoOfCars-1; j++) {
- A[j] = A[j + 1];
- }
- i--;
- NoOfCars--;
- }
- }
- //for some reasong this doesn't work...
- for (int i = 0; i < NoOfCars; i++) {
- cout << i << endl;
- A[i].number == i++;
- }
- Print();
- }
- void AddingCars() {
- cout << endl;
- A[NoOfCars].number = NoOfCars + 1;
- cout << "Iveskite informacija apie automobili:\n";
- cout << "Automobilio numeriai: ";
- cin >> A[NoOfCars].LicenzePlate;
- cout << "Automobilio marke: ";
- cin >> A[NoOfCars].Model;
- cout << "Pagaminimo metai: ";
- cin >> A[NoOfCars].Year;
- cout << "Automobilio spalva: ";
- cin >> A[NoOfCars].Color;
- cout << "Kuro tipas: ";
- cin >> A[NoOfCars].FuelType;
- cout << "Variklio galingumas (kW): ";
- cin >> A[NoOfCars].Power;
- cout << "Kuro sanaudos mieste: ";
- cin >> A[NoOfCars].FuelUsageC;
- cout << "Kuro sanaudos uzmiestyje: ";
- cin >> A[NoOfCars].FuelUsageOC;
- cout << "Kebulo tipas: ";
- cin >> A[NoOfCars].Chasy;
- NoOfCars++;
- Print();
- }
- void Sorting() {
- Cars maximum;
- for (int i = 0; i < NoOfCars; i++) {
- for (int j = 0; j < NoOfCars; j++) {
- if (A[j].Year < A[i].Year) {
- maximum = A[j];
- A[j] = A[i];
- A[i] = maximum;
- }
- }
- }
- Print();
- }
- void Print() {
- system("cls");
- for (int i = 0; i < NoOfCars; i++) {
- cout << endl;
- cout << "=========== NAUJA EILUTE ================\n";
- cout << "Eil.nr --------- " << A[i].number << endl;
- cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
- cout << " Automobilio marke: " << A[i].Model << endl;
- cout << " Pagaminimo metai: " << A[i].Year << endl;
- cout << " Automobilio spalva: " << A[i].Color << endl;
- cout << " Kuro tipas: " << A[i].FuelType << endl;
- cout << " Automobilio galia: " << A[i].Power << endl;
- cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << endl;
- cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << endl;
- cout << " Kebulo tipas: " << A[i].Chasy << endl;
- }
- if (PrintFuel == true) {
- PrintFuel = false;
- for (int i = 0; i < NoOfCars; i++) {
- if (A[i].FuelType == "benzinas") {
- cout << "=========== NAUJA EILUTE ================\n";
- cout << "Eil.nr --------- " << A[i].number << endl;
- cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
- cout << " Automobilio marke: " << A[i].Model << endl;
- cout << " Pagaminimo metai: " << A[i].Year << endl;
- cout << " Automobilio spalva: " << A[i].Color << endl;
- cout << " Kuro tipas: " << A[i].FuelType << endl;
- cout << " Automobilio galia: " << A[i].Power << endl;
- cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << (", Kuro kaina 1000km mieste: ") << A[i].FuelUsageC*Gasoline * 10 << (" eur") << endl;
- cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << (", Kuro kaina 1000km uzmiestyje: ") << A[i].FuelUsageOC*Gasoline * 10 << (" eur") << endl;
- cout << " Kebulo tipas: " << A[i].Chasy << endl;
- }
- if (A[i].FuelType == "dyzelinas") {
- cout << "=========== NAUJA EILUTE ================\n";
- cout << "Eil.nr --------- " << A[i].number << endl;
- cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
- cout << " Automobilio marke: " << A[i].Model << endl;
- cout << " Pagaminimo metai: " << A[i].Year << endl;
- cout << " Automobilio spalva: " << A[i].Color << endl;
- cout << " Kuro tipas: " << A[i].FuelType << endl;
- cout << " Automobilio galia: " << A[i].Power << endl;
- cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << (", Kuro kaina 1000km mieste: ") << A[i].FuelUsageC*Diesel * 10 << (" eur") << endl;
- cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << (", Kuro kaina 1000km uzmiestyje: ") << A[i].FuelUsageOC*Diesel * 10 << (" eur") << endl;
- cout << " Kebulo tipas: " << A[i].Chasy << endl;
- }
- if (A[i].FuelType == "dujos") {
- cout << "=========== NAUJA EILUTE ================\n";
- cout << "Eil.nr --------- " << A[i].number << endl;
- cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
- cout << " Automobilio marke: " << A[i].Model << endl;
- cout << " Pagaminimo metai: " << A[i].Year << endl;
- cout << " Automobilio spalva: " << A[i].Color << endl;
- cout << " Kuro tipas: " << A[i].FuelType << endl;
- cout << " Automobilio galia: " << A[i].Power << endl;
- cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << (", Kuro kaina 1000km mieste: ") << A[i].FuelUsageC*Gas * 10 << (" eur") << endl;
- cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << (", Kuro kaina 1000km uzmiestyje: ") << A[i].FuelUsageOC*Gas * 10 << (" eur") << endl;
- cout << " Kebulo tipas: " << A[i].Chasy << endl;
- }
- if (A[i].FuelType == "elektra") {
- cout << "=========== NAUJA EILUTE ================\n";
- cout << "Eil.nr --------- " << A[i].number << endl;
- cout << " Valstybinis numeris: " << A[i].LicenzePlate << endl;
- cout << " Automobilio marke: " << A[i].Model << endl;
- cout << " Pagaminimo metai: " << A[i].Year << endl;
- cout << " Automobilio spalva: " << A[i].Color << endl;
- cout << " Kuro tipas: " << A[i].FuelType << endl;
- cout << " Automobilio galia: " << A[i].Power << endl;
- cout << " Kuro sanaudos mieste: " << A[i].FuelUsageC << (", Kuro kaina 1000km mieste: ") << A[i].FuelUsageC*Gas * 10 << (" eur") << endl;
- cout << " Kuro sanaudos uzmiestyje: " << A[i].FuelUsageOC << (", Kuro kaina 1000km uzmiestyje: ") << A[i].FuelUsageOC*Gas * 10 << (" eur") << endl;
- cout << " Kebulo tipas: " << A[i].Chasy << endl;
- }
- }
- }
- MainMenu();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement