kD 05 ELET 2300-HW01 [Compatibility a Design Layout References Mailings Review a
ID: 3883933 • Letter: K
Question
kD 05 ELET 2300-HW01 [Compatibility a Design Layout References Mailings Review al 12A A Hwo1 Due Sunday Sep 17, by 11:59 pm Submit your solution on blackboard learn. You will need to submit 3 files: 1, A Microsoft word document with you answers to Q1-Q6. 2. Your program for Q6 as a text file, named: hw1q6.cpp 3. Your program for Q7 as a text file, named: hw1q7.cpp Note: For Q6 and Q7 DO NOT Submit you Visual Studio 2015 project/solution files. You need to submit only the program as a text file with the extension Write an algorithm (list the steps) to swap the contents of two numbers. For example, if number1 = 10 and number2-20, after the swap, number1 = 20 and number2:10. You do not have to write a program, just the algorithm. Use the pseudocode method ie write the ep procedure using ecolish phrases, Do not use the flowchart method. 1. 2. AC+ program is required that calculates the amount, in dollars, contained in a pigaybank. The piggybank contains, quarters, dimes, nickels, and pennies a. For this programming problem, how many outputs are required? b. How many inputs does this problem have? c. Write an algorithm (psuedocode format and not flowchart) for converting the input items into output items. d. Test the algorithm written for Exercise 1c using the following sample data: quarters 17, dimes 24, nickels 16, and pennies 12 3 For the following algebraic expressions, write the corresponding C expressions: a. (2x3) (4)(5) 6+18 b. 2 Determine the values of the following numerical expressions: a. 3+4 6 4. Focus 529 WordsExplanation / Answer
1. Algorithm to swap the contents of two numbers
Algorithm:
Step 1: Start
Step 2: Read number1 and number 2
Step 3: Set temp = number1
Step 4: Set number1 = number 2
Step 5: Set number2 = temp
Step 5: Print number1 and number2
Step 6: Stop
2. Amount in PiggyBank
2 a. For this programming problem , how many outputs are required?
Answer: As per the question we will be given a certain amount of quarters, dimes, nickels and pennies and we need to calculate the total amount in dollars hence the program has only one output.
2 b. How many inputs does this problem have?
Answer: As per the question the PiggyBank contains quarters, dimes, nickels and pennies and hence the program requires 4 inputs.
2 c. Algorithm:
Step 1: Start
Step 2: Set totalDollars = 0
Step3: Read quarters
Step 4: Read dimes
Step 5: Read nickels
Step 6: Read pennies
Step 7: Compute totalDollars = totalDollars + (quarters * 0.25)
Step 8: Compute totalDollars = totalDollars + (dimes * 0.10)
Step 9: Compute totalDollars = totalDollars + (nickels * 0.05)
Step 10: Compute totalDollars = totalDollars + (pennies * 0.01)
Step 11: Print totalDollars
Step 12: Stop
2 d. Test the algorithm for 17 quarters, 24 dimes, 16 nickels and 12 pennies
Answer:
totalDollars =0
quarters = 17
dimes = 24
nickels = 16
pennies = 12
Now, totalDollars = 0 + (quarters * 0.25)
=> totalDollars = 17 * 0.25
=> totalDollars = 4.25
Now, totalDollars = totalDollars + (dimes * 0.10)
=> totalDollars = 4.25 + (24 * 0.10)
=> totalDollars = 4.25 + 2.4
=> totalDollars = 6.65
Now, totalDollars = totalDollars + (nickels * 0.05)
=> totalDollars = 6.65 + (16 * 0.05)
=> totalDollars = 6.65 + 0.8
=> totalDollars = 7.45
Now, totalDollars = totalDollars + (pennies * 0.01)
=> totalDollars = 7.45 + (12 * 0.01)
=> totalDollars = 7.45 + 0.12
=> totalDollars = 7.57
Hence we have a total of 7.57 dollars for the given input.
3. For the following algebraic expressions, write the corresponding c++ statements
a. (2)(3) + (4)(5)
The equivalent c++ statement is
(2 * 3) + (4 * 5)
b. 6 + 18
2
The equivalent c++ statement is
(6 + 18) / 2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.