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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
CST 116 Austin Guertin
13a 11.7 pg 317 #5-6 (Statements for 5, Judgements for 6)
5)
.cpp
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
const int RECORDS = 100;
const int MAX = 4;
int main()
{
string records[RECORDS];
int num_records = 0;
//Open the file
ifstream inFile;
ofstream outFile;
inFile.open("C:\\TEMP\\13a_number5_data.txt");
outFile.open("C:\\TEMP\\13a_number5_report.txt");
//Check to see if file is open (a)
if (inFile.is_open() && outFile.is_open())
{
cout << "\n\n";
// Read until end of file is reached
while (!inFile.eof())
{
//Priming read (b)
getline(inFile, records[num_records], ' ');
cout << records[num_records];
outFile << records[num_records];
num_records++;
}
cout << "\n\n\n\n";
//close the file (c)
inFile.close();
}
else
{
cout << "ERROR: This file could not be opened for some reason\n\n";
return num_records;
}
}
13a_number5_data - Notepad
lname1, id1, age
lname2, id2, age
lname3, id3, age
lname4, id4, age
lname5, id5, age
lname6, id6, age
13a_number5_report - Notepad
lname1,id1,age
lname2,id2,age
lname3,id3,age
lname4,id4,age
lname5,id5,age
lname6,id6,age
6)
a. False
b. False
c. True
d. True
e. True
13b 11.9 pg 323 #1 (Write a full program to call the function)
.cpp
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream input;
double lineValue[100];
double median;
int count = 1;
input.open("C:\\TEMP\\median.txt");
if (input.fail()) {
cout << "Input file opening failed. \n";
exit(1);
}
while (count < 100 && input >> lineValue[count]) {
count++;
}
count = count - 1;
if ((count % 2) == 0) {
count = count / 2;
median = ((lineValue[count + 1] + lineValue[count]) / 2);
}
else {
count = ((count - 1) / 2) + 1;
median = lineValue[count];
}
cout << "The median is " << median << "." << endl;
return 0;
}
median.txt
2
4
8
16
32
64
13c 11.13 pg 333-336
11.14 pg 336-337 #1
.cpp
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
//This is the main function
int main()
{
//Opening the "workers" file for reading
fstream fin("C:\\TEMP\\workers.txt", ios::in);
string fname, lname, ssn;
double wage, straightTimePay, OTPay, netPay;
int hoursWorked, actualHours, OTHours;
char status;
//Printing neat header
cout << "\n\n " << left << setw(18) << "Name" << left << setw(20) << "SSN";
cout << left << setw(8) << "Wage" << left << setw(18) << "Hours Worked" << left << setw(10) << "Status";
cout << left << setw(20) << "Straight time Pay" << left << setw(15) << "OT Pay" << left << setw(15) << "Net Pay";
//Loop till entire data is read
while (fin.good())
{
//Reading data into its respective variables
fin >> fname >> lname >> ssn >> wage >> hoursWorked >> status;
//calculating if there are any OT hours
if (hoursWorked > 40)
{
//Splitting the hours
actualHours = 40;
OTHours = hoursWorked - 40;
}
else
{
actualHours = hoursWorked;
OTHours = 0;
}
//Calculating employee straight time pay
straightTimePay = actualHours * wage;
//Calculating employee OT pay
OTPay = OTHours * 1.5 * wage;
//Calculating employee Net pay
netPay = straightTimePay + OTPay;
//determining if person is full time employee
if (status == 'F')
//Deducting the union fee
netPay = netPay - 5;
//Printing the record from "workers"
cout << "\n\n " << left << setw(8) << fname << left << setw(10) << lname << left << setw(21) << ssn;
cout << left << setw(12) << wage << left << setw(14) << hoursWorked << left << setw(15) << status;
cout << left << setw(15) << straightTimePay << left << setw(15) << OTPay << left << setw(10) << netPay;
}
//Closing file
fin.close();
cout << endl << endl;
return 0;
}
workers.txt
John Smith 123-09-8765 9.00 46 F
Molly Brown 432-89-7654 9.50 40 F
Tim Wheeler 239-34-3458 11.25 83 F
Keil Wader 762-84-6543 6.50 35 P
Trish Dish 798-65-9844 7.52 40 P
Anthony Lei 934-43-9843 9.50 56 F
Kevin Ashes 765-94-7343 4.50 30 P
Cheryl Prince 983-54-9000 4.65 45 F
Kim Cares 343-11-2222 10.00 52 F
Dave Cockroach 356-98-1236 5.75 48 F
Will Kusick 232-45-2322 15.00 45 P
|