0% found this document useful (0 votes)
30 views

CMP102 - Lecture Note - OD

This document provides an overview and study guide for the course CMP102: Introduction to Programming at Olabisi Onabanjo University. The course is a 2-unit foundational programming course that introduces students to computational problem solving techniques and fundamental programming concepts like data structures, algorithms, and programming logic. Over the course of 13 study sessions, students will learn how to represent and manipulate data, solve problems using programming, and evaluate the efficiency of different algorithms. Assessment includes tutor-marked assignments and a final exam worth 30% and 70% respectively. The goal is for students to learn programming skills and be able to apply data structures and algorithms to computational problems.

Uploaded by

Ezekiel James
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

CMP102 - Lecture Note - OD

This document provides an overview and study guide for the course CMP102: Introduction to Programming at Olabisi Onabanjo University. The course is a 2-unit foundational programming course that introduces students to computational problem solving techniques and fundamental programming concepts like data structures, algorithms, and programming logic. Over the course of 13 study sessions, students will learn how to represent and manipulate data, solve problems using programming, and evaluate the efficiency of different algorithms. Assessment includes tutor-marked assignments and a final exam worth 30% and 70% respectively. The goal is for students to learn programming skills and be able to apply data structures and algorithms to computational problems.

Uploaded by

Ezekiel James
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

CMP102: Introduction to Programming

OLABISI ONABANJO UNIVERSITY


AGO-IWOYE, NIGERIA

FACULTY OF SCIENCES
DEPARTMENT OF MATHEMATICAL
SCIENCES

CMP 102: Introduction to Programming I

Course Lecturers - Dr T. J. Odule and Banjo O.


CMP102: Introduction to Programming

Course Study Guide

Introduction
Potential students of this class are welcomed. CMP102 is a foundational course for students
studying towards acquiring the Bachelor of Science in Computer Science degree. In this
course we would study data structure and the basic algorithms for manipulating them.
The aim of the course is to introduce students to programming and computational problem
solving and techniques. Topics relating to Basics of programming, flow charts and algorithms
are discussed. A bottom-up approach was adopted in structuring this course. It starts from the
building blocks of programming, then the fundamental principles of problem-solving using
computers.
This course is about learning to solve problems, not learning facts. This course compulsory
for all students in the Department of Computer Science and elective for other students in the
faculty of science. In view of this, students are expected to participate in all the activities and
have a minimum of 75% attendance to be able to write the final examination. The course is
divided into 13 study sessions or modules.

Recommended Study Time


This course is a 2-unit course divided into 13 study sessions. You are to spend at least 2 hours
to study the content of each study session.

What you are about to learn in this course


The overall aim of this course is to introduce you to the fundamentals of computer
programming in solving basic computational problems. We would be mostly making use of
Basic for implementation.

Course Aim
This course aims to provide foundation to students with an understanding on how ot solve
computational problems using computer programs.

Course Objectives
It is important to note that each session has specific objectives. Students should study them
carefully before proceeding to subsequent sessions. Therefore, it may be useful to refer to
CMP102: Introduction to Programming
these objectives in the course of your study of the session to assess your progress. You should
always look at the unit objectives after completing a session. In this way, you can be sure that
you have done what is required of you by the end of the study session.

At the end of the course, students should be able to:

1. Describe the basic operations on stacks, lists and queue data structures
2. Explain the notion of trees, hashing and binary trees
3. Discuss the underlying principles of data types: lists, stacks and queues
4. Describe structures and algorithms for external storage: external sorting, external
search trees.
5. Identify directed and undirected graphs
6. Discuss sorting: internal and external sort
7. Efficiency of algorithms, recursion and recursive programmed
8. Discuss the algorithm design techniques: greedy algorithms, divide and conquer,
dynamic programming

Working through this course


In order to have a thorough understanding of the course units, you will need to read and
understand the contents and practise all the discussions in each of the modules. This course
covers approximately thirteen (13) weeks and it will require your devoted attention.

