diff options
| author | Isabella Mon <[email protected]> | 2021-10-13 15:03:21 -0700 |
|---|---|---|
| committer | Isabella Mon <[email protected]> | 2021-10-13 15:03:21 -0700 |
| commit | 63c34532c594e7f0231773b46cd616391df65b58 (patch) | |
| tree | 7672645cd53161e70f97169c1de9ffb624a3840a /M2L2Mon.txt | |
| parent | Add online IDE url (diff) | |
| download | cst116-lab2-isabellamon-master.tar.xz cst116-lab2-isabellamon-master.zip | |
Diffstat (limited to 'M2L2Mon.txt')
| -rw-r--r-- | M2L2Mon.txt | 282 |
1 files changed, 282 insertions, 0 deletions
diff --git a/M2L2Mon.txt b/M2L2Mon.txt new file mode 100644 index 0000000..c19e2bd --- /dev/null +++ b/M2L2Mon.txt @@ -0,0 +1,282 @@ +CST116 today +Module 2: Lab 2 + +3a +4.1 Exercises +pp 63-64 +3.5 pts #1-7 +Submit: labelled and corrected literals +1. -12.34 Numeric +2. �Hello� Illegal +3. �F� String +4. �1234� String +5. �1� Character +6. A Illegal +7. �Marcus� Illegal + +4.3 Exercises +p 72 +3.5 pts #3 +Submit: corrected statements +a. int a, b; +b. int b = 0; + int a = b; +c. int a = 0 + float b = 3.5; +d. char grade = 'A'; +e. char c = '1'; +f. int a, b, c, d, e, f; +g. string x = �This is a test.�; + +6.1 Exercises +p 122 +4 pts #5-4 +Submit: corrected statements +11 pts total +1. Y = 5x + 1; Invalid because "5x" needs * +2. x^2 + 2x + 1 = 0; Invalid because "2x" and because the left side of the equal sign should just be a variable location and you cannot use exponents +3. X = 5 * a + 4; Valid +4. 0 = -15 * b; Invalid because "0" (left side of equal sign must be a variable) + +3b +4.12 Exercises +pp 82-83 +20 pts 1-2 +Submit: corrected pseudocode +20 pts total +1. + Display "Enter old wage: " + Read Old_wage + + Raise = Old_wage * .06 + New_wage = Old_wage + Raise + + Display Old_wage + Display "+ 6% =" + Display New_Wage + +2. + Display "Enter Assignment average: " + Read Assignment_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_avg = Test1 * .15 + Test2 * .15 + Test3 *.15 / 3 + Class_Score = Assign_avg * .30 + Test_avg * .45 + Final * .25 + + Display "Final score: " + Display Class_score + +3c +4.13 Programming Exercises +pp 83-�84 +20 pts 2-�3 +Submit: code & run +20 pts total +2. + #include <iostream> + using std::cout; + + int main() + { + char ascii = 67; + + cout << ascii << '\n'; + ascii = 43; + cout << ascii << '\n'; + cout << ascii << '\n'; + + return 0; + } + +RUN: +C ++ ++ + +3. +PSEUDOCODE: + Display "Enter age: " + Read age + + new_age = age * days + Display new_age + +CODE: + #include <iostream> + using namespace std; + + int main() + { + int age = 0; + int new_age = 0; + const int days = 365; + + cout << "Enter age: "; + cin >> age; + + new_age = age * days; + cout << "Your age in days is: " << new_age << endl; + + return 0; + } + +RUN: +Enter age: 19 +Your age in days is: 6935 + +4a +p 100 +5.4 Learn by Doing Exercises +10 pts #1 +Submit: code & run +1. + #include <iostream> + #include <iomanip> + using namespace std; + + int main() + { + float temp = 0; + + cout << "Enter temperature: "; + cin >> temp; + + cout.width(6); + cout.setf(ios::fixed); + cout << setprecision(1) << temp << endl; + + return 0; + } + +RUN: +Enter temperature: 98.5 + 98.5 + +pp 123�-124 +6.3 Exercises +4 pts #1-�7 +Submit: corrected equations and values of the variable �a� +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; Modulus cannot be used for floats +7. 2 - 5 + 7 = a; The left side of the equal sign should be the variable + + +4b +pp 112-114 +5.9 Debugging Exercise +10 pts +Submit: corrected code & run + + #include <iostream> + #include <iomanip> + using std::cout; + using std::cin; + using std::endl; + + int main() + { + float money = 123.45F; + float raise_amount = 0; + float raise; + float new_money = 0; + + cout << "You have $"; + cout << money << endl; + + //Breakpoint 1 + //Put a breakpoint on the following line + cout << "Enter percent raise: "; + cin >> raise_amount; + + raise = money * raise_amount; + new_money = money + raise; + + cout << "After your raise you have $"; + cout << new_money << endl; + + return 0; + } + +RUN: +You have $123.45 +Enter percent raise: .1 +After your raise you have $135.795 + +pp 114-115 +5.10 Programming Exercise +10 pts #1 +Submit: corrected code & run +20 pts total + #include <iostream> + using std::cout; + using std::cin; + using std::endl; + + int main( ) + { + double ProductionHours, ProducersHours, ProducersCost, TotalCost; + double ProductionRate = 0; + double ProductionCost = 0; + + cout << "Enter Production Hours: "; + cin >> ProductionHours; + cout << "\nEnter Production Rate: "; + cin >> ProductionRate; + + cout << "\nEnter Producers Hours: \n"; + cin >> ProducersHours; + + ProductionCost = ProductionHours * ProductionRate; + ProducersCost = ProducersHours * ProductionRate; + + TotalCost = ProductionCost + ProducersCost; + + cout << "\n\t\tCar Dealership Bill " ; + cout << "\n\nProduction Cost: "; + cout << ProductionCost ; + + cout << "\n\nPre-Production Cost: "; + cout << ProductionCost; + + cout << "\n\nProducers Cost: "; + cout << ProducersCost; + + cout << "\n\nWeekly Total Cost: "; + cout << TotalCost << endl; + + return 0; + } + +RUN: +Enter Production Hours: 5 + +Enter Production Rate: 89 + +Enter Producers Hours: +9 + + Car Dealership Bill + +Production Cost: 445 + +Pre-Production Cost: 445 + +Producers Cost: 801 + +Weekly Total Cost: 1246
\ No newline at end of file |