Ad130220 Cpp Lab Sheet 2

6
UNIVERSITI TUN HUSSEIN ONN MALAYSIA FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING COMPUTER PROGRAMMING (BDA 24202) LAB SHEET 2 Computer Programming Basics NAME : _________________________________ MATRICS NO.: _______________ DATE : _________ (MARKS) Objectives: Learn to write pseudo code Learn to draw flow chart NG YING KHIAN AD130220 (SEKSYEN 2) © NG YING KHIAN AD 130220 9/3/2015

description

aaa

Transcript of Ad130220 Cpp Lab Sheet 2

Page 1: Ad130220 Cpp Lab Sheet 2

UNIVERSITI TUN HUSSEIN ONN MALAYSIAFACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING

COMPUTER PROGRAMMING (BDA 24202)

LAB SHEET 2

Computer Programming Basics

NAME : _________________________________

MATRICS NO.: _______________ DATE : _________ (MARKS)

Objectives:

Learn to write pseudo code Learn to draw flow chart

NG YING KHIAN AD130220 (SEKSYEN 2) ©

NG YING KHIAN

AD 130220 9/3/2015

Page 2: Ad130220 Cpp Lab Sheet 2

UNIVERSITI TUN HUSSEIN ONN MALAYSIAFACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING

COMPUTER PROGRAMMING (BDA 24202)

Question 1

a) The purpose of the program is to print Welcoming text on screen when the program is run.“Variables”—do not have any variables in this program“Input”—do not required any input for this program“Output”—display a welcome text on screen by preprocessor directives printf (“_____”) “ ; ” — Punctuation “\n” — new line

b) /* The purpose of the program is to print text on screen when run.*/

#define MESSAGE “Welcome to this computer programming class!\n”

main( )

{

printf(MESSAGE);

}

c) main( ){

float gross, tax, net; \\ Declarations of Variables

\\ Statementsprintf(“Gross salary: “); scanf(“%f”, &gross); \\ Inputtax = 0.14*gross;net = gross – tax;printf(“Taxes withheld: %.2f\n”, tax); \\Output

NG YING KHIAN AD130220 (SEKSYEN 2) ©

Output

Pre-define

New li

Page 3: Ad130220 Cpp Lab Sheet 2

Display “By bus”

Display “Own Transport”

If “c” then Display “By walking”

UNIVERSITI TUN HUSSEIN ONN MALAYSIAFACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING

COMPUTER PROGRAMMING (BDA 24202)

Question 2

i) Flow chart

NG YING KHIAN AD130220 (SEKSYEN 2) ©

Start

Set ‘a’= Bus‘b’= own transport‘c’= by walking

If ‘a’

ii) Pseudo code

1. Start

2. Display “ How do you go lecture from your house?”

‘a’= Bus‘b’= own transport‘c’= by walking

3. Input ‘a’ or ‘b’ or ‘c’4. Print output5. Ends

If ‘b’

End

Page 4: Ad130220 Cpp Lab Sheet 2

Start

Enter a value for the principal (p)

Enter value for the interest rate (r)

Enter value for the num. of years (n)

Calculate i=r/100f= p*pow((1+i),n)

Display final value f=_____

End

UNIVERSITI TUN HUSSEIN ONN MALAYSIAFACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING

COMPUTER PROGRAMMING (BDA 24202)

Question 3

NG YING KHIAN AD130220 (SEKSYEN 2) ©