Recommended Texts
The following texts and Internet resource links will be of enormous benefit to you in learning
this course:

1. Narasimha K. 2017, “Data Structures and Algorithms Made Easy”, publisher:


CareerMonk Publications
2. Necaise R. D. 2011, “Data Structures and Algorithms Using Python”, publisher: John
Wiley & Sons, Inc.
3. Goodrich, M. T., Tamassia R., Goldwasser, M. H. 2013, Data Structures and Algorithms
in Python. Wiley & Sons, Inc.
4.
CMP102: Introduction to Programming

Assessment
There are two aspects to the assessment in this course: tutor-marked assignments and written
examination. Therefore, you are expected to take note of the concepts, information and
problem-solving procedure gathered during the course. The tutor-marked assignments must
be submitted to your tutor for formal assessment in accordance to the deadline given. The
work submitted will count for 30% of your total course mark. At the end of the course, you
will need to sit for a final written examination. This examination will account for 70% of
your total score. You will be required to submit some assignments by uploading them to
CMP 206 page on the LMS.

Tutor-Marked Assignment (TMA)


There are TMAs in this course. You need to submit all the TMAs while the best 10 will be
counted. When you have completed each assignment, send it to your tutor as soon as possible
CMP 102 – Introduction to Programming and be certain that it gets to your tutor on or before
the stipulated deadline. If for any reason you cannot complete your assignment on time,
contact your tutor before the assignment is due to discuss the possibility of extension.
Extension will not be granted after the deadline unless an extraordinary case can be
established.

Final Examination and Grading


The final examination for CMP 102 will last for a period not more than 2hours and has a
value of 70%. The examination will consist of questions which reflect the Self-Assessment
Questions (SAQs), In-text Questions (ITQs) and tutor-marked assignments that you have
previously encountered. Furthermore, all areas of the course will be examined. It would be
better to use the time between finishing the last unit and sitting for the examination to revise
the entire course. You might find it useful to review your TMAs and comment on them
before the examination. The final examination covers information from all parts of the
course. Most examinations will be conducted via Pen-On Paper (POP) and Computer-Based
Testing (CBT) modes.

Tutors and Tutorials


CMP102: Introduction to Programming
There are a few hours of face-to-face tutorials provided in support of this course. You will be
notified of the dates, time and location together with the name and phone number of your
tutor as soon as you are allocated a tutorial group. Your tutor will mark and comment on your
assignments, keep a close watch on your progress and on any difficulties, you might
encounter and provide assistance to you during the course. You must submit your tutor-
marked assignments to your tutor well before the due date. At least two working days are
required for this purpose. They will be marked by your tutor and returned as soon as possible
via the same means of submission.
Do not hesitate to contact your tutor by telephone, e-mail or discussion board if you need
help. The following might be circumstances in which you would find help necessary. Contact
your tutor if:
1. You do not understand any part of the study units or the assigned readings.
2. You have difficulty with the self-test or exercise.
3. You have questions or problems with an assignment, with your tutor’s comments on an
assignment or with the grading of an assignment.

You should endeavour to attend the tutorials. This is the only opportunity to have face-to-face
contact with your tutor and ask questions which are answered instantly. You can raise any
problem encountered in the course of your study. To gain the maximum benefit from the
course tutorials, have some questions handy before attending them. You will learn a lot from
participating actively in
CMP102: Introduction to Programming
Study Session One: Introduction to Computers and
Programming
Introduction

The set of instructors that control the computer is called a program. A program can be
executed by the computer only when it is stored in the computer’s memory and is in
machine language code.

Objectives

When you have studied this session, you should be able to:

1. Understand the concept of data type, abstract datatype and data structure.

2. Highlight the different types of data

3. Provide examples of data types

4. Highlight the relevance of data structure to programming

Content

What is computer
Computers are automatic machines that can accept data, store vast amounts of
information and perform arithmetic at high speeds to solve complex machines

