Saturday, May 22, 2010

Can someone help me with my C++ program?

Write a C++ program to read an arbitrary number of real numbers 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:





a. the number of strictly positive values read(greater than 0)


b. the number of strictly negative values read(less than 0)


c. the total number and average of values read


d. the largest and smallest values read


e. the percentages of the number of strictly negative values


and strictly positive values read.























#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;





using namespace std;





int main()


{


ifstream infile;


ofstream outfile;





char nam[15];


double n, sum = 0.0, mn, mx;


int total = 0, pv = 0, nv = 0;





infile.open("numbers.dat");


if (infile.fail()){


cerr %26lt;%26lt; "Can't open numbers.dat for input\n";


return 1;


}





infile %26gt;%26gt; n;


mn = mx = n;





cout %26lt;%26lt; "\n\n\tThe numbers in the input file are \n\tn";





{


cout %26lt;%26lt; n %26lt;%26lt; " ";





total++;


sum += n;





if( n %26lt; 0)


nv++;





if( n %26gt; 0)


pv++;





if( mn %26gt; n)


mn = n;





if( mx %26lt; n)


mx = n;


}while( (infile %26gt;%26gt; n) != NULL);





outfile.open("nc.out");


if (outfile.fail()){


cerr %26lt;%26lt; "Can't open nc.out for output\n";


return 2;


}





outfile %26lt;%26lt; "\n\n\tThe number of strictly positive values : " %26lt;%26lt; pv


%26lt;%26lt; "\n\tThe number of strictly negative values : " %26lt;%26lt; nv


%26lt;%26lt; "\n\tThe total number of values read : " %26lt;%26lt; total


%26lt;%26lt; "\n\tThe average of values read : " %26lt;%26lt; ( sum / total )


%26lt;%26lt; "\n\tThe largest of the values read : " %26lt;%26lt; mx


%26lt;%26lt; "\n\tThe smallest of the values read : " %26lt;%26lt; mn


%26lt;%26lt; "\n\tThe percentage of the number of strictly negative values : " %26lt;%26lt; ( ( nv * 100.0 ) / total )


%26lt;%26lt; "\n\tThe percentage of the number of strictly positive values : " %26lt;%26lt; ( ( pv * 100.0) / total );





cout %26lt;%26lt; "\n\n\t";





infile.close();


outfile.close();


return 0;

Can someone help me with my C++ program?
Email me the files (input files) you are working on.





kromped@yahoo.com
Reply:i wish i was that smart

paid survey

No comments:

Post a Comment