Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE FIX MY C++ CODE #include #include #include using namespace std; const int MAX_SIZE = 10; // Function to read names and weights from file

image text in transcribed

PLEASE FIX MY C++ CODE

#include #include #include

using namespace std;

const int MAX_SIZE = 10;

// Function to read names and weights from file int readData(string names[], int weightsInPounds[]); // Function to return pounds in kilograms float poundsToKilograms(int pounds); // Function to calculate and store weight in kilograms void calculateWeightInKilograms(int weightsInPounds[], float weightsInKilograms[], int size); // Function to print names and weights in a tabular format void printData(string names[], int weightsInPounds[], int size); // Function to calculate low, high and average weights void processData(int weightsInPounds[], int size, int &lowWeight, int &highWeight, float &averageWeight); // Function to print low, high and average weights void printProcessedData(int lowWeight, int highWeight, float averageWeight); // Function to sort data in ascending order by weight using bubble sort void sortData(string names[], int weightsInPounds[], int size);

int main() { // Declare arrays and variables string names[MAX_SIZE]; int weightsInPounds[MAX_SIZE]; int size = 0; int lowWeight, highWeight; float averageWeight;

size = readData(names, weightsInPounds); // Check if the arrays are empty if (size == 0) { return 0; } cout

// Function to read names and weights from file int readData(string names[], int weightsInPounds[]) { // Get filename from the user string filename; cin >> filename; // Open file ifstream inFile(filename); // Check if file opened successfully or not if (!inFile) { cin >> filename; cout > names[size]; if (inFile.eof()) break; inFile >> weightsInPounds[size]; size++; } // Close file inFile.close(); return size; }

// Function to return pounds in kilograms float poundsToKilograms(int pounds) { return pounds / 2.2; }

// Function to calculate and store weight in kilograms void calculateWeightInKilograms(int weightsInPounds[], float weightsInKilograms[], int size) { for (int i = 0; i

// Function to print names and weights in a tabular format void printData(string names[], int weightsInPounds[], int size) { // Calculate weight in kilograms float weightsInKilograms[MAX_SIZE]; calculateWeightInKilograms(weightsInPounds, weightsInKilograms, size); // Print names, weights in pounds and weights in kilograms cout

// Function to calculate low, high and average weights void processData(int weightsInPounds[], int size, int &lowWeight, int &highWeight, float &averageWeight) { lowWeight = highWeight = weightsInPounds[0]; int total = 0; for (int i = 0; i highWeight) { highWeight = weightsInPounds[i]; } total += weightsInPounds[i]; } averageWeight = (float)total / size; }

// Function to print low, high and average weights void printProcessedData(int lowWeight, int highWeight, float averageWeight) { cout

// Function to sort data in ascending order by weight using bubble sort void sortData(string names[], int weightsInPounds[], int size) { for (int i = 0; i weightsInPounds[j + 1]) { // Swap weightsInPounds int temp = weightsInPounds[j]; weightsInPounds[j] = weightsInPounds[j + 1]; weightsInPounds[j + 1] = temp; // Swap names string tempName = names[j]; names[j] = names[j + 1]; names[j + 1] = tempName; } } } }

image text in transcribed

Write a C++ program name manageweight.cpp to read a list of names and their weights in pounds, store them in 2 lists and process them based on the following requirements: - Write a function to prompt the user to enter a filename, read the list of integer numbers and names(1 name and weight per line) each corresponding to a person's weight in pounds and their name. Store all weights and names in 2 arrays. Assume there are no more than 10 elements (name and weight) in the file, but could be less. Make your array size 10. The function updates teh arrays and return the number of elements read from the file. File Format: Name Weight Sample file: \begin{tabular}{lr} Joe & \multicolumn{1}{c}{67} \\ Nancy & 123 \\ Allen & 234 \end{tabular} Requirements - Add a function to calculate and store the weights in kilograms in a float array, each kilogram is 2.2lbs. - Add a function to find the highest, lowest weight, and average of the weight and send them back to the caller. - Add a function to print the lists of names, weights. see sample below. - Add a function to sort lists (names and weights) based on weights from least heavy to heaviest weight. - Add the main function to call the functions and produce the following output. - Add main function to perform the following tasks: - Declare arrays and any variable you need - Call readData function - Call printData function - Call processData function (to find, high, low and average of weights - Print high, low and average (see format below) - Call sort function - Call printData function 1:Find average 0/30

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions