-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex09.cpp
69 lines (57 loc) · 1.38 KB
/
ex09.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
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
#include <iostream>
#include <string>
#include <fstream>
struct patrons
{
std::string name;
double contribution;
};
int main()
{
int records = 0;
int noPatrons = 0;
int noGrandPatrons = 0;
const int SIZE = 60;
char filename[SIZE];
std::ifstream inFile;
std::cout << "Enter name of data file: ";
std::cin.getline(filename, SIZE);
inFile.open(filename);
if(!inFile.is_open())
{
std::cout << "Could not open the file " << filename << std::endl;
std::cout << "Program terminating.\n";
exit(EXIT_FAILURE);
}
(inFile >> records).get();
patrons *list = new patrons[records];
for (int i = 0; i < records; i++)
{
std::getline(inFile, list[i].name);
(inFile >> list[i].contribution).get();
}
std::cout << "\nGrand Patrons\n";
for (int i = 0; i < records; i++)
{
if (list[i].contribution >= 10000)
{
std::cout << list[i].name << std::endl;
noGrandPatrons++;
}
}
if (noGrandPatrons == 0)
std::cout << "none\n";
std::cout << "\nPatrons\n";
for (int i = 0; i < records; i++)
{
if (list[i].contribution < 10000)
{
std::cout << list[i].name << std::endl;
noPatrons++;
}
}
if (noPatrons == 0)
std::cout << "none\n";
delete [] list;
return 0;
}