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

Number Counts-Programming Assignment Write a complete C++ program in stats . cc

ID: 3620353 • Letter: N

Question

Number Counts-Programming Assignment Write a complete C++ program in stats . cc to read an arbitrary number of real numbers (one value per input record) from a specified input file and write to a specified output file each of the values as they are read in and print with appropriate labels the following summary output (after all values have been individually read and processed ): the number of strictly positive values read (those greater than zero), the number of strictly negative values read (those less than zero), the total number and arithmetic mean (average) of values read. the largest and smallest values read. the percentages of the number of strictly negative values and strictly positives values read.

Explanation / Answer

please rate - thanks #include <iostream>
#include <fstream>
using namespace std;
int main()
{int pluses=0,minuses=0,num,sum=0,n=0,large,small;
double average,pp,pn;
char filename[30];
ifstream in;
ofstream out;
cout<<"Enter name of input file: ";
cin>>filename;
in.open(filename);      
if(in.fail())          
   { cout<<"input file did not open please check it ";
   system("pause");
   return 1;
   }
cout<<"Enter name of output file: ";
cin>>filename;
out.open(filename);       
in>>num;
small=num;
large=num;
while(in)
{       
if(num>0)
      {pluses++;
      out<<num<<" positive ";
      }
else
      {minuses++;
      out<<num<<" positive ";
      }
sum+=num;
if(num<small)
       small=num;
if(num>large)
       large=num;
n++;
in>>num;
}
average=sum/(double)n;
pp=pluses/(double)n*100.;
pn=minuses/(double)n*100.;
out<<"the number of positives is "<<pluses<<endl;
out<<"the number of negatives is "<<minuses<<endl;
out<<"the total is "<<sum<<endl;
out<<"the average is "<<average<<endl;
out<<"the largest is "<<large<<endl;
out<<"the smallest is "<<small<<endl;
out<<"the percentage positive is "<<pp<<endl;
out<<"the percentage negative is "<<pn<<endl;
out.close();
in.close();
return 0;
}