-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWrite-data-to-file-engine.cpp
More file actions
executable file
·58 lines (46 loc) · 1.38 KB
/
Write-data-to-file-engine.cpp
File metadata and controls
executable file
·58 lines (46 loc) · 1.38 KB
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
//CSC 160 Project 2 Grade C
//Purpose: Write data to a file
//Author: Larsen J Close Most recent changes: 4/27/16
#include <iostream> // preprocessor directive
#include <iomanip> // needed for most manipulators
#include <fstream> // needed for ofstream
using namespace std; // using directive
int main ( void )
{
double data, speed, torque;
ofstream out_stream;
out_stream.open("engine_01.dat");
if(out_stream.fail())
{
cout << "Failed to open file 'engine_01.dat'\n";
exit(1);
}
cout << "Please enter the data to be written to file 'engine_01.dat'...\n";
cout << " Engine Speed Torque\n";
cout << " (rpm) (lb ft)" << endl;
for (int x = 0; x <9 ; x++)
{
cin >> speed;
out_stream << setw(20) << left << speed;
cin >> torque;
out_stream << setw(20) << right << torque << endl;
}
out_stream.close();
system ("pause");
return 0;
} //end main ( )
/* Output for this program:
Please enter the data to be written to file 'engine_01.dat'...
Engine Speed Torque
(rpm) (lb ft)
1000 294.3
1500 355.8
2000 381.2
2500 388.3
3000 381.5
3500 367.4
4000 342.4
4500 309.0
5000 260.2
Press any key to continue . . .
*/