diff options
| author | Joseph Ten Eyck <[email protected]> | 2021-11-10 23:59:32 -0800 |
|---|---|---|
| committer | Joseph Ten Eyck <[email protected]> | 2021-11-10 23:59:32 -0800 |
| commit | 602385edd1cfb892e27e2a85c03f2dd1910308de (patch) | |
| tree | 02ab8065b57250917c82038495a7934f8b8f4dc0 | |
| parent | Add online IDE url (diff) | |
| download | cst116-lab6-josephteneyck-602385edd1cfb892e27e2a85c03f2dd1910308de.tar.xz cst116-lab6-josephteneyck-602385edd1cfb892e27e2a85c03f2dd1910308de.zip | |
Last problem is giving me trouble. I am pushing what I have before midnight so I have something to turn in by then.
| -rw-r--r-- | CST116F2021-Lab6/CST116F2021-Lab6 - Joseph Ten Eyck.cpp | 199 | ||||
| -rw-r--r-- | CST116F2021-Lab6/CST116F2021-Lab6.cpp | 20 | ||||
| -rw-r--r-- | CST116F2021-Lab6/CST116F2021-Lab6.vcxproj | 6 | ||||
| -rw-r--r-- | CST116F2021-Lab6/CST116F2021-Lab6.vcxproj.filters | 10 | ||||
| -rw-r--r-- | CST116F2021-Lab6/Functions.cpp | 163 | ||||
| -rw-r--r-- | CST116F2021-Lab6/Header.h | 35 | ||||
| -rw-r--r-- | RUNS.txt | 255 |
7 files changed, 666 insertions, 22 deletions
diff --git a/CST116F2021-Lab6/CST116F2021-Lab6 - Joseph Ten Eyck.cpp b/CST116F2021-Lab6/CST116F2021-Lab6 - Joseph Ten Eyck.cpp new file mode 100644 index 0000000..06a47cf --- /dev/null +++ b/CST116F2021-Lab6/CST116F2021-Lab6 - Joseph Ten Eyck.cpp @@ -0,0 +1,199 @@ +//============================================================= +// CODE FOR PROBLEM #1 ON PAGE 282 (LEARN BY DOING) IS BELOW +//============================================================= + +//#include "Header.h" +// +//int main() +//{ +// string club_name[10][31]; +// string club_pres[10][31]; +// int num_stud[10]; +// float money[10]; +// +// readData(club_name, club_pres, num_stud, money); //Takes in user entered data and writes to arrays +// +// displayData(club_name, club_pres, num_stud, money); // Displays the data from the arrays in an orderly fashion +// +//} + + + +//============================================================= +// CODE FOR DEBUGGING EXERCISE ON PAGE 289-292 IS BELOW +//============================================================= + + +/******************************************************************** +* File: Chapter 10 Debug.cpp +* +* General Instructions: Complete each step before proceeding to the +* next. +* +* Debugging Exercise 1 +* +* 1) Build and run the program. +* 2) Examine the code and the output and notice the use of +* parallel arrays. +* 3) Insert breakpoints at Breakpoint 1, Breakpoint 2, and Breakpoint +* 3. +* 4) Run to Breakpoint 1. +* 5) Place a watch on varX, varY and varZ. Click on the '+' in the +* watch window to see the individual elements associated with each +* of the arrays. +* 6) Continue running your program to Breakpoint 2. +* 7) Add a watch on the array called name. Again, click on the '+' +* symbol. Notice how a multidimensional array is shown in the +* debugger, the null terminating characters location, and how a +* character is represented within each element of the array. +* 8) Continue running the program to Breakpoint 3. +* 9) Notice the contents of varX and varY now that you are back in the +* main function. +* 10) Clear all the breakpoints. +* 11) Stop debugging. +* +* Debugging Exercise 2 +* +* 1) Change the constant SIZE from 5 to 10. +* 2) Change any literal containing a 5 to the constant SIZE. +* Notice the usefulness of the constant when changes need +* to be made to your code. +* 3) Set a breakpoint at Breakpoint 4. Now on this breakpoint +* set the necessary condition so the loop breaks when x hits 8. +* (Hint: If you need help setting breakpoints based upon a +* condition refer to Chapter 8). +* 4) Run to Breakpoint 4. +* 5) Continue stepping into the remainder of the for loop until the +* flow returns back to main. +* 6) Make sure your Watch window is visible and notice the contents +* of varY and varZ now that you are back in main. +* 7) Stop debugging. +* 8) Disable all breakpoints. +* 9) Rebuild and execute the program and verify the results. +* +* Debugging Exercise 3 +* +* 1) Just before the call to the PrintFunction in main, add an +* assignment statement to change the first element in the +* array varZ to -99. +* 2) Build and execute your code, verifying that the calculations +* are correct in relation to element 0 of varZ. +* 3) Add a line to assign the contents of the second element of +* varX to 99 in FunctionTwo. +* 4) Rebuild your program. +* 5 Obviously there is a problem. Remove the const from the +* function declaration and header for varX. +* 5) Now you should be able to build and execute your code. Do it. +* 6) Set a breakpoint on Breakpoint 2. +* 7) Re-enable Breakpoint 2. +* 8) Run to Breakpoint 2 and make sure you have a watch on the +* variable name. +* 9) Click on the '+'. Once you see all the elements +* within the array, change the 'Value' (in the Value field) +* for the first element of the array directly within the Watch +* window to the character 'Z'. Notice how the value is updated +* by displaying the new ASCII value too. +* 10) Stop debugging. +* 11) Disable all breakpoints. +* +********************************************************************/ +//#include <iostream> +//#include <iomanip> +//using std::cin; +//using std::cout; +//using std::endl; +//using std::setw; +// +//void GetAndDisplayWelcomeInfo(); +//void FunctionOne(int varX[], int varY[]); +//void FunctionTwo(int varX[], const int varY[], int varZ[]); +//void PrintFunction(const int varX[], const int varY[], +// const int varZ[]); +// +//const int SIZE = 10; +// +//int main() +//{ +// int varX[SIZE]; +// int varY[SIZE]; +// int varZ[SIZE]; // Notice how we used the const here! +// +//// Breakpoint 1 +// // Put breakpoint on the following line +// GetAndDisplayWelcomeInfo(); +// FunctionOne(varX, varY); +// +// // Breakpoint 3 +// // Put breakpoint on the following line +// FunctionTwo(varX, varY, varZ); +// +// varZ[0] = -99; +// +// PrintFunction(varX, varY, varZ); +// +// return 0; +//} +//void GetAndDisplayWelcomeInfo() +//{ +// char name[2][20]; // First name in row 0, last name in row 1 +// +// cout << "Please enter your first name: "; +// cin >> name[0]; +// +// cout << "\nPlease enter your last name: "; +// cin >> name[1]; +// +// // Breakpoint 2 +// // Put breakpoint on the following line +// cout << "\n\n\tWelcome " << name[0] << " " << name[1] +// << "!\n\t Hope all is well \n\n"; +//} +//void FunctionOne(int varX[], int varY[]) +//{ +// for (int x = 0; x < SIZE; x++) // NOTICE '<' NOT <= +// // Breakpoint 4 +// // Put breakpoint on the following line +// varX[x] = x; +// +// for (int x = 0; x < SIZE; x++) +// varY[x] = x + 100; +//} +//void FunctionTwo(int varX[], const int varY[], int varZ[]) +//{ +// varX[1] = 99; +// +// for (int x = 0; x < SIZE; x++) // Notice the const SIZE here +// varZ[x] = varX[x] + varY[x]; +//} +//void PrintFunction(const int varX[20], const int varY[20], +// const int varZ[20]) +//{ +// int x; +// +// cout << " \t x \t y \t z\n\n"; +// +// for (x = 0; x < SIZE; x++) +// cout << "\t" << setw(3) << varX[x] +// << "\t " << varY[x] +// << "\t " << varZ[x] << endl; +//} + + +//==================================================================== +// CODE FOR PROBLEM #1 ON PAGE 292 (PROGRAMMING EXERCISES) IS BELOW +//==================================================================== + + +#include "Header.h" + +int main() +{ + int menu_choice = 0; + + do + { + displayMenu(menu_choice); //Displays menu choices and takes in user choice + + processMenuChoice(menu_choice); //Process menu choice, calls relevant function + } while (menu_choice != 4); +}
\ No newline at end of file diff --git a/CST116F2021-Lab6/CST116F2021-Lab6.cpp b/CST116F2021-Lab6/CST116F2021-Lab6.cpp deleted file mode 100644 index 466d90f..0000000 --- a/CST116F2021-Lab6/CST116F2021-Lab6.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// CST116F2021-Lab6.cpp : This file contains the 'main' function. Program execution begins and ends there. -// - -#include <iostream> - -int main() -{ - std::cout << "Hello World!\n"; -} - -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu - -// 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 diff --git a/CST116F2021-Lab6/CST116F2021-Lab6.vcxproj b/CST116F2021-Lab6/CST116F2021-Lab6.vcxproj index 756680b..7fa7e6d 100644 --- a/CST116F2021-Lab6/CST116F2021-Lab6.vcxproj +++ b/CST116F2021-Lab6/CST116F2021-Lab6.vcxproj @@ -139,7 +139,11 @@ </Link> </ItemDefinitionGroup> <ItemGroup> - <ClCompile Include="CST116F2021-Lab6.cpp" /> + <ClCompile Include="CST116F2021-Lab6 - Joseph Ten Eyck.cpp" /> + <ClCompile Include="Functions.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="Header.h" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/CST116F2021-Lab6/CST116F2021-Lab6.vcxproj.filters b/CST116F2021-Lab6/CST116F2021-Lab6.vcxproj.filters index afbfcf4..ffeaa0d 100644 --- a/CST116F2021-Lab6/CST116F2021-Lab6.vcxproj.filters +++ b/CST116F2021-Lab6/CST116F2021-Lab6.vcxproj.filters @@ -15,8 +15,16 @@ </Filter> </ItemGroup> <ItemGroup> - <ClCompile Include="CST116F2021-Lab6.cpp"> + <ClCompile Include="CST116F2021-Lab6 - Joseph Ten Eyck.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="Functions.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="Header.h"> + <Filter>Source Files</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file diff --git a/CST116F2021-Lab6/Functions.cpp b/CST116F2021-Lab6/Functions.cpp new file mode 100644 index 0000000..b6683ec --- /dev/null +++ b/CST116F2021-Lab6/Functions.cpp @@ -0,0 +1,163 @@ +//============================================================= +// CODE FOR PROBLEM #1 ON PAGE 282 (LEARN BY DOING) IS BELOW +//============================================================= + +//#include "Header.h" +// +//void readData(string club_name[][31], string club_pres[][31], int num_stud[], float money[]) //Takes in user entered data and writes to arrays +//{ +// for (int i = 0; i < 10; i++) +// { +// cout << "\n\tEnter club " << i + 1 << " name: "; +// getline(cin >> ws,club_name[i][0]); +// +// cout << "\n\tEnter club " << i + 1 << " president: "; +// getline(cin >> ws,club_pres[i][0]); +// +// cout << "\n\tEnter club " << i + 1 << " number of students: "; +// cin >> num_stud[i]; +// +// money[i] = 75 * num_stud[i]; +// +// cout << "\n\n~~~~~~~~~~~~~~~~~~~~" << endl; +// } +// +//} +// +//void displayData(string club_name[][31], string club_pres[][31], int num_stud[], float money[]) // Displays the data from the arrays in an orderly fashion +//{ +// cout << "\n\nClub Name Club President # of Students Money"; +// cout << "\n--------------------------------------------------------------------------------------------------\n"; +// +// for (int i = 0; i < 10; i++) +// { +// cout << left << setw(32) << club_name[i][0] +// << left << setw(32) << club_pres[i][0] +// << left << setw(18) << num_stud[i] +// << "$" << left << money[i] << endl; +// } +//} + + +//==================================================================== +// CODE FOR PROBLEM #1 ON PAGE 292 (PROGRAMMING EXERCISES) IS BELOW +//==================================================================== + +#include "Header.h" + +void displayMenu(int& menu_choice) //Displays menu choices and takes in user choice +{ + do + { + cout << "\n\t\t=============================="; + cout << "\n\t\t What would you like to do?"; + cout << "\n\t\t=============================="; + + cout << "\n\n\t1) Test if a string is a palindrome"; + cout << "\n\t2) Test if a string is all alphabetic characters"; + cout << "\n\t3) Count the number of times a specific character appears in a string"; + cout << "\n\t4) Exit"; + + cout << "\n\n\t\tMenu choice #: "; + cin >> menu_choice; + + if (menu_choice < 1 || menu_choice > 4) + { + cout << "\n\nError: Invalid menu choice\n"; + } + } while (menu_choice < 1 || menu_choice > 4); +} + +void processMenuChoice(int menu_choice) //Process menu choice, calls relevant function +{ + switch (menu_choice) { + + case 1: + { + isPalindrome(); + break; + } + + case 2: + { + isAlphaStr(); + break; + } + + case 3: + { + countChar(); + break; + } + + case 4: + { + cout << "\n\t\t\t~ Goodbye! ~\n\n"; + break; + } + } + +} + +void isPalindrome() //Checks whether or not a user input string is a palindrome +{ + char string1[41]; + char stringR[41]; + int same = 2; + + cout << "\n\t\t---------------------------------------------------------"; + cout << "\n\t\t Enter a string (up to 40 characters, spaces are okay)"; + cout << "\n\t\t---------------------------------------------------------"; + + cin.ignore(numeric_limits<streamsize>::max(), '\n'); //****Ignores everything in the input buffer up to this point + + cout << "\n\tEnter string: "; + cin.getline(string1, 41); + + strcpy_s(stringR, string1); + + _strrev(stringR); + + + same = strcmp(string1, stringR); + + if (same == 0) + { + cout << "\n\tThe string is a palindrome!\n"; + } + else if (same == 1) + { + cout << "\n\tThe string is not a palindrome.\n"; + } +} + +void isAlphaStr() //Checks to see if a user input string contains all alphabetic characters or not, displays result +{ + char string2[31]; + int strLength = 0; + int flag = 0; + + cout << "\n\t\t---------------------------------------------------"; + cout << "\n\t\t Enter a string (up to 30 characters, no spaces)"; + cout << "\n\t\t---------------------------------------------------"; + + cin.ignore(numeric_limits<streamsize>::max(), '\n'); //****Ignores everything in the input buffer up to this point + + cout << "\n\tEnter string: "; + cin.getline(string2, 31); + + strLength = strlen(string2); + + for (int i = 0; i < strlength - 1; i++) + { + if (isalpha(string2)) + { + + } + } +} + +void countChar() //Takes in a user input string and a character, counts the frequency of that character within the string, displays result +{ + +}
\ No newline at end of file diff --git a/CST116F2021-Lab6/Header.h b/CST116F2021-Lab6/Header.h new file mode 100644 index 0000000..3eb3323 --- /dev/null +++ b/CST116F2021-Lab6/Header.h @@ -0,0 +1,35 @@ +//============================================================= +// CODE FOR PROBLEM #1 ON PAGE 282 (LEARN BY DOING) IS BELOW +//============================================================= + +//#include <iostream> +//#include <iomanip> +//#include <string> +// +//using namespace std; +// +//void readData(string[][31], string[][31], int[], float[]); //Takes in user entered data and writes to arrays +// +//void displayData(string[][31], string[][31], int[], float[]); // Displays the data from the arrays in an orderly fashion + + +//==================================================================== +// CODE FOR PROBLEM #1 ON PAGE 292 (PROGRAMMING EXERCISES) IS BELOW +//==================================================================== + +#include <iostream> +#include <string> +#include <cstring> +#include <iomanip> + +using namespace std; + +void displayMenu(int&); //Displays menu choices and takes in user choice + +void processMenuChoice(int); //Process menu choice, calls relevant function + +void isPalindrome(); //Checks whether or not a user input string is a palindrome and displays result + +void isAlphaStr(); //Checks to see if a user input string contains all alphabetic characters or not, displays result + +void countChar(); //Takes in a user input string and a character, counts the frequency of that character within the string, displays result
\ No newline at end of file diff --git a/RUNS.txt b/RUNS.txt new file mode 100644 index 0000000..07afccb --- /dev/null +++ b/RUNS.txt @@ -0,0 +1,255 @@ +============================================================= + RUN FOR PROBLEM #1 ON PAGE 282 (LEARN BY DOING) IS BELOW +============================================================= + + + Enter club 1 name: Computer Systems Society + + Enter club 1 president: Kim Cares + + Enter club 1 number of students: 49 + + +~~~~~~~~~~~~~~~~~~~~ + + Enter club 2 name: Society of Women Engineers + + Enter club 2 president: Jeanie Queen + + Enter club 2 number of students: 51 + + +~~~~~~~~~~~~~~~~~~~~ + + Enter club 3 name: Sigma Tau Gamma + + Enter club 3 president: Storm Drain + + Enter club 3 number of students: 241 + + +~~~~~~~~~~~~~~~~~~~~ + + Enter club 4 name: Trekkies + + Enter club 4 president: C. Kirk + + Enter club 4 number of students: 230 + + +~~~~~~~~~~~~~~~~~~~~ + + Enter club 5 name: Home Brewers + + Enter club 5 president: Ross Coe + + Enter club 5 number of students: 15 + + +~~~~~~~~~~~~~~~~~~~~ + + Enter club 6 name: High Altitude Ballooning + + Enter club 6 president: Justin Time + + Enter club 6 number of students: 19 + + +~~~~~~~~~~~~~~~~~~~~ + + Enter club 7 name: Rugby + + Enter club 7 president: Ryan Johns + + Enter club 7 number of students: 25 + + +~~~~~~~~~~~~~~~~~~~~ + + Enter club 8 name: IEEE + + Enter club 8 president: Marc Bransmere + + Enter club 8 number of students: 36 + + +~~~~~~~~~~~~~~~~~~~~ + + Enter club 9 name: International Club + + Enter club 9 president: Kong Mbonkum + + Enter club 9 number of students: 102 + + +~~~~~~~~~~~~~~~~~~~~ + + Enter club 10 name: Dance Club + + Enter club 10 president: Will Shaver + + Enter club 10 number of students: 64 + + +~~~~~~~~~~~~~~~~~~~~ + + +Club Name Club President # of Students Money +-------------------------------------------------------------------------------------------------- +Computer Systems Society Kim Cares 49 $3675 +Society of Women Engineers Jeanie Queen 51 $3825 +Sigma Tau Gamma Storm Drain 241 $18075 +Trekkies C. Kirk 230 $17250 +Home Brewers Ross Coe 15 $1125 +High Altitude Ballooning Justin Time 19 $1425 +Rugby Ryan Johns 25 $1875 +IEEE Marc Bransmere 36 $2700 +International Club Kong Mbonkum 102 $7650 +Dance Club Will Shaver 64 $4800 + +C:\Users\eclip\Source\Repos\cst116-lab6-JosephTenEyck\Debug\CST116F2021-Lab6.exe (process 3480) 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 289-292 ARE BELOW +//============================================================= + +Please enter your first name: Joseph + +Please enter your last name: Teneyck + + + Welcome Joseph Teneyck! + Hope all is well + + x y z + + 0 100 100 + 1 101 102 + 2 102 104 + 3 103 106 + 4 104 108 + 5 105 110 + 6 106 112 + 7 107 114 + 8 108 116 + 9 109 118 + +C:\Users\eclip\Source\Repos\cst116-lab6-JosephTenEyck\Debug\CST116F2021-Lab6.exe (process 16756) 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 . . . + + +Please enter your first name: Joseph + +Please enter your last name: Teneyck + + + Welcome Joseph Teneyck! + Hope all is well + + x y z + + 0 100 -99 + 99 101 200 + 2 102 104 + 3 103 106 + 4 104 108 + 5 105 110 + 6 106 112 + 7 107 114 + 8 108 116 + 9 109 118 + +C:\Users\eclip\Source\Repos\cst116-lab6-JosephTenEyck\Debug\CST116F2021-Lab6.exe (process 18024) 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 PROBLEM #1 ON PAGE 292 (PROGRAMMING EXERCISES) ARE BELOW +//==================================================================== + + + + ============================== + What would you like to do? + ============================== + + 1) Test if a string is a palindrome + 2) Test if a string is all alphabetic characters + 3) Count the number of times a specific character appears in a string + 4) Exit + + Menu choice #: 1 + + --------------------------------------------------------- + Enter a string (up to 40 characters, spaces are okay) + --------------------------------------------------------- + Enter string: hello dad + + The string is not a palindrome. + + ============================== + What would you like to do? + ============================== + + 1) Test if a string is a palindrome + 2) Test if a string is all alphabetic characters + 3) Count the number of times a specific character appears in a string + 4) Exit + + Menu choice #: 4 + + ~ Goodbye! ~ + + +C:\Users\eclip\Source\Repos\cst116-lab6-JosephTenEyck\Debug\CST116F2021-Lab6.exe (process 16536) 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 . . . + + + + ============================== + What would you like to do? + ============================== + + 1) Test if a string is a palindrome + 2) Test if a string is all alphabetic characters + 3) Count the number of times a specific character appears in a string + 4) Exit + + Menu choice #: 1 + + --------------------------------------------------------- + Enter a string (up to 40 characters, spaces are okay) + --------------------------------------------------------- + Enter string: racar toot racar + + The string is a palindrome! + + ============================== + What would you like to do? + ============================== + + 1) Test if a string is a palindrome + 2) Test if a string is all alphabetic characters + 3) Count the number of times a specific character appears in a string + 4) Exit + + Menu choice #: 4 + + ~ Goodbye! ~ + + +C:\Users\eclip\Source\Repos\cst116-lab6-JosephTenEyck\Debug\CST116F2021-Lab6.exe (process 16584) 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 . . . + + + + |