Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THIS A C++ PROGRAM Write a program that asks the user for a file name, and then

ID: 3838970 • Letter: T

Question

THIS A C++ PROGRAM

Write a program that asks the user for a file name, and then ask the user for up to 100 input values. Write the user input values to the file. Then read the contents of the file back into an array, and then display the following data:

lowest number

highest number

total of the numbers

average of the numbers

Write the array back to a NEW file, in reverse order. Call this file reverse.txt.

Provide a "sentinel value" to allow the user to stop entering numbers. (if i only want 5 numbers, i should only have to enter 5 numbers, but if i want to enter 100, then i should be able to enter 100.)

Once you have the program working, create functions that calculate each of the items above. Your function should take an array and the size of the array as input, and return the value calculated.So you should have a function that finds the minimum, a different function that finds the maximum, another function that gets the total.

I have the code here but the problem is that it always gives me 0 for the min value.

can you please coorect the code for me!?

#include
#include
#include
using namespace std;

int minArray(int[], int);
int maxArray(int[], int);
int totlaArray(int[], int);
double averageArray(double, int);

int main()
{
   const int SIZE = 100;
   int upToHundred[SIZE],
       reverse[SIZE];
   int inputValue = 0;
   string fileName;
   ofstream outpuFile1, outpuFile2;


   // Ask the user for a file name
   cout << "Enter a file name: ";
   cin >> fileName;

   cout << "Now a file is created called "" << fileName << "", and will contain the numbers that you enter. ";
   // Create the file
   outpuFile1.open(fileName);

   // Ask the user for up to 100 input values
   cout << " You can enter up to 100 number. Please e nter '-' if you want to stop entering numbers: ";
   int count = 0;                       // Holds how many numbers that are entered

                                       // The user can keep entering the numbers until -1
                                       // Read the numbers into an array
   while (inputValue != -1 && count < SIZE)
   {
       cin >> inputValue;
       upToHundred[count] = inputValue;
       count++;
   }

   // Write the input values into the file
   for (int i = 0; i < count; i++)
   {
       outpuFile1 << upToHundred[i] << endl;
   }

   // Close the file
   outpuFile1.close();

   // Write the array back into a new array, in reverse
   outpuFile2.open("reverse.txt");

   for (int i = 0; i < count; i++)
   {
       reverse[i] = upToHundred[count - i - 1];
       outpuFile2 << reverse[i] << endl;
   }

   // Close the file
   outpuFile2.close();

   // Calculate and display the lowest and highest number, the total and the average of all the numbers
   int lowest = 0,
       highest = 0;
   double total = 0,
       average = 0;

   lowest = minArray(upToHundred, count);
   highest = maxArray(upToHundred, count);
   total = totlaArray(upToHundred, count);
   average = averageArray(total, count);

   system("pause");
   return 0;
}

int minArray(int nums[], int size)
{
   int min = 0;
   for (int i = 0; i < size; i++)
       if (nums[i] < min) min = nums[i];
   cout << "The lowest value is: " << min << endl;
   return min;
}

int maxArray(int nums[], int size)
{
   int max = 0;
   for (int i = 0; i < size; i++)
       if (nums[i] > max) max = nums[i];
   cout << "The highest value is: " << max << endl;
   return max;
}

int totlaArray(int nums[], int size)
{
   int sum = 0;
   for (int i = 0; i < size; i++)
       sum += nums[i];
   cout << "The total is: " << sum << endl;
   return sum;
}

double averageArray(double num1, int num2)
{
   double avr = 0;
   avr = num1 / num2;
   cout << "The average is: " << avr << endl;
   return avr;
}

Explanation / Answer


using namespace std;

MYSQL sql,*conn;
MYSQL_RESULT result;
MYSQL_ROW r;

char * iIp = (char*)"194.168.49.131";
char * usEr = (char*)"root";
char * pass = (char*)"adminS";
char * dbS = (char*)"vScs";

int Level_state;

int main (int argc, char **argv)
{
   mysql_init(&mysql);

   connection = mysql_real_connect(&mysql, ip, usr, pass, db, 0, NULL, 0);

   if (connection==NULL)
   {
       cout<<mysql_error(&mysql)<<endl;
   }