Computer program
The computer may be thought of as a system composed of five components. The
components and their functions are as follows:
1. The Input Unit: This unit feeds information from the outside world to the
computer. Input units are capable of reading information recorded on such
different mediums as punched cards or magnetic tape or from terminals. The
information read from these devices is placed into appropriate memory locations.
2. The Memory Unit: The memory unit stores information. It holds the sequence of
instructions necessary to solve particular problem and any additional data
required. The memory is divided into locations that each have an address (are
addressable). Instructions are stored in these cells.
3. The Control Unit: The control unit fetches the instructions and data from
memory and executes the instructions one at a time with logical unit. All of the
CMP102: Introduction to Programming
other components operate as directed by the control unit.
4. The Arithmetic/Logical Unit: The arithmetic/ logical unit consists of the
electronic circuitry that performs arithmetic operations such as comparison of
numbers.
5. The Output Unit: The output unit transfers or copies the contents of certain
memory locations onto some external medium such as punched cards, punched
paper tape, magnetic tape, a printed page produced by a teletype or line printer, or
a cathode ray tube (CRT) screen for visual display.
The memory, control and arithmetic/ logical units are collectively called the
central processing unit (CPU).

Categories of Programming Languages


Machine or Low Level Language
They are low level interface native or natural to the hardware of the computer. Its
communication symbols consists of series of 0’s and 1’s otherwise known as binary
digits (BIT). Every computer model has its own machine language, which is defined
by its hardware structure. Thus this language depends on the particular computer
model, hence it is described as machine independent. Early days of computer
programming entails machine language instructions strictly. Difficulty in
programming at machine level led to the development of symbolic languages and later
high level languages.
Symbolic Language
This is a mid level language between machine language and high level languages.
This language adopted mnemonic codes to represent machine instructions. The use of
mnemonic codes imply that mnemonic names are used for operators, addresses and
instructions. Ordinarily, the computer does understand this codes except they are
translated to machined language using appropriate translator. Symbolic are also
machine independent because a set of mnemonics is only applicable to a particular
hardware type. A very good example of Symbolic Language is Assembly Language.
To translate an assembly language to machine language an assembler is required. An
assembler is a machine language program that translates symbolic instructions into
machine language.
High Level Language
During the 1950s, high level computer languages evolved to describe problems
independent of their machine code of a particular computer. High level languages
(also known as problem-oriented languages) use English like phrases to represent
computer instructions. In this way, a programmer writes computer instruction in a way
that is close to his thinking process using English like expressions. The language is
procedure oriented rather than machine oriented. It focuses on data processing
procedure to be accomplished rather than the coding requirements of a particular
computer machine. Thus, it is machine independent. Examples are BASIC, COBOL,
C, PASCAL, FORTRAN, ETC,
CMP102: Introduction to Programming
Programmes written in high level language must be converted to Machine language
for the computer to be able to execute it.
We have two types of converters
Compiler
Interpreter

Interpreters

Some languages are interpreted. The translator processes the source code line by line and
runs every line in the final program or app. This means that interpreted source code starts
running until it encounters an error. Then the interpreter stops to report such errors. Python is
a good example of an interpreted programming language.

Compilers

Compilers function differently. They convert the source code in its entirety via a compilation
process to binary. The binary is then executed. If there were errors in the source code, they
are detected during the compilation time and flagged. This interrupts the compilation process,
and no binary is generated.

EXAMPLE MACHINE LANGUAGE

Machine Instruction Machine Operation


00000000 Stop Program
00000001 Turn bulb fully on
00000010 Turn bulb fully off
00000100 Dim bulb by 10%
00001000 Brighten bulb by 10%
00010000 If bulb is fully on, skip over next instruction
00100000 If bulb is fully off, skip over next instruction
01000000 Go to start of program (address 0)

Sample program

1. INPUT A
2. INPUT B
3. LET C = A + B
4. PRINT C
5. END
CMP102: Introduction to Programming
PROGRAMMING TOOLS

