THE OPEN UNIVERSITY OF TANZANIA FACULTY OF SCIENCE, TECHNOLOGY AND ENVIRONMENTAL STUDIES ODM 103: INTRODUCTION TO COMPUTER PROGRAMMING LANGUAGES Said Ally i
ODM 103 INTRODUCTION TO COMPUTER PROGRAMMING LANGUAGES Said Ally Lecturer The Open University of Tanzania The Open University of Tanzania Biafra Grounds, Kawawa Road P. O. Box 23409, Dar Es Salaam, Tanzania ii
The Open University of Tanzania Kawawa Road - Next to Biafra Grounds P.O. Box 23409, Dar Es Salaam, Tanzania. The Open University of Tanzania, 2015 ISBN FIRST EDITION, 2015 All Rights Reserved. No part of this publication may be reproduced, stored, in a retrieval system or transmited in any form or by any means; electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the copyright owner i.e. The Open University of Tanzania. iii
ODM 103: Introduction to Programming Languages Course Status: Core Number of Credits: 10 Total hours spent: 53 Pre-requisite: None iv
Why Learn Computer Programming Languages? You may already have used software, perhaps for word processing or spreadsheets, to solve problems. Perhaps now you are curious to learn how programmers write software. A program is a set of step-by-step instructions that directs the computer to do the tasks you want it to do and produce the results you want. There are at least three good reasons for learning programming: (i). Programming helps you understand computers. The computer is only a tool. If you learn how to write simple programs, you will gain more knowledge about how a computer works. (ii). Writing a few simple programs increases your confidence level. Many people find great personal satisfaction in creating a set of instructions that solve a problem. (iii). Learning programming lets you find out quickly whether you like programming and whether you have the analytical turn of mind programmers need. Even if you decide that programming is not for you, understanding the process certainly will increase your appreciation of what programmers and computers can do. v
Unit Introduction Dear learner Welcome to programming world; it is pleasure to have you in this class of ODM 103 (Introduction to Computer Programming Languages). I am excited to share the bolts and nuts of programming languages, a subject of interest in recent years. In fact, you are joining a course that has attracted most of the software developers and computer programmers in IT industry. I am delighted that you are joining us at this course after having used computer in various applications. This course is 1 Unit and so it is organized into ten lectures. In Lecture One, you are introduced to the concepts of software engineering with main focus on software process models and activities, the open source software development, distributed software engineering, client-server architecture and embedded software. In Lecture Two, you will explore some of the basic concepts lower level programming languages and their features. The lecture will cover programming at abstract level of microprocessors using both machine and assembly language programs and the instruction set architectures. In Lecture Three, you will explore some of the basic concepts of the Programming languages and their features. The main focus are on introduction to the various forms of programming languages, software compilers, editors and interpreters, the procedures for program development, the basic structure of a typical program, programming language comments, program identifiers and reserved words, program syntax and semantics, programming errors such as compile-time errors, run-time errors and logical errors and lastly the detailed explanation of the American Standard Code for Information Interchange (ASCII) and the Unicode Character Set (UCS). vi
In Lecture Four, you are provided with very critical concepts of any programming (preferably C++) language. This includes concepts of data types, expressions and (conditionals) decision statements in programming. It will include declaration of variables, constants and assignments. You will explore the assignment operators, the increment and decrement operators, the arithmetic, unary, binary operators and their precedence. Lastly, a discussion on data conversion and their techniques are described. Lecture Five contains conceptual discussion on the programming loops and arrays. In Lecture Six, you are introduced on how to program GUIs and concepts WebPages. Lecture Seven provides you with overview of structured programming and their examples. Lecture Eight provides you with overview of object oriented programming (OOP) & unified modeling languages (UML). Various OOP concepts and UML diagrams will be elaborated with examples. Lecture Nine contains extensive coverage of database and network programming. Finally, Lecture Ten covers how to build a secure program. At a very last part of this study material, you will find a list of glossaries related to computer programming concepts for mutual understanding of the terms used in this material. vii
Course Assessment The main objective of this course is to introduce you to computer programming skills and apply them to create computer software. More generally, on the completion of this course, you should be able to use various software engineering techniques and apply them with any programming language (with more preference in C++ programming language) to design any application software. The course is delivered through Open and Distance Learning (ODL) mode with intensive face to face sessions and practical demonstrations in the computer laboratory. The course is a level ONE course intended for BSc in Data Management first year students. It is a one-unit course equivalent to 10 lectures (35 are lecture hours and 18 practical hours). The assessment procedures and criteria for this course follow the standard OUT examination regulations for undergraduate courses. The following regulations based on three assessment marking criteria shall apply for the assessment of the course: Practical Demonstrations 20% Main Timed Test (MTT) 30% Annual Examination (AE) 50% The MTT shall be assessed in lectures 1 through 5 and AE shall cover the whole study material from lecture 1 through 10. Considering the fact that we use ODL mode to deliver our learning materials, throughout the course, you will find different symbols summarized below: This symbol appears with each list of objectives. At the beginning of each lecture there is a set of objectives, which tell you what you should be able to do once you have completed the lecture. viii
? This symbol tells you that you should take note. Throughout the unit, when you are asked to remember something important, you will see this symbol. It is also meant to emphasize an idea or a concept. You should write the point down. This symbol tells you that this is an activity. An activity helps you to find out if you have understood what you have just read in the lecture. An activity may ask you to relate what you have read real life situation, or lead you to think about what is coming in the next paragraph. This symbol tells you that the text you read is a summary of a section, lecture or any portion of the unit. Some activities may take the form of self-tests. Self-tests are practice exercise which enable you to test how well you have understood the content of a section. Make sure you try all questions in each self-test. Be honest with yourself so that you can find out what you know and what you don t know. The answers may be found at the end of the unit or through reading the text. This is the symbol which you will find beside a list of books for further reading. You should try to obtain and read as many books as possible in the suggested list of essential and recommended reading. The main thrust of the course is directed towards learning the fundamental tools in designing and implementing computer programs. In each section, you are provided with a programming exercise which you should make sure that you write it, compile and run before moving to next section. While you are running the programs in the compiler, try as much as possible to change parameter values and observe the results displayed in the GUI window. We strongly advise and recommend you to attempt all review questions at the end of each lecture so that you can be able to assess the level of understanding and competency in each specific part of the course. To widen up your programming knowledge, it is recommended that you visit all listed references appeared at the end of each lecture. Lastly, we welcome you again in this amazing programming language. ix
Course Syllabus/Indicative Content The following areas are covered: i. Introduction to Software Engineering (overview of software engineering, ethics in software engineering, software processes, software process models, software process activities, the open source software development, distributed software engineering, distributed system issues, client-server computing, and embedded software. ii. Basic concepts of Object Oriented Programming (the OOP software principles, object, method, class, abstraction, inheritance, overriding, polymorphism, encapsulation, interfaces, packages). iii. UML diagrams (usecase diagram, class diagram, relationships: association, aggregation, composition, generalization, realization, and dependency, interaction diagrams: sequence diagrams and collaboration diagrams, state diagrams, activity diagrams, UML software: MS Visio, StarUML, Umbrello UML Modeler, ArgoUML). iv. Introduction to programming languages (JAVA, C, C++, PASCAL, PHP, etc), forms of a language, compilers, editors and interpreters, syntax and semantics, program errors, comments, identifiers and reserved words, the ASCII and UCS characters sets). v. Data types and expressions (escape sequences, primitive and object data types, numerical variable declaration, variables constants and assignments, the assignment operators, the increment and decrement operators, expressions, the arithmetic operators, unary and binary operators, data conversion, narrowing and widening conversions). vi. Writing interactive programs and constructors). vii. Strings, Conditionals statements (logical operators, operator s precedence, ifstatement, if-else statement, nested if statement, switch statement, data compariso). x
viii. Programming loops (while statement, do statement, for statement, nested loop, infinite loop). ix. Programming arrays (strength of arrays, array declaration, allocate array object with new keyword, determine the array length, the subscript/index of array, arrays of string, arrays of objects, passing array by reference, 2D arrays, the common array problems). x. GUIs (principles of good GUI designs and coordinate system, use of colors and drawing shapes, GUI containers, frames, panels, nested panels, images, buttons, password fields, text fields, determining event sources, dialog boxes, check boxes, radio buttons, layout managers, borders, containment hierarchies, events, mouse events and mouse listeners). xi. Network and Database programming. xii. Inheritance and Polymorphism xiii. Programming exceptions. xiv. Recursion, Collections and Data Structures xv. Secure Programming (enhancing security of your program). Generally more concentration will be on C++ programming language focusing on basic elements of a computer (hardware and software, Computer organization), Principles of programming (Overview of programming languages), Overview of Software Development, and Phases in the Execution of a Computer Program, Overview of Problem-Solving Techniques, and Overview of Program Types, Fundamentals of C programming(anatomy of a C program, Program layout and syntax rules), Fundamentals of C++ programming (Anatomy of a C++ program,program layout and syntax rules) and Sources and types of programming errors: syntax errors, run-time errors and logic errors. xi
Course Rationale This course is the introduction to programming languages which will provide students with the basic concepts of programming needed to gain knowledge of methods used to solve real life computer problems. It will enable them to become comfortable with the use of computer and more aware of program in driving computer hardware Course Aim This course aimed for students with little or no prior knowledge of programminglanguage experience, but required to learn and understand computational approaches to problem solving. Since computer programming involves computational modes of thinking, it will help to have some mathematical and logical aptitude. Learning Outcomes Upon completion of the course a student should be able to: i. Demonstrate the ability to use different data types in expressions in simple computer programs. ii. Demonstrate the ability to use control structures and simple algorithms in computer programs. iii. Use a variety of problem-solving strategies to solve different types of problems iv. Design software solutions to meet a variety of challenges, using a set of standards. v. Apply a software development life-cycle model to a software development project. xii
vi. Demonstrate an understanding of the differences between object oriented and procedural programming languages and recognize appropriate uses of each. Course Content Indicative Reading List i. Deitel.P, Harvey. M.(2001), C how to program,3rd edition, Prentice Hall ii. Bansal.A.K (2013), Introduction to Programming Languages, 1 edition, Chapman and Hall/CRC iii. Perry.G and Miller.D (2013),C Programming Absolute Beginner's Guide, 3rd edition, Que Publishing xiii
If You Have Never Programmed Before Although some students will have some previous programming experience, this may be your first exposure to programming. Therefore, I am providing you with some fundamental prerequisite concepts required for any programming language. In particular, you need to understand general skills for problem solving and program development. The concepts of algorithms, assignments, data types, data structures, arrays and sequences, decisions and loops are vital. The decisions and loops will allow you to deviate from the sequential mode of operation during execution and vastly increase a program s power to solve numerical problems. To become a good programmer, you need to undertake as many programming exercises as possible and to spend most of your studying time playing and practicing compiler. Spending much time with a compiler, will give you exposure to write lots of code and this is one of the top secrets to become a full bright and competent programmer. Programming is an art, so once you have a small project, start reading other people's code. At first, it might be difficult as you may find things you haven't seen before, just pick one or two things that you wish you could learn how to do, and find out how they were done. Reading new code exposes you to ways of thinking that are new, and this helps stretch your brain. Stretching is vital to keeping up progress, and it will help ensure that as you go along you keep discovering new stuff to learn. Talk to other programmers too and ask how and why they did certain things. Finally, I advice you take part in online coding contests and participate in some Free Open Source Software (FOSS) projects. These are good for developing your algorithmic and programming skills and they may make you think fast. Don t waste time sharpening your pencil when you should be drawing. xiv
About the Author The author is a Lecturer in ICT and Computer Science working under the ICT department at the Faculty of Science, Technology & Environmental Studies. He also serves as Head of Department of Records and Qualifications in the Directorate of Examinations Syndicate and Coordinator of the ICT Security Management Research Group registered at the Open University of Tanzania (OUT). His area of expertise is in software security and software engineering. The author, educated at the University of Dar Es Salaam (BSc in Computer-2006) and at OUT (MSc in Computer Science-2011). In the University of Dar Es Salaam, the author grew up in atmosphere of science, taking both computer science and mathematics providing him valuable insight into the problem solving; mathematical algorithms and modeling, science data analysis, programming, acquisition and IT project management skills. At OUT, he has developed skills in open source software security. He has participated in several software development projects for web systems involved intensive java programming and other open source tools. He has also participated in various consultancy works for writing IT strategies, security policies and operational procedures. One of his achievement is to become a member of the National Steering Committee for establishment of the rules and guidelines for the National Computer Emergency Response Team (TZ-CERT) coordinated by Tanzania Communications Regulatory Authority (TCRA). In various times, the author has experience in teaching the courses for Object Oriented Programming with JAVA, Computer Architecture, Information Systems Planning, Management and Security, Computer Graphics, Pascal Programming, Informatics and Cyber-ethics. Mr. Said Ally is also a course leader and has co-authored a university wide IT course OCP 100 - Introduction to Microcomputer Studies and IT Applications the IT course for non IT students. He also supervises student s final year projects in the field of software engineering and IT security. xv
1