aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CST116F2021-Lab8/CST116F2021-Lab8.cpp237
-rw-r--r--CST116F2021-Lab8/CST116F2021-Lab8.vcxproj6
-rw-r--r--CST116F2021-Lab8/CST116F2021-Lab8.vcxproj.filters8
-rw-r--r--CST116F2021-Lab8/Chapter 11 Debug.cpp151
-rw-r--r--TextFile1.txt19
5 files changed, 411 insertions, 10 deletions
diff --git a/CST116F2021-Lab8/CST116F2021-Lab8.cpp b/CST116F2021-Lab8/CST116F2021-Lab8.cpp
index d4a77b8..b2a6d15 100644
--- a/CST116F2021-Lab8/CST116F2021-Lab8.cpp
+++ b/CST116F2021-Lab8/CST116F2021-Lab8.cpp
@@ -2,19 +2,236 @@
//
#include <iostream>
+#include <iomanip>
+#include <fstream>
+#include <string>
+
+using namespace std;
+
+const int RECORDS = 100;
+
+void getData(string[RECORDS][6], int);
+void calcData(string[RECORDS][6],string[RECORDS][9], int);
+void dispData(string[RECORDS][9], int);
int main()
{
- std::cout << "Hello World!\n";
+ string user_data[RECORDS][6]{};
+ string output_data[RECORDS][9]{};
+ int num_records = 0;
+
+ getData(user_data, num_records);
+ calcData(user_data, output_data, num_records);
+ dispData(output_data, num_records);
+
+ return 0;
}
-// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
-// Debug program: F5 or Debug > Start Debugging menu
+void getData(string inputArray[][6], int inputRecords)
+{
+ ifstream inFile;
+
+ inFile.open("C:\\TEMP\\336_data.txt");
+
+ if (inFile.is_open())
+ {
+ //cout << left;
+ //cout << setw(width) << "First Name" << setw(width) << "Last Name" << setw(width) << "SSN" << setw(width) << "Wage" << setw(width) << "Hours/Week" << setw(width) << "Work Status" << endl;
+ while (getline(inFile, inputArray[inputRecords][0], ' '))
+ {
+ cout << left;
+
+ getline(inFile, inputArray[inputRecords][1], ' ');
+ //cout << inputArray[inputRecords][1] << setw(width);
+ getline(inFile, inputArray[inputRecords][2], ' ');
+ //cout << inputArray[inputRecords][2] << setw(width);
+ getline(inFile, inputArray[inputRecords][3], ' ');
+ //cout << inputArray[inputRecords][3] << setw(width);
+ getline(inFile, inputArray[inputRecords][4], ' ');
+ //cout << inputArray[inputRecords][4] << setw(width);
+ getline(inFile, inputArray[inputRecords][5]);
+ //cout << inputArray[inputRecords][5];
+ inputRecords++;
+ }
+ }
-// 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
+ inFile.close();
+}
+
+void calcData(string calcArray[][6], string postcalcArray[][9], int calcRecords)
+{
+ float rate = 0.0;
+ float std_pay = 0.0;
+ float ot_pay = 0.0;
+ float net_pay = 0.0;
+ int hours = 0;
+
+ while (calcRecords < 11)
+ {
+ rate = stof(calcArray[calcRecords][3]);
+ hours = stoi(calcArray[calcRecords][4]);
+ if (calcArray[calcRecords][5] == "P")
+ {
+ std_pay = rate * hours;
+ net_pay = std_pay;
+ postcalcArray[calcRecords][7] = "Part Time";
+ }
+ else if (hours > 40 && calcArray[calcRecords][5] == "F")
+ {
+ std_pay = (40 * rate);
+ ot_pay = ((hours - 40) * (rate * 1.5));
+ net_pay = std_pay + ot_pay - 5;
+ postcalcArray[calcRecords][7] = "Full Time";
+ }
+ else
+ {
+ std_pay = rate * hours;
+ net_pay = std_pay - 5;
+ postcalcArray[calcRecords][7] = "Full Time";
+ }
+ postcalcArray[calcRecords][0] = calcArray[calcRecords][0];
+ postcalcArray[calcRecords][1] = calcArray[calcRecords][1];
+ postcalcArray[calcRecords][2] = calcArray[calcRecords][2];
+ postcalcArray[calcRecords][3] = calcArray[calcRecords][3];
+ postcalcArray[calcRecords][4] = calcArray[calcRecords][4];
+ postcalcArray[calcRecords][5] = to_string(std_pay);
+ postcalcArray[calcRecords][6] = to_string(ot_pay);
+ postcalcArray[calcRecords][8] = to_string(net_pay);
+ calcRecords++;
+ }
+}
+
+void dispData(string outputArray[][9], int outputRecords)
+{
+ int width = 20;
+
+ cout << left;
+ cout << setw(width) << "First Name" << setw(width) << "Last Name" << setw(width) << "SSN" << setw(width) << "Wage" << setw(width) << "Hours/Week" << setw(width) << "Straight Time Pay" << setw(width) << "Overtime Pay" << setw(width) << "Work Status" << setw(width) << "Net Pay" << endl;
+
+ while (outputRecords < 11)
+ {
+ cout << setw(width);
+ cout << outputArray[outputRecords][0] << setw(width);
+ cout << outputArray[outputRecords][1] << setw(width);
+ cout << outputArray[outputRecords][2] << setw(width);
+ cout << outputArray[outputRecords][3] << setw(width);
+ cout << outputArray[outputRecords][4] << setw(width);
+ cout << fixed << setprecision(2) << stof(outputArray[outputRecords][5]) << setw(width);
+ cout << fixed << setprecision(2) << stof(outputArray[outputRecords][6]) << setw(width);
+ cout << outputArray[outputRecords][7] << setw(width);
+ cout << fixed << setprecision(2) << stof(outputArray[outputRecords][8]);
+ cout << endl;
+ outputRecords++;
+ }
+}
+
+//p.323
+//#include <iostream>
+//#include <fstream>
+//
+//using namespace std;
+//
+//const int NUMBERS = 100;
+//
+//int main()
+//{
+// int num_values = 0;
+// int temp = 0;
+// float median = 0.0;
+// float values[NUMBERS]{};
+//
+// ifstream inFile;
+// inFile.open("C:\\TEMP\\323_values.txt");
+//
+// if (inFile.is_open())
+// {
+// inFile >> values[num_values];
+// cout << values[num_values] << endl;
+// while (!inFile.eof())
+// {
+// num_values++;
+// inFile >> values[num_values];
+// cout << values[num_values] << endl;
+// }
+// num_values++;
+//
+// temp = num_values % 2;
+//
+// if (temp)
+// {
+// median = values[(num_values) / 2];
+// }
+// else
+// {
+// median = (values[(num_values-1) / 2] + values[((num_values-1) / 2) + 1]) / 2;
+// }
+//
+// cout << "The median of this set of " << num_values << " is " << median << '.' << endl;
+// }
+// inFile.close();
+// return 0;
+//}
+
+
+
+
+//EXAMPLE
+//#include <iostream>
+//#include <fstream>
+//#include <string>
+//
+//using namespace std;
+//
+//const int RECORDS = 100;
+//const int MAX = 4;
+//
+//int main()
+//{
+// string record[RECORDS][MAX]{};
+// int num_records = 0;
+// char inChar[50];
+// string inString;
+//
+// FILE* inPtr;
+// ifstream inFile;
+// ofstream outFile;
+// outFile.open("C:\\TEMP\\Chap_11_Report.txt");
+// //r for read, w for write
+// fopen_s(&inPtr, "C:\\TEMP\\Chap_11_Data.txt", "r");
+// //inFile.open("C:\\TEMP\\Chap_11_Data.txt");
+//
+// if (/*inFile.is_open()*/ inPtr != NULL && outFile.is_open())
+// {
+// while (/*getline(inFile, record[num_records][0], ' ')*/ fscanf_s(inPtr, "%s", inChar, 50) >=0)
+// {
+// inString = inChar;
+// record[num_records][0] = inString;
+// cout << record[num_records][0];
+// outFile << record[num_records][0];
+// fscanf_s(inPtr, "%s", inChar, 50);
+// inString = inChar;
+// record[num_records][1] = inString;
+// //getline(inFile, record[num_records][1], ' ');
+// cout << record[num_records][1];
+// outFile << record[num_records][1];
+// fscanf_s(inPtr, "%s", inChar, 50);
+// inString = inChar;
+// record[num_records][2] = inString;
+// //getline(inFile, record[num_records][2], ' ');
+// cout << record[num_records][2];
+// outFile << record[num_records][2];
+// fscanf_s(inPtr, "%s", inChar, 50);
+// inString = inChar;
+// record[num_records][3] = inString;
+// //getline(inFile, record[num_records][3], ' ');
+// cout << record[num_records][3];
+// outFile << record[num_records][3];
+// num_records++;
+// }
+// }
+//
+//
+// inFile.close();
+// outFile.close();
+// return 0;
+//}
diff --git a/CST116F2021-Lab8/CST116F2021-Lab8.vcxproj b/CST116F2021-Lab8/CST116F2021-Lab8.vcxproj
index 00a34aa..999d665 100644
--- a/CST116F2021-Lab8/CST116F2021-Lab8.vcxproj
+++ b/CST116F2021-Lab8/CST116F2021-Lab8.vcxproj
@@ -139,8 +139,14 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClCompile Include="Chapter 11 Debug.cpp" />
<ClCompile Include="CST116F2021-Lab8.cpp" />
</ItemGroup>
+ <ItemGroup>
+ <Text Include="..\..\..\..\..\..\TEMP\336_Data.txt" />
+ <Text Include="..\..\..\..\..\..\TEMP\Chap_11_Debug.txt" />
+ <Text Include="..\..\..\..\..\..\TEMP\Chap_11_Report2.txt" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
diff --git a/CST116F2021-Lab8/CST116F2021-Lab8.vcxproj.filters b/CST116F2021-Lab8/CST116F2021-Lab8.vcxproj.filters
index b0158d2..c4d2a7f 100644
--- a/CST116F2021-Lab8/CST116F2021-Lab8.vcxproj.filters
+++ b/CST116F2021-Lab8/CST116F2021-Lab8.vcxproj.filters
@@ -18,5 +18,13 @@
<ClCompile Include="CST116F2021-Lab8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Chapter 11 Debug.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <Text Include="..\..\..\..\..\..\TEMP\Chap_11_Debug.txt" />
+ <Text Include="..\..\..\..\..\..\TEMP\Chap_11_Report2.txt" />
+ <Text Include="..\..\..\..\..\..\TEMP\336_Data.txt" />
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/CST116F2021-Lab8/Chapter 11 Debug.cpp b/CST116F2021-Lab8/Chapter 11 Debug.cpp
new file mode 100644
index 0000000..9d1ecf3
--- /dev/null
+++ b/CST116F2021-Lab8/Chapter 11 Debug.cpp
@@ -0,0 +1,151 @@
+/********************************************************************
+* 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 <iostream>
+//#include <fstream> // For the files!!!!
+//#include <iomanip> // 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:\\TEMP\\Chap_11_Report2.txt" );
+//
+// inFile.open ( "C:\\TEMP\\Chap_11_Debug.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 Output File";
+// cout << "\n\n\t\t ** About to EXIT NOW! ** ";
+// }
+// }
+// else
+// {
+// cout << "Trouble Opening Input File";
+// 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";
+//}
diff --git a/TextFile1.txt b/TextFile1.txt
new file mode 100644
index 0000000..d02b7c3
--- /dev/null
+++ b/TextFile1.txt
@@ -0,0 +1,19 @@
+p.317 #5
+a. if(input_file.is_open())
+{
+ ...
+}
+b. input_file >> lname[num_records] >> id[num_records] >> age;
+ while(!input_file.eof())
+ {
+ num_records++;
+ input_file >> lname[num_records] >> id[num_records] >> age;
+ }
+c. input_file.close();
+
+#6
+a. False
+b. True
+c. True
+d. True
+e. True \ No newline at end of file