online exsam

profilefadoo
cs1150_exam2_sampleproblems-solution.pdf

CS1150 Introduction to Computer Science Exam #2 Review - Algorithm Practice Problems

A Solution

1. Create an algorithm to describe how to balance a checkbook for a company that has more than 100 transactions.

Assumptions: Company has enough money to not go into the negative with all their transactions. Input: Initial balance from the user. Individual transactions from the user. Output: New balance after each transaction.

Step 1. Get the initial balance. Step 2. Ask the user if there are any other transactions. If not then go to Step 6. Step 3. Get a transaction. Step 4. Update the balance to be balance – tranaction. Step 5. Go to Step 2. Step 6. Tell the company user that the balancing is complete.

2. What does this algorithm do?

Assumptions: The user provides a positive integer. Input: A number from the user. Output: Some result.

Get a number from the user. // Step 1. Set result and count to 1. // Step 2. while (count <= 3) // Step 3.

Set result to result * number. // Step 4. Set count to count + 1. // Step 5.

Provide the result to the user. // Step 6.

This algorithm calculates the cube of a number.