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
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
//Main Program
int main()
{
ifstream inFile;
ofstream outputFile;
double curr1, curr2, curr3, curr4, curr5;
double power1, power2, power3, power4, power5;
double resistance[5] = { 16, 27, 39, 56, 81 }; // Array of size 5
outputFile.open("C:\\current.txt");
if (!outputFile)
{
cout << "Unable to create file current.txt\n";
return 1;
}
cout << "Please enter 5 integer values for the current." << endl;
cin >> curr1 >> curr2 >> curr3 >> curr4 >> curr5;
// Ask the user to enter 5 valuse write on the file
outputFile << curr1 << endl;
outputFile << curr2 << endl;
outputFile << curr3 << endl;
outputFile << curr4 << endl;
outputFile << curr5 << endl;
// Close the file
outputFile.close();
cout << "Done.\n";
// We will open the file here
inFile.open("C:\\current.txt");
// Read the integers from the user input from the created file
// And store them in the variables
inFile >> curr1;
inFile >> curr2;
inFile >> curr3;
inFile >> curr4;
inFile >> curr5;
// Output of the table.
cout << endl
<< endl
<< "Resistance" << setw(12) << "Current" << setw(14) << "Power"
<< endl
<< "-------------------------------------"
<< endl;
// This will do the calculations for each power for each current
power1 = resistance[0] * pow(curr1, 2);
power2 = resistance[1] * pow(curr2, 2);
power3 = resistance[2] * pow(curr3, 2);
power4 = resistance[3] * pow(curr4, 2);
power5 = resistance[4] * pow(curr5, 2);
// Here we will display the totals in table form.
cout << setw(7) << resistance[0] << setw(12) << curr1 << setw(16) << power1 << endl;
cout << setw(7) << resistance[1] << setw(12) << curr2 << setw(16) << power2 << endl;
cout << setw(7) << resistance[2] << setw(12) << curr3 << setw(16) << power3 << endl;
cout << setw(7) << resistance[3] << setw(12) << curr4 << setw(16) << power4 << endl;
cout << setw(7) << resistance[4] << setw(12) << curr5 << setw(16) << power5 << endl;
system("pause");
return 0;
}
|