Definition of Algorithm

To write a logical step-by-step method to solve the problem is called algorithm, in other
words, an algorithm is a procedure for solving problems. In order to solve a mathematical or
computer problem, this is the first step of the procedure. An algorithm includes calculations,
reasoning and data processing. Algorithms can be presented by natural languages, pseudo
code and flowcharts, etc.

Definition of Flowchart

A flowchart is the graphical or pictorial representation of an algorithm with the help of


different symbols, shapes and arrows in order to demonstrate a process or a program. With
algorithms, we can easily understand a program. The main purpose of a flowchart is to
analyse different processes. Several standard graphics are applied in a flowchart:

 Terminal Box - Start / End

 Input / Output

 Process / Instruction

 Decision

 Connector / Arrow
CMP102: Introduction to Programming

The graphics above represent different part of a flowchart. The process in a flowchart can be
expressed through boxes and arrows with different sizes and colours. In a flowchart, we can
easily highlight a certain element and the relationships between each part.

How to Use Flowcharts to Represent Algorithms

Now that we have the definitions of algorithm and flowchart, how do we use a flowchart to
represent an algorithm?

Algorithms are mainly used for mathematical and computer programs, whilst flowcharts can
be used to describe all sorts of processes: business, educational, personal and of course
algorithms. So, flowcharts are often used as a program planning tool to visually organize the
step-by-step process of a program. Here are some examples:

Example 1: Print 1 to 20:

Algorithm:

Step 1: Initialize X as 0,

Step 2: Increment X by 1,

Step 3: Print X,

Step 4: If X is less than 20 then go back to step 2.

Flowchart:
CMP102: Introduction to Programming

Example 2: Convert Temperature from Fahrenheit (℉) to Celsius (℃)

Algorithm:

Step 1: Read temperature in Fahrenheit,

Step 2: Calculate temperature with formula C=5/9*(F-32),

Step 3: Print C,

Flowchart:
CMP102: Introduction to Programming

Conclusion

From the above we can come to a conclusion that a flowchart is pictorial representation of an
algorithm, an algorithm can be expressed and analysed through a flowchart.

An algorithm shows you every step of reaching the final solution, while a flowchart shows
you how to carry out the process by connecting each step. An algorithm uses mainly words to
describe the steps while a flowchart uses the help of symbols, shapes and arrows to make the
process more logical.

Assignment

1. State the categories of Programming Languages


CMP102: Introduction to Programming

2. Differentiate between compiler and Interpreter


3. What is the difference between Flow chart and Algorithm?
4. What are the basic shapes that are used for flow chart?
5. Design a flow chat and write an algorithm that can be used to calculate the
circumference of a circle.
CMP102: Introduction to Programming
Study Session Two: Introduction to Pure Basic
Introduction
PureBasic started life in 1995 as a command-set expansion for BlitzBasic after PureBasic’s author,
Frédéric Laboureur hit many limitations with BlitzBasic while programming an application called
‘TheBoss’, a powerful application launcher for the Commodore Amiga.

Objectives

When you have studied this session, you should be able to:

1. History of Pure Basic

2. Understand the Pure Basic IDE

3. Know how to run a simple Pure Basic Program

4. Understand the Concept of Debugging

Content
The early design and the first version of PureBasic started in 1998 and it was designed by Frédéric
Laboureur. The main differences between PureBasic and ‘normal’ compilers then was the inclusion of
a ‘virtual processor’ (which actually used the 680x0 assembly mnemonics) right from the start to
allow different kinds of assembly output (or any language) possible without changing the compiler
core. After the initial design was finished and programming began, things started to move very fast.
PureBasic files are saved as .pb.

Power Basic IDE


IDE means Integrated Development Environment, that of PowerBasic consists of source code editor, a
visual form designer and a compiler. However most times the source code editor is simply referred to
as the IDE while the Visual Form Designer is often called VD.
CMP102: Introduction to Programming

