From a0f0580c7dafef026be1593aa9dd53e508147df6 Mon Sep 17 00:00:00 2001 From: DoolyBoi Date: Wed, 2 Nov 2022 21:45:00 -0700 Subject: Did debugging exercises --- .../CST116-CH11-Debugging-Havaldar.cpp | 148 +++++++++++++++++++++ CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp | 148 --------------------- .../CST116-Ch11-Debugging.vcxproj | 6 +- .../CST116-Ch11-Debugging.vcxproj.filters | 6 +- 4 files changed, 158 insertions(+), 150 deletions(-) create mode 100644 CST116-Ch11-Debugging/CST116-CH11-Debugging-Havaldar.cpp delete mode 100644 CST116-Ch11-Debugging/CST116-Ch11-Debugging.cpp diff --git a/CST116-Ch11-Debugging/CST116-CH11-Debugging-Havaldar.cpp b/CST116-Ch11-Debugging/CST116-CH11-Debugging-Havaldar.cpp new file mode 100644 index 0000000..9ff09a4 --- /dev/null +++ b/CST116-Ch11-Debugging/CST116-CH11-Debugging-Havaldar.cpp @@ -0,0 +1,148 @@ +/******************************************************************** +* 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\\haval\\OneDrive\\Documents\\ch11OutputFile.txt"); + + inFile.open("C:\\Users\\haval\\OneDrive\\Documents\\ch11InputFile.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.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..a84f1d3 100644 --- a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj +++ b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj @@ -127,7 +127,11 @@ - + + + + + diff --git a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj.filters b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj.filters index 2029dc7..c7b9cf5 100644 --- a/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj.filters +++ b/CST116-Ch11-Debugging/CST116-Ch11-Debugging.vcxproj.filters @@ -15,8 +15,12 @@ - + Source Files + + + + \ No newline at end of file -- cgit v1.2.3