-
Notifications
You must be signed in to change notification settings - Fork 0
/
outfile.cpp
44 lines (37 loc) · 1.01 KB
/
outfile.cpp
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
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char automobile[50];
int year;
double a_price;
double d_price;
//创建一个ofstream对象outFile
ofstream outFile;
//将该对象与一个文件关联起来。该文件是不存在的
outFile.open("carinfo.txt");
cout << "Enter the make and model of automobile: ";
cin.getline(automobile, 50);
cout << "Enter thr model year: ";
cin >> year;
cout << "Enter the original askng price: ";
cin >> a_price;
d_price = 0.913*a_price;
cout << fixed;
cout.precision(2);
cout.setf(ios_base::showpoint);
cout << "Make and model: " << automobile << endl;
cout << "Year: " << year << endl;
cout << "Was asking $" << a_price << endl;
cout << "Now asking $" << d_price << endl;
outFile << fixed;
outFile.precision(2);
outFile.setf(ios_base::showpoint);
outFile << "Make and model: " << automobile << endl;
outFile << "Year: " << year << endl;
outFile << "Was asking $" << a_price << endl;
outFile << "Now asking $" << d_price << endl;
outFile.close();
return 0;
}