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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <iostream>
#include <fstream>
#include <cmath>
//Function Program
using namespace std;
double add(double, double);
double sub(double, double);
double powers(double, double);
double Largest(double, double);
double Smallest(double, double);
double total(double, double);
int main()
{
ofstream outfile;
outfile.open("DATA.txt");
double num1, num2, num3, num4, tot, dif1, dif2, large, small, tot1, tot2, runtot;
long double pow1, pow2;
cout << "Enter 4 numbers" << endl;
cin >> num1 >> num2 >> num3 >> num4;
outfile << "Numbers used = " << num1 << " " << num2 << " " << num3 << " " << num4 << endl;
tot = add(add(num1, num2), add(num3, num4));
outfile << "The sum of the four numbers is = " << tot << endl;
dif1 = sub(num1, num2);
dif2 = sub(num3, num4);
outfile << "Difference between the first two numbers = " << dif1 << endl;
outfile << "Difference between the last two numbers = " << dif2 << endl;
pow1 = powers(num1, num2);
pow2 = powers(num4, num3);
outfile << "The first number raised to the second number power = " << pow1 << endl;
outfile << "The last number raised to the third number power = " << pow2 << endl;
large = Largest(Largest(num1, num2),Largest(num3, num4));
outfile << "The largest number = " << large << endl;
small = Smallest(Smallest(num1, num2),Smallest(num3, num4));
outfile << "The smallest number = " << small << endl;
tot1 = total(num1, num2);
outfile << "Running total = " << tot1;
tot2 = total(tot1, num3);
outfile << ", " << tot2;
runtot = total(tot2, num4);
outfile << ", " << runtot << endl;
outfile.close();
return 0;
}
double add(double a, double b)
{
double sum;
sum = a + b;
return sum;
}
double sub(double y, double z)
{
if (y > z)
{
double diff = y - z;
return diff;
}
else
{
double diff = z - y;
return diff;
}
}
double powers(double j, double k)
{
double power;
power = pow(j,k);
return power;
}
double Largest(double m, double n)
{
double larger;
if (m > n)
{
larger = m;
return larger;
}
else
{
larger = n;
return larger;
}
}
double Smallest(double o, double p)
{
double smaller;
if (o < p)
{
smaller = o;
return smaller;
}
else
{
smaller = p;
return smaller;
}
}
double total(double g, double h)
{
double tot;
tot = g + h;
return tot;
}
|