From 7571a2b5485977736560b02bcd2bbc93759b2809 Mon Sep 17 00:00:00 2001 From: Joseph Ten Eyck Date: Tue, 23 Nov 2021 23:54:19 -0800 Subject: Joseph Ten Eyck - Lab 8 --- CST116F2021-Lab8/CST116F2021-Lab8.cpp | 378 +++++++++++++++++++++++++++++++++- Data File 2.txt | 11 + Data File.txt | 6 + Data Report 2.txt | 0 Data Report.txt | 11 + RUNS.txt | 185 +++++++++++++++++ dta Report.txt | 0 7 files changed, 580 insertions(+), 11 deletions(-) create mode 100644 Data File 2.txt create mode 100644 Data File.txt create mode 100644 Data Report 2.txt create mode 100644 Data Report.txt create mode 100644 RUNS.txt create mode 100644 dta Report.txt diff --git a/CST116F2021-Lab8/CST116F2021-Lab8.cpp b/CST116F2021-Lab8/CST116F2021-Lab8.cpp index d4a77b8..d7607a5 100644 --- a/CST116F2021-Lab8/CST116F2021-Lab8.cpp +++ b/CST116F2021-Lab8/CST116F2021-Lab8.cpp @@ -1,20 +1,376 @@ -// CST116F2021-Lab8.cpp : This file contains the 'main' function. Program execution begins and ends there. +//////////////////////////////////////////////// +// ANSWERS TO PROBLEM #5 ON PAGE 317 ARE BELOW +//////////////////////////////////////////////// + + +// 5 a. Necessary statement to check to make sure a file is open: +// fileName.is_open + +// 5 b. Necessary statement to read and display all information contained within the space delimited +// file declared above: +// +// string readStr; +// +// if (fileName.is_open()) +// { +// while (!fileName.eof()) +// { +// getline(fileName, readStr, ' '); +// cout << readStr; +// } +// } + +// 5 c. Necessary statment to close file: +// fileName.close + +// 6 a. FALSE +// 6 b. TRUE +// 6 c. TRUE +// 6 d. TRUE +// 6 e. TRUE + + +////////////////////////////////////////////////////////////// +// CODE FOR PROBLEM #1 (LEARN BY DOING) ON PAGE 323 IS BELOW +////////////////////////////////////////////////////////////// + +//#include +//#include +// +//using namespace std; +// +//const int MAX_VALUES{ 25 }; +// +//void getValues(int[], int&); //gets user input list of integers +//void calcMedian(int[], int); //finds and displays median of list of integers +// +//int main() +//{ +// int values[MAX_VALUES]; +// int num_values = 0; +// +// getValues(values, num_values); //gets user input list of integers +// calcMedian(values, num_values); //finds and displays median of list of integers +// +//} +// +// +//void getValues(int values[], int& num_values) //gets user input list of integers +//{ +// char cont = 'y'; +// +// cout << "\n\t\tEnter up to 25 integers, smallest to greatest\n"; // +// do +// { +// cout << "\n\tInteger " << num_values + 1 << " : "; +// cin >> values[num_values]; +// +// num_values++; +// +// cout << "\n\tEnter another? (y/n): "; +// cin >> cont; +// +// } while (num_values < MAX_VALUES + 1 && cont == 'y'); +//} +// +//void calcMedian(int values[], int num_values) //finds and displays median of list of integers +//{ +// if (num_values % 2 == 1) //if number of values in list is odd +// { +// int middle1 = (num_values / 2) + 0.5; +// +// cout << "\n\t\tThe median is " << values[middle1] << endl; +// } +// else //if number of values is even +// { +// int middle2 = (num_values / 2) - 1; //left middle number index +// int middle3 = (num_values / 2); //right middle number index +// float middleValue = ((values[middle2] + values[middle3]) / 2) + 0.5; //median value between the two middle numbers +// +// cout << "\n\t\tThe median is " << middleValue << endl; +// } +//} + + +///////////////////////////////////////////////////// +// CODE FOR DEBUGGING EXERCISE ON PAGE 333 IS BELOW +///////////////////////////////////////////////////// + +/******************************************************************** +* File: Chapter 11 Debug.cpp +* +* General Instructions: Complete each step before proceeding to the +* next. +* +* Debugging Exercise 1 +* +* 1) Make your own data file like Troy 12, with the next person on the +* next line and save it to a directory you create on your drive. +* 2) Under the Project menu, select Add Existing Item and +* add the input file you just placed on your drive to your +* current project. Make sure your Solution Explorer window +* is visible. If not, you can display it by selecting Solution +* Explorer (or Ctrl+Alt+L). +* 3) Open the input file by simply double clicking the name of the +* file in your Solution Explorer. +* 4) Build and execute the program. +* 5) Update the file paths below to correctly represent the path you +* created. +* 6) Rebuild and execute the program. +* 7) Examine the code and the output and notice the use of +* parallel arrays. +* 8) Add the output file created via the execution of +* your program to your Project. Execute your program again +* and notice how Visual Studio has rewritten your output file +* and asks if you would like to reload the file (select Yes). +* 9) Examine the contents of both the input and the output file. +* 10) Fix all the problems in your code that exist in relation to +* the output. Verify that your output is appropriate for your + input file. +* 11) Build and execute your code until you have all errors +* removed and all the output is correct. +* +* Debugging Exercise 2 +* +* 1) Replace the double slashes (\\) in the input file open statement +* with only a single slash +* (i.e., inFile.open("C:\TEMP\Chap_11_data.txt"). +* 2) Build your code, noticing the impact of the invalid path you +* created in the previous step. +* 3) Replace the backslashes as they were. +* 4) Change both the input and output filenames so they are +* invalid. +* 5) Update the file related error messages within the code +* to also provide the specific name of the file that is having a +* problem. +* 6) Rebuild and execute your program to verify that your messages +* are correct. +* 7) Correct the path names. +* 8) Build and execute your code and carefully check your +* output on both the console and in the output file. +* +********************************************************************/ +//#include +//#include // For the files!!!! +//#include // For manipulators & formatting options +//using std::cin; +//using std::cout; +//using std::endl; +//using std::setw; +//using std::ios; +// +//using std::ifstream; +//using std::ofstream; +// +//const int EMPLOYEES = 20; +//const int MAX = 21; +// +//int ReadData(ifstream& inFile, ofstream& outFile, char name[][MAX], int age[]); +//void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[], +// int counter); +//void PrintTotalsAndSummary(ofstream& out, int totalRecords); +// +//int main() +//{ +// char name[EMPLOYEES][MAX]; +// int age[EMPLOYEES]; +// int record_counter(0); +// +// ifstream inFile; +// +// // Notice how this automatically opens the file +// ofstream outFile("C:\\Users\\eclip\\source\\repos\\cst115-lab8-JosephTenEyck\\Data Report.txt"); +// +// inFile.open("C:\\Users\\eclip\\source\\repos\\cst115-lab8-JosephTenEyck\\Data File.txt"); +// +// if (inFile.is_open()) +// { +// record_counter = ReadData(inFile, outFile, name, age); +// inFile.close(); +// +// if (outFile.is_open()) +// { +// WriteOutputFile(outFile, name, age, record_counter); +// PrintTotalsAndSummary(outFile, record_counter); +// outFile.close(); +// } +// else +// { +// cout << "Trouble Opening 'Data Report.txt'"; +// cout << "\n\n\t\t ** About to EXIT NOW! ** "; +// } +// } +// else +// { +// cout << "Trouble Opening 'Data File.txt'"; +// cout << "\n\n\t\t ** About to EXIT NOW! ** "; +// } +// return 0; +//} +//int ReadData(ifstream& inFile, ofstream& outFile, char name[][MAX], int age[]) +//{ +// int counter = 0; +// inFile >> name[counter] >> age[counter]; // Priming Read +// +// while (!inFile.eof()) +// { +// cout << setiosflags(ios::left) << setw(25) +// << name[counter] << resetiosflags(ios::left) +// << setw(4) << age[counter] << endl; +// counter++; +// inFile >> name[counter] >> age[counter]; +// } +// +// cout << setiosflags(ios::left) << setw(25) +// << name[counter] << resetiosflags(ios::left) +// << setw(4) << age[counter] << endl; +// +// return counter; +//} +//void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[], int counter) +//{ +// outFile << " Here is the Output File" << endl; +// for (int r = 0; r <= counter; r++) +// { +// outFile << setiosflags(ios::left) << setw(25) +// << name[r] << setw(4) +// << resetiosflags(ios::left) << age[r] +// << endl; +// } +//} +//void PrintTotalsAndSummary(ofstream& outFile, int totalRecords) +//{ +// // To screen +// cout << "\n\n\t** Total Records: " << totalRecords + 1 << " **\n" +// << "\t\t The End \n"; +// +// // To file +// outFile << "\n\n\t** Total Records: " << totalRecords + 1 << " **\n" +// << "\t\t The End \n"; +//} + + + +/////////////////////////////////////////////////////////////////// +// CODE FOR PROBLEM #1 PROGRAMMING EXERCISES ON PAGE 336 IS BELOW +/////////////////////////////////////////////////////////////////// #include +#include +#include + +using namespace std; + +const int NUM_EMPLOYEES = 11; +const int MAX = 21; + +void readData(ifstream& inFile, char[][MAX], char[][MAX], char[][MAX], float[], int[], char[]); //reads input file into arrays +void calcPay(float[], int[], char[], float[], float[], float[]); //calculates pay information +void displayInfo(char[][MAX], char[][MAX], char[][MAX], float[], int[], char[], float[], float[], float[]); //displays all information in an organized fashion int main() { - std::cout << "Hello World!\n"; + //input arrays from file + char firstName[NUM_EMPLOYEES][MAX]; + char lastName[NUM_EMPLOYEES][MAX]; + char ssNum[NUM_EMPLOYEES][MAX]; + float baseWage[NUM_EMPLOYEES]; + int hoursWorked[NUM_EMPLOYEES]; + char status[NUM_EMPLOYEES]; + + //calculated arrays + float straightPay[NUM_EMPLOYEES]; + float overTimePay[NUM_EMPLOYEES]; + float netPay[NUM_EMPLOYEES]; + + + ifstream inFile; //delares input file + + ofstream outFile("C:\\Users\\eclip\\source\\repos\\cst115-lab8-JosephTenEyck\\Data Report 2.txt"); //declares output file and opens it + + inFile.open("C:\\Users\\eclip\\source\\repos\\cst115-lab8-JosephTenEyck\\Data File 2.txt"); //opens input file + + + if (inFile.is_open()) + { + readData(inFile, firstName, lastName, ssNum, baseWage, hoursWorked, status); //reads input file into arrays + inFile.close(); + } + + calcPay(baseWage, hoursWorked, status, straightPay, overTimePay, netPay); //calculates pay information + + displayInfo(firstName, lastName, ssNum, baseWage, hoursWorked, status, straightPay, overTimePay, netPay); //displays all information in an organized fashion + + return 0; } -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu +void readData(ifstream& inFile, char firstName[][MAX], char lastName[][MAX], char ssNum[][MAX], float baseWage[], int hoursWorked[], char status[]) //reads input file into arrays +{ + int record_count = 0; + + inFile >> firstName[record_count] >> lastName[record_count] >> ssNum[record_count] + >> baseWage[record_count] >> hoursWorked[record_count] >> status[record_count]; //priming read + + while (!inFile.eof()) + { + record_count++; + + inFile >> firstName[record_count] >> lastName[record_count] >> ssNum[record_count] + >> baseWage[record_count] >> hoursWorked[record_count] >> status[record_count]; //inputs the rest of the file into the arrays + } +} + +void calcPay(float baseWage[], int hoursWorked[], char status[], float straightPay[], float overTimePay[], float netPay[]) //calculates pay information +{ + int hoursOver = 0; + float actualWage = 0; + + for (int i = 0; i < NUM_EMPLOYEES; i++) + { + if (status[i] == 'F') //check for full-time status + { + actualWage = baseWage[i] - 5; + } + else + { + actualWage = baseWage[i]; + } + + if (hoursWorked[i] > 40) //if overtime worked + { + hoursOver = hoursWorked[i] - 40; + + straightPay[i] = (40 * actualWage); + overTimePay[i] = (hoursOver * (3/2) * actualWage); + netPay[i] = straightPay[i] + overTimePay[i]; + } + else //overtime not worked + { + straightPay[i] = (hoursWorked[i] * actualWage); + overTimePay[i] = 0; + netPay[i] = straightPay[i]; + } + } +} + +void displayInfo(char firstName[][MAX], char lastName[][MAX], char ssNum[][MAX], float baseWage[], int hoursWorked[], + char status[], float straightPay[], float overTimePay[], float netPay[]) //displays all information in an organized fashion +{ + cout << "\n\t\t========================"; + cout << "\n\t\t EMPLOYEE INFORMATION"; + cout << "\n\t\t========================"; + + cout << "\n\n Base Hours Full/Part Straight Over "; + cout << "\nName SS# Wage Worked Time Time Pay Time Pay Net Pay"; + cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; + + for (int i = 0; i < NUM_EMPLOYEES; i++) //includes specific name spacing for this specific data + { + cout << setw(7) << left << firstName[i] << " " << setw(13) << left << lastName[i] << setw(15) << left << ssNum[i] + << "$" << setw(5) << left << baseWage[i] << " " << setw(8) << left << hoursWorked[i] << setw(11) << left << status[i] + << "$" << setw(11) << left << straightPay[i] << "$" << setw(11) << left << overTimePay[i] << "$" << setw(11) << left << netPay[i] << endl; -// Tips for Getting Started: -// 1. Use the Solution Explorer window to add/manage files -// 2. Use the Team Explorer window to connect to source control -// 3. Use the Output window to see build output and other messages -// 4. Use the Error List window to view errors -// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project -// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file + //cout << setw(7) << left << firstName[i]; + } +} \ No newline at end of file diff --git a/Data File 2.txt b/Data File 2.txt new file mode 100644 index 0000000..582d470 --- /dev/null +++ b/Data File 2.txt @@ -0,0 +1,11 @@ +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 \ No newline at end of file diff --git a/Data File.txt b/Data File.txt new file mode 100644 index 0000000..b4f149e --- /dev/null +++ b/Data File.txt @@ -0,0 +1,6 @@ +David 24 +Melissa 25 +Flunker 99 +John 19 +Terry 20 +Jill 22 \ No newline at end of file diff --git a/Data Report 2.txt b/Data Report 2.txt new file mode 100644 index 0000000..e69de29 diff --git a/Data Report.txt b/Data Report.txt new file mode 100644 index 0000000..6cb6628 --- /dev/null +++ b/Data Report.txt @@ -0,0 +1,11 @@ + Here is the Output File +David 24 +Melissa 25 +Flunker 99 +John 19 +Terry 20 +Jill 22 + + + ** Total Records: 6 ** + The End diff --git a/RUNS.txt b/RUNS.txt new file mode 100644 index 0000000..6e0ac21 --- /dev/null +++ b/RUNS.txt @@ -0,0 +1,185 @@ +//////////////////////////////////////////////////////////// + RUNS FOR PROBLEM #1 LEARN BY DOING ON PAGE 323 ARE BELOW +//////////////////////////////////////////////////////////// + + + Enter up to 25 integers + + Integer 1 : 5 + + Enter another? (y/n): y + + Integer 2 : 6 + + Enter another? (y/n): y + + Integer 3 : 7 + + Enter another? (y/n): y + + Integer 4 : 8 + + Enter another? (y/n): n + + The median is 6.5 + +C:\Users\eclip\source\repos\lab 8 temp\Debug\lab 8 temp.exe (process 13772) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + + Enter up to 25 integers + + Integer 1 : 8 + + Enter another? (y/n): y + + Integer 2 : 9 + + Enter another? (y/n): y + + Integer 3 : 10 + + Enter another? (y/n): y + + Integer 4 : 11 + + Enter another? (y/n): y + + Integer 5 : 12 + + Enter another? (y/n): n + + The median is 10 + +C:\Users\eclip\source\repos\lab 8 temp\Debug\lab 8 temp.exe (process 14304) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + + + Enter up to 25 integers, smallest to greatest + + Integer 1 : 1 + + Enter another? (y/n): y + + Integer 2 : 3 + + Enter another? (y/n): y + + Integer 3 : 11 + + Enter another? (y/n): y + + Integer 4 : 16 + + Enter another? (y/n): y + + Integer 5 : 18 + + Enter another? (y/n): y + + Integer 6 : 20 + + Enter another? (y/n): n + + The median is 13.5 + +C:\Users\eclip\source\repos\lab 8 temp\Debug\lab 8 temp.exe (process 11024) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + +////////////////////////////////////////////////////// +// RUNS FOR DEBUGGING EXERCISE ON PAGE 333 ARE BELOW +////////////////////////////////////////////////////// + +//EXERCISE 1 + +Trouble Opening File + + ** About to EXIT NOW! ** +C:\Users\eclip\Source\Repos\cst115-lab8-JosephTenEyck\Debug\CST116F2021-Lab8.exe (process 10236) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + +David 24 +Melissa 25 +Flunker 99 +John 19 +Terry 20 + + + ** Total Records: 5 ** + The End + +C:\Users\eclip\Source\Repos\cst115-lab8-JosephTenEyck\Debug\CST116F2021-Lab8.exe (process 18304) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + +David 24 +Melissa 25 +Flunker 99 +John 19 +Terry 20 +Jill 22 + + + ** Total Records: 6 ** + The End + +C:\Users\eclip\Source\Repos\cst115-lab8-JosephTenEyck\Debug\CST116F2021-Lab8.exe (process 10692) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + +//EXERCISE 2 + +Trouble Opening File + + ** About to EXIT NOW! ** +C:\Users\eclip\Source\Repos\cst115-lab8-JosephTenEyck\Debug\CST116F2021-Lab8.exe (process 16168) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + + +Trouble Opening 'dta File.txt' + + ** About to EXIT NOW! ** +C:\Users\eclip\Source\Repos\cst115-lab8-JosephTenEyck\Debug\CST116F2021-Lab8.exe (process 3240) exited with code 0. +To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. +Press any key to close this window . . . + + +////////////////////////////////////////////////////////////////// +// RUN FOR PROBLEM #1 PROGRAMMING EXERCISES ON PAGE 336 IS BELOW +////////////////////////////////////////////////////////////////// + + ======================== + EMPLOYEE INFORMATION + ======================== + + Base Hours Full/Part Straight Over +Name SS# Wage Worked Time Time Pay Time Pay Net Pay +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +John Smith 123-09-8765 $9 46 F $160 $24 $184 +Molly Brown 432-89-7654 $9.5 40 F $180 $0 $180 +Tim Wheeler 239-34-3458 $11.25 83 F $250 $268.75 $518.75 +Keil Wader 762-84-6543 $6.5 35 P $227.5 $0 $227.5 +Trish Dish 798-65-9844 $7.52 40 P $300.8 $0 $300.8 +Anthony Lei 934-43-9843 $9.5 56 F $180 $72 $252 +Kevin Ashes 765-94-7343 $4.5 30 P $135 $0 $135 +Cheryl Prince 983-54-9000 $4.65 45 F $-14 $-1.75 $-15.75 +Kim Cares 343-11-2222 $10 52 F $200 $60 $260 +Dave Cockroach 356-98-1236 $5.75 48 F $30 $6 $36 +Will Kusick 232-45-2322 $15 45 P $600 $75 $675 diff --git a/dta Report.txt b/dta Report.txt new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3