diff options
| -rw-r--r-- | CST116F2021-Lab8/CST116F2021-Lab8.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/CST116F2021-Lab8/CST116F2021-Lab8.cpp b/CST116F2021-Lab8/CST116F2021-Lab8.cpp index 2bf5681..7061264 100644 --- a/CST116F2021-Lab8/CST116F2021-Lab8.cpp +++ b/CST116F2021-Lab8/CST116F2021-Lab8.cpp @@ -74,10 +74,65 @@ 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 @@ -85,3 +140,88 @@ lname6,id6,age 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 |