Question
Debugging slove #include #include #define SIZE 3 using namespace std; void getSpec(string caption, string *p_data) { cout < < caption; cin >> p_data; } void
Debugging slove
#include
using namespace std;
void getSpec(string caption, string *p_data) { cout << caption; cin >> p_data; }
void getSpec(string caption, int p_data) { cout << caption; cin >> *p_data; }
int fastestModel(string *m[], int *hp, int *w) { float whp_ratio, whp_ratio_lowest = 0; int idx; 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 << " "; } 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; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started