PROGRAMMING TECHNIQUE I (C++) - people.utm.my · Dayang Norhayati Abang Jawawi Noraniah Mohd Yassin...

5
2nd Edition 2008 PROGRAMMING TECHNIQUE I (C++) •xJ T 00101010 •010101 01010010 10 . - Norazah Yusof Dayang Norhayati Abang Jawawi Noraniah Mohd Yassin Radziah Mohamad Paridah Samsuri Rohayanti Hassan Department of Software Engineering Faculty of Computer Science & Information Systems Universiti Teknologi Malaysia ESKTOP PUBLISHER

Transcript of PROGRAMMING TECHNIQUE I (C++) - people.utm.my · Dayang Norhayati Abang Jawawi Noraniah Mohd Yassin...

Page 1: PROGRAMMING TECHNIQUE I (C++) - people.utm.my · Dayang Norhayati Abang Jawawi Noraniah Mohd Yassin Radziah Mohamad Paridah Samsuri Rohayanti Hassan Department of Software Engineering

2nd Edition 2008

PROGRAMMINGTECHNIQUE I

(C++)

•xJ T00101010•010101

01010010

10 . -

Norazah YusofDayang Norhayati Abang JawawiNoraniah Mohd YassinRadziah MohamadParidah SamsuriRohayanti HassanDepartment of Software EngineeringFaculty of Computer Science & Information SystemsUniversiti Teknologi Malaysia

ESKTOPP U B L I S H E R

Page 2: PROGRAMMING TECHNIQUE I (C++) - people.utm.my · Dayang Norhayati Abang Jawawi Noraniah Mohd Yassin Radziah Mohamad Paridah Samsuri Rohayanti Hassan Department of Software Engineering

PROGRAMMING TECHNIQUE I

(C++)

Norazah Yusof

Dayang Norhayati Abang Jawawi

Noraniah Mohd Yassin

Radziah Mohamad

Paridah Samsuri

Rohayanti Hassan

Copyright © 2007, 2008

All rights reserved. No part of this publication may be reproduced or distributed inany form or by any means, or stored in a data base or retrieval system, or transmittedin any form or by any means, electronics, mechanical, photocopying or otherwise,without the prior written permission of the authors.

Disclaimer

This workbook and its contents are intended solely for the use of the subjectProgramming Technique I to be taught at Fakulti Sains Komputer dan SistemMaklumat, Universiti Teknologi Malaysia, Skudai. The algorithms and programs inthis workbook have been included for their instructional value. They have been testedbut are not guaranteed for any particular purpose. The authors do not offer anywarranties or representations nor do they accept any liabilities with respect to theiruse. The authors reserve the right to revise this publication and make changes fromtime to time in its content without notice.

Second EditionJune 2008

Page 3: PROGRAMMING TECHNIQUE I (C++) - people.utm.my · Dayang Norhayati Abang Jawawi Noraniah Mohd Yassin Radziah Mohamad Paridah Samsuri Rohayanti Hassan Department of Software Engineering

CONTENTS

LAB TOPIC

INTRODUCTIONTERMS

1 RUNNING THE C++ PROGRAM

Objectives For StudentsAssumptionsLab Exercises :

Exercise 1Exercise 2Exercise 3

2 DESIGNING PSEUDO CODE AND FLOWCHART USING MOROSOFT WORD

Objectives For StudentsAssumptionsLab Exercises :

Exercise 1Exercise 2Exercise 3Exercise 4Exercise 5Exercise 6

3 DESIGN PSEUDO CODE / FLOW CHARTUSING MICROSOFT

Objectives For StudentsAssumptionsLab Exercises :

Exercise 1Exercise 2Exercise 3

4 CONVERTING ALGORITHM TO C++ CODE

Objectives For StudentsAssumptionsLab Exercise :

Exercise 1Exercise 2Exercise 3

PAGE

vvii

11

1911

17

1717

172023262830

31

3131

313639

41

4141

414243

11

Page 4: PROGRAMMING TECHNIQUE I (C++) - people.utm.my · Dayang Norhayati Abang Jawawi Noraniah Mohd Yassin Radziah Mohamad Paridah Samsuri Rohayanti Hassan Department of Software Engineering

WORKING WITH DATA 45

Objectives For Students 45Assumptions 45Lab Exercise :

Exercise 1 45Exercise 2 46Exercise 3 47Exercise 4 48Exercise 5 49Exercise 6 50

INPUT & OUTPUT 51

Objectives For Students 51Assumptions 51Lab Exercise:

Exercise 1 51Exercise 2 52Exercise 3 53Exercise 4 54Exercise 5 55Exercise 6 56

SELECTION OR DECISION 59

Objectives For Students 59Assumptions 59Lab Exercise :

Exercise 1 59Exercise 2 60Exercise 3 62Exercise 4 63Exercise 5 65Exercise 6 66Exercise 7 67

LOOP 71

Objectives For Students 71AssumptionsLab Exercise :

Exercise 1 72Exercise 2Exercise 3Exercise 4 76Exercise 5Exercise 6Exercise 7Exercise 8Exercise 9

111

Page 5: PROGRAMMING TECHNIQUE I (C++) - people.utm.my · Dayang Norhayati Abang Jawawi Noraniah Mohd Yassin Radziah Mohamad Paridah Samsuri Rohayanti Hassan Department of Software Engineering

Exercise 10 82

9 NESTED LOOP

Objectives For StudentsAssumptionsLab Exercise :

Exercise 1Exercise 2Exercise 3Exercise 4

10 PREDEFINED FUNCTIONS

Objectives For StudentsAssumptionsLab Exercise :

Exercise 1Exercise 2Exercise 3

85

8585

85878889

91

9191

919293

11 USER-DEFINED FUNCTION

Objectives For StudentsAssumptionsLab Exercise :

Exercise 1Exercise 2Exercise 3Exercise 4Exercise 5Exercise 6

12 ONE-DIMENSIONAL ARRAY

Objectives For StudentsAssumptionsLab Exercises:

Exercise 1Exercise 2Exercise 3

13 TWO-DIMENSIONAL ARRAY

Objectives For StudentsAssumptionsLab Exercises :

Exercise 1Exercise 2

95

9595

9596101103

107

111

111111

111115117

121

121121

121124

IV