0% found this document useful (0 votes)
50 views3 pages

Cpe 150 Laboratory 4: Control Structures Ii: 1 Objectives

This document outlines the objectives and exercises for a computer engineering laboratory on control structures. The objectives are to understand basic problem-solving techniques, algorithms, and how to use repetition structures like while and for loops. The exercises include writing programs to check if customers exceed credit limits, create a sales bar chart by storing asterisks, simulate a girl subtracting numbers incorrectly, and compute factorials.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views3 pages

Cpe 150 Laboratory 4: Control Structures Ii: 1 Objectives

This document outlines the objectives and exercises for a computer engineering laboratory on control structures. The objectives are to understand basic problem-solving techniques, algorithms, and how to use repetition structures like while and for loops. The exercises include writing programs to check if customers exceed credit limits, create a sales bar chart by storing asterisks, simulate a girl subtracting numbers incorrectly, and compute factorials.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CpE 150 Laboratory 4: Control Structures II

Department of Computer Engineering


Yarmouk University
October 22, 2019

1 Objectives
• To understand basic problem-solving techinques.
• To be able to develop algorithms through the process of top-down stepwise refinment.
• To be able to use the while and for repetition structures to execute statementin a program repeatdly.
• To understand counter-controlled repetition and sentinel-controlled repetition.
• To be able use the increment, decrement, assignment and logical operators.
• To be able to use break and continue program control statements.

2 Lab Exercise 1 - Department Store


Write a program that will determine if a department-store customer has exceeded the credit limit on a
charge account. For each customer, the folowing information is availble:
1. account number (an integer);
2. balance at the beginning of the month;
3. total of all items charged by the customer this month;
4. total of all credits applied to the curtome’s account this month;
5. allowed credit limit.
This program should input this information, calculate the new balance (= beginning balance + charges -
credits) and determine if the new balance exceeds the customer’s credit limit. For those customers whose
credit limit is exceeded, the program should display the customer’s account number, credit limit, new
balance and the message “ Credit limit exceeded.”
Enter account number (-1 to end): 100
Enter beginning balance: 5394.78
Enter total charges: 1000.00
Enter total credits: 500.00
Enter credit limit: 5500.00
*************************************
Account: 100
Credit Limit: 5500.00

1
New Balance: 5894.78
Credit Limit Exceeded.
*************************************

Enter account number (-1 to end): 200


Enter beginning balance: 1000.00
Enter total charges: 123.45
Enter total credits: 321.00
Enter credit limit: 1500.00

Enter account number (-1 to end): 300


Enter beginning balance: 500.00
Enter total charges: 274.73
Enter total credits: 100.00
Enter credit limit: 800.00

Enter account number (-1 to end): -1


Follow-Up Questions and Activities

Why it is necessary to ask the user to input the first account number before you begin the while loop?
What problems could occur if the user was asked for an account number only inside the while loop?

3 Lab Exercise 2 - Sales Bar Chart


Write a program that asks the user to enter today’s sales for five stores. The program should then display
a bar graph comparing each store’s sales. Create each bar in the bar graph by displaying a row of asterisks.
Each asterisk should represent $100 of sales. Here is an example of the program’s output.
Enter today’s sales for store 1: 1000 [Enter]
Enter today’s sales for store 2: 1200 [Enter]
Enter today’s sales for store 3: 1800 [Enter]
Enter today’s sales for store 4: 800 [Enter]
Enter today’s sales for store 5: 1900 [Enter]
SALES BAR CHART
(Each * = $100)
Store 1: **********
Store 2: ************
Store 3: ******************
Store 4: ********
Store 5: *******************

4 Lab Exercise 3 - Wrong Subtraction


Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number
consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
• if the last digit of the number is non-zero, she decreases the number by one;
• if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit).

2
You are given an integer number n. Tanya will subtract one from it k times. Your task is to print the
result after all k subtractions. It is guaranteed that the result will be positive integer number.

Input
The first line of the input contains two integer numbers n and k(2 ≤ n ≤ 109 , 1 ≤ k ≤ 50) — the number
from which Tanya will subtract and the number of subtractions correspondingly.

Output
Print one integer number — the result of the decreasing n by one k times.

n: 512
k: 4
50

n: 1000000000
k: 9
1

5 Postlab Exercise
Write a program that reads a nonnegative integer and computes and prints its factorial. The factorial of
a nonnegative integer n is written n! (pronounced “n factorial”) and i defined as follows:

n! = n × (n − 1) × (n − 2) × · · · × 1 (for values of n greater than or equal to 1) and n! = 1 for n = 0

For example, 5! = 5 × 4 × 3 × 2 × 1 which is 120.

You might also like