Lab #1: Three Simple Exercises
CS1010 AY2017/8 Semester 1
Date of release: 28 August 2017, Monday, 8am.
Submission deadline: 6 September 2017, Wednesday, 5pm.
School of Computing, National University of Singapore

0 Introduction

Important: Please read Lab Guidelines before you continue.

This lab requires you to do 3 simple exercises.

You may assume that the input data are according to specification, and hence there is no need to do input data validation, unless otherwise stated.
The maximum number of submissions for each exercise is 15.

If you have any questions on the task statements, you may post your queries on the relevant IVLE discussion forum. However, do not post your programs (partial or complete) on the forum before the deadline!

1 Exercise 1: Investment

1.1 Learning objectives

1.2 Task statement

If you invest principal amount of money (in dollars) at rate percent interest rate compounded annually, in numYears years, your investment will grow to

principal × ( 1 - (rate/100)numYears+1 )

1 - rate/100

dollars.

Write a program invest.c that accepts positive integers principal, rate and numYears and computes the amount of money (of type float) earned after numYears years, presented in two decimal places.

You may assume that the interest rate is always smaller than 100.

1.3 Sample runs

Sample run using interactive input (user's input shown in blue; output shown in bold purple).
Sample run #1:

Enter principal amount: 100
Enter interest rate   : 10
Enter number of years : 5
Amount = $111.11 

Sample run #2:

Enter principal amount: 20000
Enter interest rate   : 5
Enter number of years : 10
Amount = $21052.63 

1.4 Skeleton program and Test data

1.5 Important notes

1.6 Estimated development time

The time here is an estimate of how much time we expect you to spend on this exercise. If you need to spend way more time than this, it is an indication that some help might be needed.

2 Exercise 2: Box Surface Area and Diagonal

2.1 Learning objectives

2.2 Task statement

Write a program box.c that reads three positive integers representing the length, width and height of a box, and computes (1) its surface area, and (2) the length of the diagonal between two vertices of the box that are furthest apart.

You may assume that the surface area of the box does not exceed the maximum value representable in the int data type.

Hint: Do you know the formula for computing the length of the diagonal?

2.3 Sample runs

Sample run using interactive input (user's input shown in blue; output shown in bold purple).
Sample run #1:

Enter length: 12
Enter width : 3
Enter height: 10
Surface area = 372
Diagonal = 15.91

Sample run #2:

Enter length: 10
Enter width : 20
Enter height: 30
Surface area = 2200
Diagonal = 37.42

2.4 Skeleton program and Test data

2.5 Important notes

2.6 Estimated development time

The time here is an estimate of how much time we expect you to spend on this exercise. If you need to spend way more time than this, it is an indication that some help might be needed.

3 Exercise 3: Packing

3.1 Learning objectives

3.2 Task statement

You are given a rectangle tray and an unlimited supply of slabs. An example of a 12×20 tray and a 8×3 slab are shown below.

You are to find the maximum number of slabs that can be packed into the tray. The slabs may be packed in either one of the two orientations, as shown below, but not in a mix of orientations.

The figures above show that the tray may be filled with 6 slabs arranged in one orientation, or 8 slabs arranged in the other orientation. Hence, the answer is 8.

You are to write a program packing.c to read in the dimensions of a tray and a slab, and to compute the maximum possible number of slabs that could be packed onto the tray.

You may assume that all inputs are positive integers.

3.3 Sample runs

Sample run using interactive input (user's input shown in blue; output shown in bold purple).
Sample run #1:

Enter dimension of tray: 12 20
Enter dimension of slab: 8 3
Maximum number of slabs = 8 

Sample run #2:

Enter dimension of tray: 60 35
Enter dimension of slab: 6 8
Maximum number of slabs = 40 

3.4 Skeleton program and Test data

3.5 Important notes

3.6 Estimated development time

The time here is an estimate of how much time we expect you to spend on this exercise. If you need to spend way more time than this, it is an indication that some help might be needed.

3.7 Exploration

Here are some possible extensions of the problem for you to try on your own. You do NOT need to submit them.

4 Deadline

The deadline for submitting all programs is 6 September 2017, Wednesday, 5pm. Late submission will NOT be accepted.




Last updated: 26 August 2017