The professor is correct on all issues, if you would have compiled and run the program you should have found most of these problems since the output of the program is not the output you said it should produce.
So do you see what is wrong with the nested loops in your pounds and kilogram functions?
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void kilogram(int a[], int& numUsed, double k[])
{
for(int i = 0; i < numUsed; i++)// for loop that will do the kilo gram
{
int temp = 0;
temp = a[i];
for(int j = 0; j < numUsed; j++)
{
k[j] = temp;
cout << k[j] << endl;
}
}
}
|
IMO the name of this function could be clearer, and the name of the parameters should be more descriptive. There is no need for any temp variable, and really this function should be doing the conversion, not the display function. By the way did your instructor tell you why the formula is incorrect? I'd do something like:
1 2 3 4 5 6 7
|
void convert_to_kilograms(const int ounces[], int numUsed, double kilograms[])
{
for(int i = 0; i < numUsed; i++)
{
kilograms[i] = ounces[i] * .0283495;
}
}
|
Note I prefer using multiplication over division because the multiplication is quite often faster than division. And note that the use of the const keyword.
call calculation functions before displaying result; |
Very true, you should be calling these functions before you try to display the results otherwise you will get undefined values.
wrong number format for output; |
Very true, you stated that there must be four decimal places, so you should be using some of the manipulators to set the width, precision, and to insure the decimal point is always shown.
you had to overload a display method that one use integers and the other use doubles |
Again this is correct. You should have overloaded your display function to properly handle the different arrays. Your code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
void display(int a[], int&numUsed, double p[], double k[])
{
cout << "Original list in Ounces:\n";
for(int i = 0; i < numUsed; i++) //loop will display the output ounces
{
cout << a[i] << endl;
}
cout << "Values in pounds:\n";
for(int i = 0; i < numUsed; i++)//loop will display the output pounds
{
cout << p[i] / 16 << endl;// the conversion display
}
cout << "Values in Kilograms:\n";
for(int i = 0; i < numUsed; i++)//loop will display the output for kilogram
{
cout << k[i] / 35.27396195 << endl; // the conversion display
}
}
|
IMO, this code has too much duplicate code and the calculations should be done in the "calculation" functions not the display function. The display function should only be displaying the values held in the arrays, not doing the calculations.
IMO, you could print the messages and call a slightly different display() function to display the individual arrays. However you could also create two more overloaded display functions and still use this function something like:
1 2 3 4 5 6 7 8 9
|
void display(const int ounces[], int numUsed, const double pounds[], const double kilograms[])
{
cout << "Original list in Ounces:\n";
display(ounces, numUsed);
cout << "Values in pounds:\n";
display(pounds, numUsed);
cout << "Values in Kilograms:\n";
display(kilograms, numUsed);
}
|
And for actually displaying the arrays something like:
1 2 3 4 5 6
|
void display(const int array[], int numUsed)
{
for(int i = 0; i < numUsed; ++i)
cout << setw(10) << array[i] << " ";
cout << endl;
}
|
I'll leave you the task of properly coding the following function to properly display the values:
1 2 3 4
|
void display(const double array[], int numUsed)
{
}
|
In this function you'll need to use manipulators to set the precision and to insure the decimal point is always displayed.
The overload of your getInfo() is really not needed, better to have two different functions with meaningful names, and remember that first call is not using the array so you really shouldn't be passing the array into that function.