From 96fd6d0370a1537c65e89bab0c752ece7728a937 Mon Sep 17 00:00:00 2001 From: IsabellaMon <91996332+IsabellaMon@users.noreply.github.com> Date: Wed, 20 Oct 2021 11:38:39 -0700 Subject: Add files via upload M3L3 --- L3M3Mon.txt | 323 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 L3M3Mon.txt (limited to 'L3M3Mon.txt') diff --git a/L3M3Mon.txt b/L3M3Mon.txt new file mode 100644 index 0000000..ea972cb --- /dev/null +++ b/L3M3Mon.txt @@ -0,0 +1,323 @@ +CST116 +Module 3: Lab 3 + +5a +6.4 Exercises +p 126 +5 pts #1 +Submit: output + OUTPUT: + cout << a++ << endl; 0 + cout << ++a << endl; 2 + cout << a + 1 << endl; 3 + cout << a << endl; 2 + cout << --a << endl; 1 + +7.1 Exercises +p 148 +5 pts #1­-6 +Submit: corrected conditions + +int_exp1 = 0, int_exp2 = 1 +char_exp = 'B' + 1. int_exp1 => int_exp2 int_exp1 <= int_exp2 (Flip sign) + 2. int_exp1 = int_exp2 int_exp1 == int_exp2 (Two =) + 3. int_exp1 =! int_exp2 int_exp1 != int_exp2 (= comes second) + 4. char_exp == "A" char_exp == 'A' (Single quotes) + 5. int_exp1 > char_exp Correct + 6. int_exp1 < 2 && > -10 int_exp1 < 2 && int_exp 1 > -10 + +7.2 Learn by Doing Exercises +p 155 +10 pts #1 +Submit: code & run +Total: 15 pts + + +5b +7.4 Learn by Doing Exercises +p 161 +10 pts #1 +Submit: code & run + + #include + #include + using namespace std; + + int main() + { + int select; + + cout << "\n\t\tStudent Grade Program "; + cout << "\n\t\t - Main Menu - "; + cout << "\n\t\t1. Enter name "; + cout << "\n\t\t2. Enter test scores "; + cout << "\n\t\t3. Display test scores "; + cout << "\n\t\t9. Exit "; + + cout << "\n\n\tPlease Enter your choice from the list above: "; + cin >> select; + + switch (select) + { + case 1: + cout << "\n\tYou chose to enter name " << endl; + break; + case 2: + cout << "\n\tYou chose to enter test score " << endl; + break; + case 3: + cout << "\n\tYou chose to display test scores " << endl; + break; + case 9: + cout << "\n\tYou chose to exit " << endl; + break; + default: + cout << "\n\tInvalid option entered." << endl; + } + + + return 0; + } + +RUN: + + Student Grade Program + - Main Menu - + 1. Enter name + 2. Enter test scores + 3. Display test scores + 9. Exit + + Please Enter your choice from the list above: 5 + + Invalid option entered. + +5c +7.10 Programming Exercises +p 168 +10 pts #2 +Submit: code & run + +PSEUDOCODE: + + Display "Enter loan interest rate " + Read rate + + Display "Enter loan amount " + Read loan + + If rate amount is between 1 and 18% && loan amount is between 100 - 1000 + If loan is between 100 - 200 + loan_fee = 20 + If loan > 500 + loan_fee = 25 + If else + Display error message and end program + + Calculate the amount of interest paid on loan + Display requested amount of loan + Display interest rate + Display sum of interest and fees + +CODE: + #include + using namespace std; + + int main() + { + float rate = 0; + int amount = 0; + int loan_fee = 0; + float fees = 0; + float interest_rate = 0; + + cout << "Enter interest rate percentage: "; + cin >> rate; + + cout << "Enter loan amount: "; + cin >> amount; + + if (rate >= 1 && rate <= 18 && amount >= 100 && amount <= 1000) + { + if (amount >= 100 && amount <= 500) + loan_fee = 20; + else if (amount > 500) + loan_fee = 25; + + interest_rate = rate / 100; + fees = amount * interest_rate + loan_fee; + + cout << "Requested amount of loan: " << amount << "\nInterest rate: " << rate << "\nSum of interest and fees: " << fees << endl; + } + else + { + cout << "Invalid amount entered" << endl; + } + return 0; + } + +RUN: + Enter interest rate percentage 10 + Enter loan amount 500 + Requested amount of loan: 500 + Interest rate: 10 + Sum of interest and fees: 70 + +6a +6.5 Exercises +pp 126-127 +3 pts #1-5 +Submit: converted statements + +int a(10), b(20), c(30); +1. a = 25 + a; a += 25; +2. b = b * a * 2; b *= a * 2; +3. b = 1 + b; b += 1; OR b++; +4. c = c % 5; c %= 5; +5. b = b / a; b /+ a; + +8.2 Learn by Doing Exercises +pp 177 +10 pts #1 +Submit: code & run + +CODE: + #include + #include + using namespace std; + + int main() + { + int value = 0; + + cout << "Enter an integer between 1 and 50: "; + cin >> value; + + cout << "Even numbers from " << value << " to 0: \n"; + for (int i = value; i >= 0; i--) + { + if (i % 2 == 0) + cout << i << " "; + } + + return 0; + } + +RUN: + Enter an integer between 1 and 50: 25 + Even numbers from 25 to 0: + 24 22 20 18 16 14 12 10 8 6 4 2 0 + +8.3 Learn by Doing Exercises +pp 179 +10 pts #1 +Submit: code & run + +CODE: + #include + #include + using namespace std; + + int main() + { + int value = 0; + + do + { + cout << "\nPlease enter an integer between 1 and 50: "; + cin >> value; + } while (value > 50 || value < 1); + + cout << "Even numbers from " << value << " to 0: \n"; + for (int i = value; i >= 0; i--) + { + if (i % 2 == 0) + cout << i << " "; + + } + + return 0; + } + +RUN: + Please enter an integer between 1 and 50: 85 + + Please enter an integer between 1 and 50: 25 + Even numbers from 25 to 0: + 24 22 20 18 16 14 12 10 8 6 4 2 0 + +6b +8.4 Learn by Doing Exercises +p 184 +10 pts #2 +Submit: code & run + +CODE: + #include + using namespace std; + + int main() + { + int length = 0; + + cout << "Enter triangle lenth: "; + cin >> length; + + for (int row = length; row >= 1; row--) + { + for (int column = row; column > 0; column--) + { + cout << "* "; + } + cout << endl; + } + + } + +RUN: + Enter triangle lenth: 6 + * * * * * * + * * * * * + * * * * + * * * + * * + * + +6c +8.10 Programming Exercises +p 192 +10 pts #3 +Submit: code & run + +#include +using namespace std; + +int main() +{ + int term1 = 0; + int term2 = 1; + int nextTerm = 0; + int end; + + cout << "Enter an integer: "; + cin >> end; + + cout << "Fibonacci sequence: " << term1 << ", " << term2 << ", "; + + nextTerm = term1 + term2; + + while(nextTerm <= end) { + cout << nextTerm << ", "; + term1 = term2; + term2 = nextTerm; + nextTerm = term1 + term2; + + } + return 0; + +} + +RUN: +Enter an integer: 21 +Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, \ No newline at end of file -- cgit v1.2.3