lab1_zad2
gorazd
c_cpp
a month ago
1.2 kB
3
Indexable
OOP_labs_stari
#include <cstring> #include <iostream> using namespace std; struct Engine { int horsepower; int torque; }; struct car { char name[20]; int yearProd; Engine engine; }; void swap(car &a, car &b) { car temp; temp = a; a = b; b = temp; } void bubbleSort(car *cars,int n) { for(int i=0;i<n;i++) { for(int j=0;j<n-i-1;j++) { if(cars[j].engine.horsepower>cars[j+1].engine.horsepower) swap(cars[j],cars[j+1]); } } } int main() { int n; cin>>n; car cars[n]; for(int i=0;i<n;i++) { cin>>cars[i].name >>cars[i].yearProd >> cars[i].engine.horsepower >> cars[i].engine.torque; } bubbleSort(cars,n); if(cars[0].engine.torque>cars[1].engine.torque) { cout<<"Manufacturer: " <<cars[0].name<<endl; cout<<"Horsepower: " <<cars[0].engine.horsepower<<endl; cout<<"Torque: " <<cars[0].engine.torque<<endl; } else { cout<<"Manufacturer: " <<cars[1].name<<endl; cout<<"Horsepower: " <<cars[1].engine.horsepower<<endl; cout<<"Torque: " <<cars[1].engine.torque<<endl; } }
Editor is loading...
Leave a Comment