Question: #include #include #define SIZE 3 using namespace std; void getSpec(string caption, string *p_data) { cout < < caption; cin >> p_data; } void getSpec(string caption,
#include
cout << "Check weight and horsepower ratio: ";
for (int i = 0; i < SIZE; i++) { whp_ratio = (float)*w[i] / *hp[i]; cout << m[i] << " - " << whp_ratio << " ";
if (whp_ratio_lowest > whp_ratio) { whp_ratio = whp_ratio_lowest; idx = i; } }
cout << " ";
return idx; } // Start main function int main() { string *models [SIZE]; int *horsepower [SIZE]; int weight [SIZE];
// Examples of car's models, horse power and weight // Almera - 76 hp - 1035 Kg // City - 88 hp - 1110 Kg // Persona - 80 hp - 1210 Kg // Vios - 78 hp - 1112 Kg for (int i = 0; i < SIZE; i++) { models[i] = new string; getSpec("Car's model: ", models[i]);
horsepower[i] = new string; getSpec("Horsepower (hp): ", horsepower[i]);
getSpec("Weight (Kg): ", weight[i]); cout << " "; 4 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 }
int idx_fastest = fastestModel(models, horsepower, *weight);
cout << "Fastest car's model is " << *models[idx_fastest] << " with " << *horsepower[idx_fastest] << " horsepower and " << *weight[idx_fastest] << " kg of weight ";
// delete array data from memory for (int i = 0; i < SIZE; i++) { delete models[i]; delete horsepower[i]; delete weight[i]; }
return 0; }
debugging..
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
