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

Problem #2 Write a C program that uses an array and reads up to 50 floating poin

ID: 651661 • Letter: P

Question

Problem #2

Write a C program that uses an array and reads up to 50 floating point values from the user and then calculates their average. In addition to calculating the average, the program will also compute the absolute deviation of each numerical quantity from the average using the formula: deviation = | xvaluei ? average |, where i= 1, 2, .., n

The program should use a while loop to, check the process of putting number in the array 2 times so that it is know that the quantity is variable up to 50 pieces of data, first 5 values are put in and next 7 values are put in. The output display of numbers should be with 2 decimal places. Use of the Math header file built-in functions is mandatory where applicable.

DO NOT USE <ISOSTREAM>, USE <STDIO.H> INSTEAD.

Sample Output: (heading information) How many numbers will be averaged? => 5 Values in set# 1 input # 1 --> value = 30.7 input # 2 --> value = -20.1 input # 3 --> value = 120.8 input # 4 --> value = 48.9 input # 5 --> value = 65 The average is 49.06 item # 1 value = 30.70 deviation = 18.36 item # 2 value = -20.10 deviation =69.16 item # 3 value = 120.80 deviation =71.74 item # 4 value = 48.90 deviation = 0.16 item # 5 value = 65.00 deviation = 15.94 How many numbers will be averaged? => 7 Values in set# 2 input # 1 --> value = 25.7 input # 2 --> value = 93.1 input # 3 --> value = -5.6 input # 4 --> value = 12.8 input # 5 --> value = 47.9 input # 6 --> value = -26.4 input # 7 --> value = 78.2 The average is 32.24 item # 1 value = 25.70 deviation = 6.54 item # 2 value = 93.10 deviation =60.86 item # 3 value = -5.60 deviation = 37.84 item # 4 value = 12.80 deviation = 19.44 item # 5 value = 47.90 deviation = 15.66 item # 6 value = -26.40 deviation = 5

Explanation / Answer

Hope this may helps you....


#include <iostream>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <fstream>
#include <stdio.h>

using namespace std;

main ()
{

while (inFile >> num)
{
  
   if (count3 == 0)
   {
       max = num;
       min = num;
   }
   if (num > max)
   {
       max = num;
   }
   if (num < min)
   {
       min = num;
   }
   count3++;
  
  
   sum += num;
   totSum += num;
   count1++;
   count2++;
}
  

  
  
   int main()
   {
       float Max, Min, num;
       int i;
       FILE *fi;
       FILE *fo;
       if ((fi = fopen("a3.txt")) == 0)
        {
           printf("error opening file ");
           return 1;
        }
      
       fscanf(fi, %f, & Max);
       Min = Max;
      
       for (i = 0; i < 8; i ++)
       {
           if (num > Max)
           {
               Max = num;
           }
           if (Temp < Min)
           {
               Min = num;
           }
       }
       fclose(fi);
       if ( (fo=fopen("a3.txt")) == NULL )
       {
           printf("ERROR opening file ");
           return 1;
       }
      
       cout << "The minimum value found is %f" << Min;
       cout << "The maximum = " << Max;
       fclose(fo);
       return 0;
      
   }
       system ("Pause");
       return 0;
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote