1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
string FileName ;
ofstream fout ;
ifstream fin ;
int int1, int2, int3, int4, int5, int6, int7, int8, int9, int10, int11, int12, int13, int14, int15;
float sum, sum2, sumsquares, sum2squares, mean, deviation;
cout <<"Enter input file name and location: " ;
getline(cin, FileName);
fin.open(FileName.c_str());
while (fin.fail())
{
cout <<"Bad file name or location.\n" ;
fin.clear();
cout <<"Enter file name and location: " ;
getline(cin, FileName);
fin.open( FileName.c_str());
}
cout <<"Enter output file name and location: " ;
getline(cin, FileName);
fout.open(FileName.c_str());
if (fout.fail())
{
cout << "Bad file name.\n";
exit(0);
}
sum = int1 + int2 + int3 + int4 + int5;
sum2 = int6 + int7 + int8 + int9 + int10 + int11 + int12 + int13 + int14 + int15;
sumsquares = (sqrt(int1)) + (sqrt(int2)) + (sqrt(int3)) + (sqrt(int4)) + (sqrt(int5));
mean = sum; // divided by what?//
deviation = sqrt ( (sumsquares)); //divided by what?// - (pow *(mean,2));
fout <<"My first output file.\n" ;
fout << "input.txt" << endl;
cout << sum;
fout <<"Part 2 output file.\n" ;
fout << "input.txt" << endl ;
cout << sum2;
float i ;
fin >> i ; // initialize
fout << fixed << setprecision(3)<<showpoint << left;
while (!fin.eof()) // check end of file
{
fout << setw(10) <<i << setw(20) <<i*i << setw(20) << i*i*i <<endl ;
fin >> i ; // reset condition
}
fout.close();
return 0;
}
|