0% found this document useful (0 votes)
71 views2 pages

ECP1016 - Computer and Program Design: Tutorial 3 Control Program (Selection Structure)

This document outlines the topics and assignments for a tutorial on control programs and selection structures in C programming. Section A instructs students to familiarize themselves with if, if-else, and switch statements before the tutorial. Section B provides three programming assignments involving selection structures, including determining multiples of 5, identifying keys pressed, and building a basic calculator. Section C assigns a post-tutorial program to calculate discounted prices based on color codes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views2 pages

ECP1016 - Computer and Program Design: Tutorial 3 Control Program (Selection Structure)

This document outlines the topics and assignments for a tutorial on control programs and selection structures in C programming. Section A instructs students to familiarize themselves with if, if-else, and switch statements before the tutorial. Section B provides three programming assignments involving selection structures, including determining multiples of 5, identifying keys pressed, and building a basic calculator. Section C assigns a post-tutorial program to calculate discounted prices based on color codes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

ECP1016 - Computer and Program Design

(T1-2014/2015)

Tutorial 3
Control Program (Selection Structure)



Section A: Student Self Learning, reading and Preparation before the tutorial

1. Familiarize with the syntax of the selection structures in C, i.e., the if, if-else and switch
statements.

2. Self-Reading Materials
http://begincprogram.blogspot.com/2009/05/tutorial-51-if-selection-structure.html
http://www.cs.cf.ac.uk/Dave/C/node5.html#SECTION00500000000000000000


Section B: Tutorial Questions or Assignments during the lab

1. Design a program that inputs an integer number from the user and determines if the integer is a
multiple of 5.

a) Draw a flowchart of this program
b) Write a complete C program using if-else statement.
c) Replace the if-else statement in part (b) with a switch statement.

2. Write a C program that receives a key-pressed by the user, and determines if the key entered is a
numeric digit, alphabet (uppercase or lowercase) or other character.

3. Write a complete C program to implement the functions of a calculator. The calculator is limited
for some simple arithmetic operations such as addition, subtraction, multiplication and division.
Upon receiving two real numbers and a valid arithmetic operator, the calculator displays the result of
the computation. An error message should be printed if an invalid operator has been entered.











Section C: Post Tutorial Questions or Assignments

1. Write a C program (Using nested if-else and switch statements) that computes the new
price of an item. The program should receive a character variable colour and a double
precision floating-point variable price from the user. Discount rate is determined based on
the colour of the discount sticker, as shown in the following table:
[5 marks]




Sl. No Colour Discount rate
1 Red (R or r) 20%
2 Green (G or g) 15%
3 Blue (B or b) 10%

You might also like