-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
89 lines (87 loc) · 2.43 KB
/
Copy pathSource.cpp
File metadata and controls
89 lines (87 loc) · 2.43 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
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
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
while (true)
{
setlocale(LC_ALL, "ukr");
cout << "Ïîêàçàòè äàíi - íàòèñíiòü 1" << endl;
cout << "Çàïèñàòè äàíi - íàòèñíiòü 2" << endl;
cout << "Âèõiä - íàòèñíiòü 3" << endl;
int choice;
cin >> choice;
if (choice == 1)
{
string name;
int number;
int prise;
int tCost;
ifstream infile;
infile.open("File.txt");
if (!infile)
{
cout << "Íå ìîæíà âiäêðèòè ôàéë" << endl;
return -1;
}
cout << setw(9) << "Íàçâà" << setw(13) << "Êiëüêiñòü" << setw(6) << "Öiíà" << setw(8) << "Ñóìà" << endl;
while (!infile.eof())
{
infile >> name;
infile >> number;
infile >> prise;
infile >> tCost;
if (!infile.eof())
{
cout.width(9);
cout << name;
cout.width(9);
cout << number;
cout.width(9);
cout << prise;
cout.width(9);
cout << tCost;
cout << endl;
}
}
infile.close();
}
if (choice == 2)
{
string name;
int number;
int cost;
int tcost;
cout << "Íàçâà: ";
cin >> name;
cout << "Êiëüêiñòü: ";
cin >> number;
cout << "Öiíà: ";
cin >> cost;
tcost = number * cost;
fstream outfile("File.txt", ios::app);
if (!outfile)
{
cout << "Íå ìîæíà âiäêðèòè ôàéë" << endl;
return -1;
}
outfile.setf(ios::left);
outfile.width(9);
outfile << name << ' ';
outfile.width(9);
outfile << number << ' ';
outfile.width(9);
outfile << cost << ' ';
outfile.width(9);
outfile << tcost << endl;
outfile.close();
}
if (choice == 3)
{
break;
}
}
system("pause");
}