Untitled

 avatar
unknown
plain_text
7 days ago
2.2 kB
3
Indexable
#include <iostream>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;

struct Engine {
    int hp;
    int torque;

    Engine(int hpp=0, int torquee=0) {
        hp = hpp;
        torque = torquee;
    }

    void setSe(int hpp, int torquee) {
        hp = hpp;
        torque = torquee;
    }

    int getHp() {
        return hp;
    }

    int getTorqe() {
        return torque;
    }
};

struct Car {
    char ime[30];
    int godina;
    Engine motor;

    Car(char *imee="", int godinaa=0,Engine motorr=Engine()) {
        strcpy(ime, imee);
        godina = godinaa;
        motor = motorr;
    }

   //  void setIme(char *imee) {
   //      strcpy(ime, imee);
   //  }
   //
   //  void setGod(int godinaa) {
   //      godina = godinaa;
   //  }
   // void setEng(Engine motorr) {
   //  motor = motorr;
   //  }
    void setSe(char *imee, int godinaa, Engine motorr) {
        strcpy(ime,imee);
        godina=godinaa;
        motor=motorr;
    }
    char *getIme() {
        return ime;
    }
    int getGod() {
        return godina;
    }
   Engine getEng() {
        return motor;
    }
};






void print(Car *koli, int n) {

    int min1=-1,min2=0;
// bmw 200, audi 250, benz 150, corsa 350
    for (int i=1;i<n;i++) {
        if (koli[i].getEng().getHp()<koli[min1].getEng().getHp()) {
            min2=min1;
            i=min1;
        } else if (min2== -1 || koli[i].getEng().getHp()<koli[min2].getEng().getHp()) {
            min2=i;
        }
    }
    int l;
    if (koli[min1].getEng().getTorqe()>koli[min2].getEng().getTorqe()) {
        l=min1;
    }
    else {
        l=min2;
    }

    cout << "Ime: " << koli[l].getIme() << endl;
    cout << "Godina: " << koli[l].getGod() << endl;
    cout << "HP: " << koli[l].getEng().getHp() << endl;
    cout << "Torque: " << koli[l].getEng().getTorqe() << endl;
}
int main() {
    int n;
    cin >> n;
    Car niza[n];
    char ime[30];
    int godina, hp, torque;
    for (int i = 0; i < n; i++) {
        cin>>ime>>godina>>hp>>torque;
        Engine eng(hp,torque);
        niza[i].setSe(ime,godina,eng);
    }
print(niza,n);

    return 0;
}
Editor is loading...
Leave a Comment