From c30e2e6fa029e1da063a7418c7c9f46b5eb7b571 Mon Sep 17 00:00:00 2001 From: IsabellaMon <91996332+IsabellaMon@users.noreply.github.com> Date: Wed, 10 Nov 2021 23:59:42 -0800 Subject: Add files via upload Lab 6 mon --- M6L6Mon.txt | 598 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 598 insertions(+) create mode 100644 M6L6Mon.txt (limited to 'M6L6Mon.txt') diff --git a/M6L6Mon.txt b/M6L6Mon.txt new file mode 100644 index 0000000..9a0418c --- /dev/null +++ b/M6L6Mon.txt @@ -0,0 +1,598 @@ +CST116 +Module 6: Lab 6 + +11a +10.10 Learn by Doing Exercises +pp 282-283 +10 pts #1 +Submit: code & run + +CODE: + + #include + #include + #include + using namespace std; + + #define ARRAY_SIZE 10 + + void ReadData(int[ARRAY_SIZE][4], string[ARRAY_SIZE][4]); + void PrintData(int[ARRAY_SIZE][4], string[ARRAY_SIZE][4]); + + int main() + + { + + int NumStudents_Club[ARRAY_SIZE][4]{}; + string Pres_Club[ARRAY_SIZE][4]{}; + ReadData(NumStudents_Club, Pres_Club); + PrintData(NumStudents_Club, Pres_Club); + + } + + + void ReadData(int intData[ARRAY_SIZE][4], string stringData[ARRAY_SIZE][4]) + + { + + int Club_M = 75; + int again = 1, numb_clubs = 0; + + string Club_Name; + + while (again && (numb_clubs < ARRAY_SIZE)) + + { + cout << "Enter the club name: "; + getline(cin >> ws, stringData[numb_clubs][0]); + + intData[numb_clubs][0] = again; + + cout << "Enter the president's name: "; + getline(cin >> ws, stringData[numb_clubs][1]); + + cout << "Enter the amount of members: "; + cin >> intData[numb_clubs][1]; + + cout << "This club has: $" << Club_M * intData[numb_clubs][1] << endl; + + numb_clubs++; + + cout << "\n\tEnter 0 to exit or 1 to continue: "; + cin >> again; + + } + + cout << endl; + + } + + void PrintData(int intData[ARRAY_SIZE][4], string stringData[ARRAY_SIZE][4]) + { + int numb_clubs = 0; + int Club_M = 75; + + + cout << "|Student Club\t|President\t|Number of Students\t|Club Money\t|" << endl; + + while (numb_clubs < ARRAY_SIZE) + + { + cout << "| " << stringData[numb_clubs][0] << "\t\t|" << stringData[numb_clubs][1] << "\t\t|" << intData[numb_clubs][1] << "\t\t\t\t\t| " << "$" << Club_M * intData[numb_clubs][1] << "\t\t\t| " << endl; + + numb_clubs++; + + } + + } + + +RUN: + + Enter the club name: Computer Systems Society + Enter the president's name: Kim Cares + Enter the amount of members: 49 + This club has: $3675 + + Enter 0 to exit or 1 to continue: 1 + Enter the club name: Society of Women Engineers + Enter the president's name: Jeanie Queen + Enter the amount of members: 51 + This club has: $3825 + + Enter 0 to exit or 1 to continue: 1 + Enter the club name: Sigma Tau Gamma + Enter the president's name: Storm Drain + Enter the amount of members: 241 + This club has: $18075 + + Enter 0 to exit or 1 to continue: 1 + Enter the club name: Trekkies + Enter the president's name: C. Kirk + Enter the amount of members: 230 + This club has: $17250 + + Enter 0 to exit or 1 to continue: 1 + Enter the club name: Home Brewers + Enter the president's name: Ross Coe + Enter the amount of members: 15 + This club has: $1125 + + Enter 0 to exit or 1 to continue: 1 + Enter the club name: High Altitude Ballooning + Enter the president's name: Justin Time + Enter the amount of members: 19 + This club has: $1425 + + Enter 0 to exit or 1 to continue: 1 + Enter the club name: Rugby + Enter the president's name: Ryan Johns + Enter the amount of members: 25 + This club has: $1875 + + Enter 0 to exit or 1 to continue: 1 + Enter the club name: IEEE + Enter the president's name: Marc Bansmere + Enter the amount of members: 36 + This club has: $2700 + + Enter 0 to exit or 1 to continue: 1 + Enter the club name: International Club + Enter the president's name: King Mbonkum + Enter the amount of members: 102 + This club has: $7650 + + Enter 0 to exit or 1 to continue: 1 + Enter the club name: Dance Club + Enter the president's name: Will Shaver + Enter the amount of members: 64 + This club has: $4800 + + + Enter 0 to exit or 1 to continue: 0 + + |Student Club |President |Number of Students |Club 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 Bansmere |36 | $2700 + | International Club |King Mbonkum |102 | $7650 + | Dance Club |Will Shaver |64 | $4800 + + + + + +11b +10.14 Debugging Exercises +pp 289-292 +10 pts #1 +Submit: code & run + + * Debugging Exercise 1 +CODE: + + #include + #include + using std::cin; + using std::cout; + using std::endl; + using std::setw; + + void GetAndDisplayWelcomeInfo ( ); + void FunctionOne ( int varX[], int varY[] ); + void FunctionTwo ( const int varX[], const int varY[], int varZ[] ); + void PrintFunction ( const int varX[], const int varY[], + const int varZ[] ); + + const int SIZE = 5; + + int main ( ) + { + int varX[5]; + 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 ); + 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 < 5; x++ ) + varY[x] = x + 100; + } + void FunctionTwo ( const int varX[], const int varY[], int varZ[] ) + { + 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; + } + +RUN: + + Please enter your first name: Isabella + + Please enter your last name: Mon + + + Welcome Isabella Mon! + Hope all is well + + x y z + + 0 100 100 + 1 101 102 + 2 102 104 + 3 103 106 + 4 104 108 + + * Debugging Exercise 2 +CODE: + + #include + #include + using std::cin; + using std::cout; + using std::endl; + using std::setw; + + void GetAndDisplayWelcomeInfo(); + void FunctionOne(int varX[], int varY[]); + void FunctionTwo(const 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); + 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 < 5; x++) + varY[x] = x + 100; + } + void FunctionTwo(const int varX[], const int varY[], int varZ[]) + { + 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; + } + +RUN: + + Please enter your first name: Isabella + + Please enter your last name: Mon + + + Welcome Isabella Mon! + 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 + + * Debugging Exercise 3 +CODE: + + #include + #include + 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 < 5; 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; + } + +RUN: + + Please enter your first name: Isabella + + Please enter your last name: Mon + + + Welcome Isabella Mon! + 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 + + + +11c +10.15 Programming Exercises +pp 292-293 +10 pts #1 +Submit: code & run +Total: 30 pts + +CODE: + #include + #include + #include + + using namespace std; + + bool IsPalindrome(string cString); + bool IsAlphaStr(string cString); + int CountChar(string cString, char input); + + int main() + { + string userdata; + + cout << "Enter the string: "; + cin >> userdata; + + if (IsPalindrome(userdata)) + + { + cout << userdata << " is a palindrome\n" << endl; + + } + + else + { + cout << userdata << " is not a palindrome\n" << endl; + } + + if (IsAlphaStr(userdata)) { + cout << userdata << " is alphabetic\n" << endl; + } + + else + { + cout << userdata << " is not alphabetic\n" << endl; + } + char input; + + cout << "\n\tWhat character do you want to count? "; + cin >> input; + + cout << input << " appeared " << CountChar(userdata, input) << " times." << endl; + + return 0; + + } + + bool IsPalindrome(string cString) + { + for (int i = 0; i < cString.length() / 2; i++) + { + if (cString[i] != cString[cString.length() - 1 - i]) + return false; + } + return true; + } + + bool IsAlphaStr(string cString) + { + for (int i = 0; i < cString.length(); i++) + { + if (((cString[i] >= 'A' && cString[i] <= 'Z') || (cString[i] >= 'a' && cString[i] <= 'z'))) + { + return false; + } + + } + + return true; + } + + int CountChar(string cString, char input) + + { + + int count = 0; + + for (int i = 0; i < cString.length(); i++) + { + if (cString[i] == input) + { + count++; + } + + } + return count; + + } + + + +RUN1: + Enter the string: hello + hello is not a palindrome + + hello is not alphabetic + + + What character do you want to count? l + l appeared 2 times. + + +RUN2: + Enter the string: racecar + racecar is a palindrome + + racecar is not alphabetic + + + What character do you want to count? e + e appeared 1 times. \ No newline at end of file -- cgit v1.2.3