-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.cpp
More file actions
108 lines (106 loc) · 2.78 KB
/
6.cpp
File metadata and controls
108 lines (106 loc) · 2.78 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <fstream>
using namespace std;
void GetOrders(int ord, int pr);
string name[10];
int orders[10];
int prices1[10];
int main()
{
int option;
cout << "Press 1 To Enter Data & 2 To Check Result:......";
cin >> option;
if (option == 1)
{
for (int i = 0; i < 10; i++)
{
int option;
cout << "Enter The Customer: ";
cin >> name[i];
cout << "Enter Total Orders: ";
cin >> orders[i];
for (int j = 0; j < orders[i]; j++)
{
cout << "Enter The " << j + 1 << " Order Price: ";
cin >> prices1[j];
}
fstream file;
file.open("customer.txt", ios::app);
file << name[i] << " " << orders[i] << " [";
for (int k = 0; k < orders[i]; k++)
{
if (k < orders[i] - 1)
{
file << prices1[k] << ",";
}
else if (k == orders[i] - 1)
{
file << prices1[k] << "]" << endl;
break;
}
}
cout << "Press 1 To Enter More Data & Go Back:......";
cin >> option;
if (option == 1)
{
continue;
}
if (option == 2)
{
break;
}
}
}
if (option == 2)
{
int ord, pr;
cout << "Enter The Total Orders You Want To Check: ";
cin >> ord;
cout << "Enter The Max Price: ";
cin >> pr;
GetOrders(ord, pr);
}
return 0;
}
void GetOrders(int ord, int pr)
{
int idx = 0;
string line;
fstream file;
string prices[1000];
file.open("customer.txt", ios::in);
while (!file.eof())
{
string orders2[100], name, order3;
int order4;
file >> name >> order4 >> order3;
int length = sizeof(order3) / sizeof(order3[0]);
if (idx == 0)
{
fstream newfile;
newfile.open("1stcustomer.txt",ios::out);
for (int i = 1; i < length; i++)
{
if (order3[i] != ']')
{
newfile << order3[i];
}
}
newfile.close();
}
if (idx == 1)
{
fstream newfile;
newfile.open("2ndcustomer.txt",ios::out);
for (int i = 1; i < length; i++)
{
if (order3[i] != ']')
{
newfile << order3[i];
}
}
newfile.close();
}
idx = 1;
}
}