Untitled
gorazd
c_cpp
9 months ago
1.2 kB
10
Indexable
#include <cstring>
#include <iostream>
using namespace std;
struct Engine
{
int horsepower;
int torque;
};
struct car
{
char name[50];
int yearProd;
Engine engine;
};
void swap(car &a, car &b)
{
car temp;
temp = a;
a = b;
b = temp;
}
void printCars(car *cars,int n)
{
//bubble sort
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]);
}
}
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;
}
}
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;
}
printCars(cars,n);
}Editor is loading...
Leave a Comment