diff options
Diffstat (limited to 'Lab2_Taormina.txt')
| -rw-r--r-- | Lab2_Taormina.txt | 288 |
1 files changed, 288 insertions, 0 deletions
diff --git a/Lab2_Taormina.txt b/Lab2_Taormina.txt new file mode 100644 index 0000000..e494aaa --- /dev/null +++ b/Lab2_Taormina.txt @@ -0,0 +1,288 @@ + + +Tyler Taormina +October 6, 2021 + +Module 2 Lab 2 + +3a) Literals +pg 62 +4.1 Exercises +------------------------ + +Correct and Label Literals +----------------------------------------------------------------------- + +1. -12.34 Numeric +. +2. �Hello� �Hello� type string + +3. �F� type string + +4. �1234� type string + +5. �1� type character + +6. A �A� type character + +7. �Marcus� �Marcus� type string + + +pg 65 +4.3 Exercises +--------------------- + +State what is wrong with each of the below +------------------------------------------------------------------------- + +a. int a, int b; + In the above code we could remove the second 'int' before the b. We would have... + + int a, b; + +b. Int a = b; + Int b = 0; + + In the above code we would need to change the order so that we are giving b a value before we initialize a. Corrected would look like... + int b = 0; + int a = b; + +c. Int a = 0, b = 3.5; +Should be.... +int a = 0; +float b = 3.5; + +d. Char grade = �A�; +Should be single quotes... + char grade = 'A'; + +e. Char c = 1; +Should be in single quotes... + char c = '1'; + +f. Int a, b, c, d, e, f; +should be lowercase 'i' in "int" and the names are nondescriptive + + +g. Char x = �This is a test.�; +Should be a string... + String x = "This is a test."; + + + pg 122 +6. 1 Exercises +---------------------------------------------------------------------------- + +1. y = 5x + 1; +invalid because in c++ we cannot use a coefficient with a variable. We would need an asterisc to imply multiplication + +2. X^2 + 2x + 1 = 0; +invalid because of the coefficient + +3. x = 5 * a + 4; +valid c++ statement + +4. 0 = -15 * b; +cannot have a constant on the left side of an equal sign, must be a variable. + + + + +pg 82 +3B) +4.12 Exercises +-------------------------------------------------------------------------------- + +1. 6% raise problem (this is the corrected pseudo code) + +Display "enter old wage: " +read old_wage + +raise_amnt = old_wage * .06 +new_wage = old_wage + raise_amnt + +display old_wage +display " + 6% = " +display new_wage + + +2. Final Grade problem (this is the corrected pseudo code) + +Display "Enter Assignment Avergae: " +read assign_avg + +Display "Enter test 1: " +read test1 + +Display "Enter test 2:" +read test2 + +Display "Enter test 3:" +read test3 + +Display "Enter Final: " +read final_test + +test_avg = (test1 * .15 + test2 * .15 + test3 * .15) / 3 +class_score = assign_avg * .30 + test_avg * .45 + final_test * .25 + +Display "Final Score:" +display class_score + +3C) +4.13 Programming exercise +pg 83-84 +#2-3 + + +2) Just compile and run program. Will include image. + +3) +#include <iostream> +#include <iomanip> +using namespace std; + +int main() { + int year = 365; + int age = 27; + int age_in_days; + age_in_days = year * age; + + cout << "You are " << age_in_days << " days old!"; + + return 0; +} + + + + + +4A) +5.4 Exercise +pg 100 +#1 + +#include <iostream> +#include <iomanip> + +using namespace std; + +int main() +{ + float temp; + cin >> temp; + + cout << "Your temperature is: "; + cout.width(6); + cout.setf(ios::fixed); // decimal notation + cout << setprecision(1) << temp << endl; + + return 0; + + +6.3 Exercises +pg 123-124 +#1-7 + +1) a = 5 + 10 * 2 + a = 25 + +2) a = (5 + 10) * 2; + a = 30 + +3) a = 5; + a = a + (5 + 10) * 2; + a = 35 + +4) a = 10 % 5; + a = 0 + +5) a = 10 % 3; + a = 1 + +6) a = 5.2 % 2.3; + Error for incorrect opperands. Cannot use '%' with type double or float + +7) 2 - 5 + 7 = a; + Error saying expression must be a modifiable value + + + +4B) +5.9 Debugging Exercise + +int main() { + float money = 123.45; + float raise; + cout << "You have $ "; + cout << money << endl; + // breakpoint 1 + //put a breakpoint on the folowing line + cout << "Enter percent raise: "; + cin >> raise; + + money = money * raise + money; + cout << "After your raise you have $"; + cout.setf(ios::fixed); + cout << setprecision(2) << money << endl; + + return 0; +} + + +5.10 Programming Exercise +pg 114-115 +#1 +#include <iostream> + +using namespace std; + +int main() { + float PRODUCTION_RATE = 10.00; + float PRE_PRODUCTION_RATE = 10.00; + float PRODUCERS_RATE = 10.00; + + double ProductionHours, PreProductionHours, ProducersHours, ProductionCost, + PreProductionCost, ProducersCost, TotalCost; + cout << "Enter Production Hours: "; + cin >> ProductionHours; + + cout << "\nEnter Pre-Production Hours: "; + cin >> PreProductionHours; + + cout << "\nEnter Producers Hours: "; + cin >> ProducersHours; + + ProductionCost = ProductionHours * PRODUCTION_RATE; + PreProductionCost = PreProductionHours * PRE_PRODUCTION_RATE; + ProducersCost = ProducersHours * PRODUCERS_RATE; + + TotalCost = ProductionCost + PreProductionCost + ProducersCost; + + cout << "\n\t\tCar Dealership Bill\n"; + + cout << "\n\nProduction Cost: "; + cout << ProductionCost; + + cout << "\n\nPre-Production Cost: "; + cout << PreProductionCost; + + cout << "\n\nProducers Cost: "; + cout << ProducersCost; + + cout << "\n\nWeekly Total Cost: "; + cout << TotalCost << endl; + + return 0; + +} + + + + + + + + + + |