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

This is a program in c++, I need help with it.beacuse the problem is about using

ID: 671488 • Letter: T

Question

This is a program in c++, I need help with it.beacuse the problem is about using input and outfile and I don't how to solve it. Write a program that will read integer values from an input file, and store those values in an rite a program that will read integer values from an input filc/and store those array called My Values". The program then will output the largest value and average value into an output file. You should write the following functions: ReadValues( Reads the integer values from input file into the array" int Findt-argestReturns largest value in the array */ int FindAvg/Returns the average value of all elements in the array/ eOutp L ) /. Write the largestvalue n the array and the average value i to output f e ) 7* Write the largest value in the array and the average value into output file .nchrole

Explanation / Answer

#include<iostream.h>
#include<fstream.h>

using namespace std;

class aa
{
public:
   int a[1000];
   int count;
void ReadValues()
{
   ifstream inf;
   inf.open("data.txt");
   int i=0;

   while(inf)
   {
       inf>>a[i];
       i++;
      
   }
   count=i;
   inf.close();
}

int FindLargest()
{
   int i=0,lar;
   lar=a[0];
  
   for(i=0;i<count-1;i++)
   {
       if(a[i]>lar)
       {
           lar=a[i];
       }
   }
   return lar;
}

int FindAvg()
{
   int i=0,av,sum=0;
  
  
   for(i=0;i<count-1;i++)
   {
       sum=sum+a[i];
   }
   av=sum/count;
   return av;
}

WriteOutput()
{
   ReadValues();
   cout<<"Largest="<<FindLargest();
   cout<<"Average = "<<FindAvg();
}
};
void main()
{
   aa o;
   o.WriteOutput();
}

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