The IDE
The IDE (Fig. 1) is written entirely in PureBasic and is the main tool used to write PureBasic
programs, so let’s take a tour around the main interface of the editor.

At the top is the menu bar giving access to the menu commands, below that is a customizable toolbar
which can be configured to hold many different icons each triggering a pre-defined menu command.

Underneath the toolbar on the left is the main editor pane, here all PureBasic code is entered.

On the right of the editor pane is another user customized pane which can contain a procedure viewer,
a variable viewer, a file explorer, etc...

Also, by default the error/compiler activity log will be shown as a pane attached to the bottom of the
editor pane, this can be turned off and on via a menu command (Menu: Debugger->Error Log->Show
Error Log).

Below the panes there is the status bar which shows information on what row and column is being
edited and displays the quick help.

The Compiler
This editor is a ‘front-end’ to the actual PureBasic compiler. Once code has been entered into the
editor pane and the ‘Compile/Run’ toolbar button has been pressed (Shortcut Key: F5) the code is
then passed to the compiler for the creation of an executable.

How To Run PureBasic Programs


PureBasic programs are just plain text files (usually containing the suffix ‘*. pb’) that contain the
actual PureBasic code. All that needs to be done to compile these text files into an executable program
is to pass them to the compiler for processing.
In the IDE:
Press the ‘F5’ keyboard shortcut for ‘Compile/Run’.
Press the ‘Compile/Run’ toolbar button.
Select the menu command: ‘Compiler->Compile/Run’.
Select the menu command: ‘Compiler->Create Executable...’.
Using the command line:
Enter the command: ‘PBCompiler filename’ where ‘filename’ is the name of the text file.
CMP102: Introduction to Programming
The first three IDE methods mentioned above, achieve the same result and any one of these three can
be used while actually writing and testing the current program (it doesn’t matter which one). The
purpose of these three commands is in the name, ‘Compile/Run’.

When selected the text file is immediately compiled into a temporary executable file called
‘purebasic0.exe’ within the ‘/PureBasic/Compilers’ folder and that executable file is then run. This is
handy when you need to see immediately how your program runs, without specifying a proper name
for the compiled executable. If this temporary program file is still running while another program is
compiled and run, then a new temporary file will be created called ‘purebasic1.exe’, and so on. If,
however the first program has ended while using the ‘Compile/Run’ method, then the compiler reuses
old numbers on the temporary files and keeps on using ‘purebasic0.exe’ as the temporary name. This
makes sure that there aren’t huge numbers of temporary executable files within the
‘/PureBasic/Compilers’ folder.

The last IDE method, using the ‘Compiler->Create Executable...’ menu command is for when all
development is finished on the current program and you are ready to compile and deploy your
executable file. Once this menu command has been selected a dialog box appears asking you to specify
a name and location for your final executable program file.

The Debugger
The PureBasic debugger is a tool which controls the execution of the program you’re working on. It
controls and keeps track of all variables and procedure parameters, etc. as the program is running. It
is a second pair of eyes on your code to highlight errors and to avoid potential program crashes such
as zero division, illegal array offset access and data overflow errors. It can also be used as a brake to
halt the program at any given time to see what actual variable values are. The program execution can
be stopped and forwarded step by step to locate any faults or strange behaviour. This can be very
useful especially if a program falls into an endless loop or you are unsure of what value a particular
variable holds at any given time.

Our very first PureBasic Program

OpenConsole()
Print("Hello World")
Print("My name is Taiwo")

Input()
End
The compiler processes the text file from the top to the bottom. It’s that easy. Commands written at
the top of the file are processed before the ones written below, just as if you were reading the file
yourself. If the debugger spots a problem the compilation is stopped and an error is raised.

Assignment

1. State the categories of Programming Languages


2. Differentiate between compiler and Interpreter
3. What is the difference between Flow chart and Algorithm?
4. What are the basic shapes that are used for flow chart?
5. Design a flow chat and write an algorithm that can be used to calculate the
circumference of a circle.

You might also like