From 97f55faef5d4e7a6844de89216077dce8c12ca3c Mon Sep 17 00:00:00 2001 From: Lloyd Crawford Date: Wed, 9 Nov 2022 16:38:01 -0800 Subject: Here is my completed CH11 Debugging. --- CH_11_Data_LC.txt | 10 ++ CH_11_Report.txt | 15 ++ CST116-CH11Debugging-Output-Crawford.txt | 20 +++ CST116-Ch11-Debugging.sln | 2 +- .../CST116-Ch11-Debugging-Crawford.cpp | 155 +++++++++++++++++++++ CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp | 148 -------------------- .../CST116-Ch11-Debugging.vcxproj | 6 +- .../CST116-Ch11-Debugging.vcxproj.filters | 5 +- .../~AutoRecover.CST116-Ch11-Debugging.vcxproj | 136 ++++++++++++++++++ .../~AutoRecover.CST116-Ch11-Debugging.vcxproj2 | 139 ++++++++++++++++++ CST116-Ch11-debugging-Pseudocode-Crawford.txt | 134 ++++++++++++++++++ 11 files changed, 619 insertions(+), 151 deletions(-) create mode 100644 CH_11_Data_LC.txt create mode 100644 CH_11_Report.txt create mode 100644 CST116-CH11Debugging-Output-Crawford.txt create mode 100644 CST116-Ch11-Debugging/CST116-Ch11-Debugging-Crawford.cpp delete mode 100644 CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp create mode 100644 CST116-Ch11-Debugging/~AutoRecover.CST116-Ch11-Debugging.vcxproj create mode 100644 CST116-Ch11-Debugging/~AutoRecover.CST116-Ch11-Debugging.vcxproj2 create mode 100644 CST116-Ch11-debugging-Pseudocode-Crawford.txt diff --git a/CH_11_Data_LC.txt b/CH_11_Data_LC.txt new file mode 100644 index 0000000..5595a0d --- /dev/null +++ b/CH_11_Data_LC.txt @@ -0,0 +1,10 @@ +Vincent 24 +Johnny 81 +Hector 45 +Ranni 89 +Radahn 90 +DrLivesly 45 +Powerwolf 10 +Iggy 23 +Bertrum 15 +Goofy 99 \ No newline at end of file diff --git a/CH_11_Report.txt b/CH_11_Report.txt new file mode 100644 index 0000000..6438727 --- /dev/null +++ b/CH_11_Report.txt @@ -0,0 +1,15 @@ + Here is the Output File +Vincent 24 +Johnny 81 +Hector 45 +Ranni 89 +Radahn 90 +DrLivesly 45 +Powerwolf 10 +Iggy 23 +Bertrum 15 +Goofy 99 + + + ** Total Records: 10 ** + The End diff --git a/CST116-CH11Debugging-Output-Crawford.txt b/CST116-CH11Debugging-Output-Crawford.txt new file mode 100644 index 0000000..f453fb9 --- /dev/null +++ b/CST116-CH11Debugging-Output-Crawford.txt @@ -0,0 +1,20 @@ +Output + +Vincent 24 +Johnny 81 +Hector 45 +Ranni 89 +Radahn 90 +DrLivesly 45 +Powerwolf 10 +Iggy 23 +Bertrum 15 +Goofy 99 + + + ** Total Records: 10 ** + The End + +C:\Users\Lloyd Crawford\source\repos\cst116-ch11-debugging-19-Ruin\x64\Debug\CST116-Ch11-Debugging-Crawford.exe (process 22772) 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 . . . diff --git a/CST116-Ch11-Debugging.sln b/CST116-Ch11-Debugging.sln index f71ac42..57d8906 100644 --- a/CST116-Ch11-Debugging.sln +++ b/CST116-Ch11-Debugging.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32929.385 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CST116-Ch11-Debugging", "CST116-Ch11-Debugging\CST116-Ch11-Debugging.vcxproj", "{2F33289E-7D00-4EC4-9951-F3DB9CD7C178}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CST116-Ch11-Debugging-Crawford", "CST116-Ch11-Debugging\CST116-Ch11-Debugging.vcxproj", "{2F33289E-7D00-4EC4-9951-F3DB9CD7C178}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/CST116-Ch11-Debugging/CST116-Ch11-Debugging-Crawford.cpp b/CST116-Ch11-Debugging/CST116-Ch11-Debugging-Crawford.cpp new file mode 100644 index 0000000..623683f --- /dev/null +++ b/CST116-Ch11-Debugging/CST116-Ch11-Debugging-Crawford.cpp @@ -0,0 +1,155 @@ +/******************************************************************** +* File: Chapter 11 Debug.cpp +* Lloyd Crawford, CST 116 02, Chapter 11 Debug, Github + +* 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. Wont run program as path is not established. +* 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!!!! // lol stream......good thing its not a pstream ^o^ . +#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\\Lloyd Crawford\\source\\repos\\cst116-ch11-debugging-19-Ruin\\CH_11_Report.txt"); + + inFile.open("C:\\Users\\Lloyd Crawford\\source\\repos\\cst116-ch11-debugging-19-Ruin\\CH_11_Data_LC.txt"); + // double slash has to be used in all file in or out. If you use a single slach bad things happen. + 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 File"; + cout << "\n\n\t\t ** About to EXIT NOW! ** "; + } + } + else + { + cout << "Trouble Opening 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]; + } + // next segment is for reading and priming the file. + cout << setiosflags(ios::left) << setw(25) + << name[counter] << resetiosflags(ios::left) + << setw(4) << age[counter] << endl; + counter++; + inFile >> name[counter] >> age[counter]; + + 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++) // femove the = here to stop the report from adding wierd coding to your solution and your file. nasty bug. + { + 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 << " **\n" + << "\t\t The End \n"; + + // To file + outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; +} diff --git a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp deleted file mode 100644 index 53830da..0000000 --- a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************** -* 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:\\TEMP\\Chap_11_Report.txt"); - - inFile.open("C:\\TEMP\\Chap_11_data.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 File"; - cout << "\n\n\t\t ** About to EXIT NOW! ** "; - } - } - else - { - cout << "Trouble Opening 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]; - } - - 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 << " **\n" - << "\t\t The End \n"; - - // To file - outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" - << "\t\t The End \n"; -} diff --git a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj index 2073e5b..1c5380a 100644 --- a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj +++ b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj @@ -24,6 +24,7 @@ {2f33289e-7d00-4ec4-9951-f3db9cd7c178} CST116Ch11Debugging 10.0 + CST116-Ch11-Debugging-Crawford @@ -127,7 +128,10 @@ - + + + + diff --git a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj.filters b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj.filters index 2029dc7..42b6d8a 100644 --- a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj.filters +++ b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj.filters @@ -15,8 +15,11 @@ - + Source Files + + + \ No newline at end of file diff --git a/CST116-Ch11-Debugging/~AutoRecover.CST116-Ch11-Debugging.vcxproj b/CST116-Ch11-Debugging/~AutoRecover.CST116-Ch11-Debugging.vcxproj new file mode 100644 index 0000000..b00994d --- /dev/null +++ b/CST116-Ch11-Debugging/~AutoRecover.CST116-Ch11-Debugging.vcxproj @@ -0,0 +1,136 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {2f33289e-7d00-4ec4-9951-f3db9cd7c178} + CST116Ch11Debugging + 10.0 + CST116-Ch11-Debugging-Crawford + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/CST116-Ch11-Debugging/~AutoRecover.CST116-Ch11-Debugging.vcxproj2 b/CST116-Ch11-Debugging/~AutoRecover.CST116-Ch11-Debugging.vcxproj2 new file mode 100644 index 0000000..c502ba8 --- /dev/null +++ b/CST116-Ch11-Debugging/~AutoRecover.CST116-Ch11-Debugging.vcxproj2 @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {2f33289e-7d00-4ec4-9951-f3db9cd7c178} + CST116Ch11Debugging + 10.0 + CST116-Ch11-Debugging-Crawford + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/CST116-Ch11-debugging-Pseudocode-Crawford.txt b/CST116-Ch11-debugging-Pseudocode-Crawford.txt new file mode 100644 index 0000000..fec69e4 --- /dev/null +++ b/CST116-Ch11-debugging-Pseudocode-Crawford.txt @@ -0,0 +1,134 @@ +Ch 11 Debug Pseudocode + + +Wrote own file & named it CH_11_Data_LC.txt +Replaced location of older file with new file location and name of file. +Had to debug own coding for a new file location as I had made my input my output +causing it to write over my input. Found errors in the code and fixed them. +Duplicated the while loop to be outside of the while and inside. +Changed <= to < on line 137 + In part 2 if you change the input from double slash to single slash it will cause the program to fail. + double slash is always a requirement. + Changing and tampering with input and output placements causes error coding. Best way is to copy the address of the file you use by going + to the files properties and copying it's address. + + #include +#include // For the files!!!! // lol stream......good thing its not a pstream ^o^ . +#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\\Lloyd Crawford\\source\\repos\\cst116-ch11-debugging-19-Ruin\\CH_11_Report.txt"); + + inFile.open("C:\\Users\\Lloyd Crawford\\source\\repos\\cst116-ch11-debugging-19-Ruin\\CH_11_Data_LC.txt"); + // double slash has to be used in all file in or out. If you use a single slach bad things happen. + 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 File"; + cout << "\n\n\t\t ** About to EXIT NOW! ** "; + } + } + else + { + cout << "Trouble Opening 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]; + } + // next segment is for reading and priming the file. + cout << setiosflags(ios::left) << setw(25) + << name[counter] << resetiosflags(ios::left) + << setw(4) << age[counter] << endl; + counter++; + inFile >> name[counter] >> age[counter]; + + 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++) // femove the = here to stop the report from adding wierd coding to your solution and your file. nasty bug. + { + 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 << " **\n" + << "\t\t The End \n"; + + // To file + outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" + << "\t\t The End \n"; + + Felt like I learned in this lesson and once I found how to do it, it felt like it went quick. + output + Vincent 24 +Johnny 81 +Hector 45 +Ranni 89 +Radahn 90 +DrLivesly 45 +Powerwolf 10 +Iggy 23 +Bertrum 15 +Goofy 99 + + + ** Total Records: 10 ** + The End + +C:\Users\Lloyd Crawford\source\repos\cst116-ch11-debugging-19-Ruin\x64\Debug\CST116-Ch11-Debugging-Crawford.exe (process 18708) 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 . . . -- cgit v1.2.3