diff options
| author | Tyler Taormina <[email protected]> | 2021-11-09 22:36:26 -0800 |
|---|---|---|
| committer | Tyler Taormina <[email protected]> | 2021-11-09 22:36:26 -0800 |
| commit | f86fe8059b8ae06b748c0e20a80e45a98c2d19d1 (patch) | |
| tree | fa445ca0b5bfbfcd45c64183c2decf661b159682 /lab6_taormina.txt | |
| parent | November 3, 2021 update to Lab 6. (diff) | |
| download | cst116-lab6-till-t-f86fe8059b8ae06b748c0e20a80e45a98c2d19d1.tar.xz cst116-lab6-till-t-f86fe8059b8ae06b748c0e20a80e45a98c2d19d1.zip | |
Completed modules 11a and 11b.
Need last module.
Diffstat (limited to 'lab6_taormina.txt')
| -rw-r--r-- | lab6_taormina.txt | 241 |
1 files changed, 240 insertions, 1 deletions
diff --git a/lab6_taormina.txt b/lab6_taormina.txt index 5ed8f9f..05d6af5 100644 --- a/lab6_taormina.txt +++ b/lab6_taormina.txt @@ -11,10 +11,132 @@ pg 282-283 CODE: +/*Tyler Taormina + *Module 11a + *Matrix Practice + */ + +#include <iostream> +#include <cstring> +#include <iomanip> +using namespace std; + +#define ARRAY_SIZE 10 + +int readData(int[ARRAY_SIZE][2], string[ARRAY_SIZE][2]); + +void printData(int[ARRAY_SIZE][2], string[ARRAY_SIZE][2], int[ARRAY_SIZE], int); +void calcData(int[ARRAY_SIZE][2], int[ARRAY_SIZE]); + +int main() +{ + int COUNTER; + int award[ARRAY_SIZE]; + int id_numStu[ARRAY_SIZE][2]; + string pres_club[ARRAY_SIZE][2]; + COUNTER = readData(id_numStu, pres_club); + calcData(id_numStu, award); + printData(id_numStu, pres_club, award, COUNTER); +} + + + +void printData(int intData[ARRAY_SIZE][2], string stringData[ARRAY_SIZE][2], int awardData[ARRAY_SIZE], int ctr) +{ + cout << setw(20) << left << "Student Club" << left << setw(20) << "President" << setw(20) << left << "Number of Students" << setw(20) << left << "Award" << endl; + // Headings for the columns ^^ + cout << "=============================================================================" << endl; + + + for (int i = 0; i < ctr; i++) + { + for (int j = 0; j < 1; j++) + { + cout << setw(20) << left << stringData[i][j] << setw(20) << left << stringData[i][j+1] << setw(20) << left << intData[i][j+1] << setw(20) << left << awardData[i] << endl; + } + } + +} + +int readData(int intData[ARRAY_SIZE][2], string stringData[ARRAY_SIZE][2]) +{ + int again = 1, i = 0, num_stu = 0, counter = 0; + while (again && i < ARRAY_SIZE) + { + cout << "Enter the ID (0 to exit): "; + cin >> again; + if (again) + { + intData[i][0] = again; + cout << "Enter the name of the club: "; + getline( cin >> ws, stringData[i][0]); + cout << "Enter the President of the club: "; + getline( cin >> ws, stringData[i][1]); + cout << "Enter the number of students in the club: "; + cin >> num_stu; + intData[i][1] = num_stu; + cout << endl; + i++; + counter++; + } + + + } + cout << endl; + return counter; + +} + + +void calcData(int intData[ARRAY_SIZE][2], int awardData[ARRAY_SIZE]) +{ + int award = 75; + int i; + + for (i = 0; i < ARRAY_SIZE; i++) + { + awardData[i] = intData[i][1] * award; + } +} RUN: +Enter the ID (0 to exit): 1 +Enter the name of the club: Weenies +Enter the President of the club: Oliver +Enter the number of students in the club: 2 + +Enter the ID (0 to exit): 2 +Enter the name of the club: Huskies +Enter the President of the club: Koda +Enter the number of students in the club: 3 + +Enter the ID (0 to exit): 3 +Enter the name of the club: Ping Pong +Enter the President of the club: Tyler +Enter the number of students in the club: 1 + +Enter the ID (0 to exit): 4 +Enter the name of the club: Video +Enter the President of the club: Mike +Enter the number of students in the club: 20 + +Enter the ID (0 to exit): 5 +Enter the name of the club: Photo +Enter the President of the club: Sun +Enter the number of students in the club: 2 + +Enter the ID (0 to exit): 0 + +Student Club President Number of Students Award +============================================================================= +Weenies Oliver 2 150 +Huskies Koda 3 225 +Ping Pong Tyler 1 75 +Video Mike 20 1500 +Photo Sun 2 150 + _______________________________________________________________________________ @@ -24,11 +146,128 @@ pg 289-292 CODE: +// Tyler Taormina +// CST 116 +// Module 11B Debugging Exercise +// pg 289-292 +// #1 for 10pts + + +#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[] ) +{ + for ( int x = 0; x < SIZE; x++ ) // Notice the const SIZE here + varZ[x] = varX[x] + varY[x]; + varX[1] = 99; +} + + +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: tyler + +Please enter your last name: taormina + + + Welcome tyler taormina! + Hope all is well + + x y z + + 0 100 -99 + 99 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 + _______________________________________________________________________________ -11c +11c 10.15 Programming Exercises pg 292-293 #1 for 10pts |