Title: Assignment
1Assignment 2
2Problem 2.37
- Read a Encrypted Number
- Then Decrypt It
- And Return the Value to the Screen
3PSEUDOCODE
- Initialize Program
- Declare Variables
- Input and Read Number
- Break number into digits
- Add 7 and Determine Modulus
- Rearrange Digits
- Return the Value
- End Program
4Flow Chart
Start
Enter Number
Decrypt Number
ReturnNumber
5Source Code
include ltiostream.hgt int main() int
number int digit1, digit2, digit3, digit4,
encrypted int digit1new, digit2new, digit3new,
digit4new, decrypted cout ltlt "Enter a four
digit number to be decrypted " cin gtgt number
digit1 number / 1000 digit2 number 1000
/ 100 digit3 number 1000 100 /
10 digit4 number 1000 100
10 digit1new (digit1 7) 10 digit2new
(digit2 7) 10 digit3new (digit3 7)
10 digit4new (digit4 7) 10 encrypted
digit1 1000 digit2 100 digit3 10
digit4 decrypted digit3new 1000
digit4new 100 digit1new 10
digit2new cout ltlt "Check to make sure \nYour
Orginal Number was " ltlt encrypted ltlt
endl cout ltlt "Your Super Heavy Duty
Super-Secret\nDecrypted number is " ltlt
decrypted ltlt endl return 0 // indicate that
program ended successfully
6Output
7Problem 2.49
- Goal to Read
- Then Decrypt It
- And Return the Value to the Screen
8PSEUDOCODE
- Initialize Program
- Declare Variables
- Input and Read Number
- Start the While Loop
- Use the Switch Commands
- Add to Total
- Return the Total Value
- End Program
9Flow Chart
Get Numbers
1
Add
T
break
F
T
Add
2
break
F
T
Add
3
break
F
T
Add
4
break
F
T
Add
5
break
F
Total
10Source Code
include ltiostream.hgt include ltiomanip.hgt int
main() int product_number, sold float
total 0.0 cout ltlt "Enter pairs of item
numbers and quantities" ltlt "\nEnter -1
for the item number to end input " cin gtgt
product_number while ( product_number !
-1 ) cin gtgt sold switch (
product_number ) case 1 total sold
2.98 break case 2 total sold
4.50 break case 3 total sold
9.98 break
case 4 total sold 4.49
break case 5 total sold 6.87
break default cout ltlt "Incorrect Product
Number Entered." ltlt product_number ltlt "\n
Quantity" ltlt sold ltlt '\n' break
cout ltlt "Enter the Product Number (-1 to
end)" cin gtgt product_number cout ltlt
setiosflags( iosfixed iosshowpoint ) ltlt
"Total " ltlt setprecision( 2 ) ltlt total ltlt
endl return 0 // indicate that program ended
successfully
11Output