CSC 201
COMPUTER PROGRAMMING I
Course Lecturer:
AMINU MUSA
(musa.aminu@fud.edu.n
g)
Department of Computer Science
2022/2023
Course Objectives
This course will provide students with a
sound background on problem solving
methods and able to implement such
methods in program development with
programming language of choice.
Course Grading
Coursework: 2%
Test: 10 marks%
Starting Date: to be announced
Assignment: 10 marks%
Starting Date: 29th May 2023
Due Date: June 12th 2023
Practical : 10%
Exam: 70%
Course Outline
Introduction to Computer programming
Introduction to Problem Solving
methods
Algorithm development
Designing, coding, debugging and
decumenting programmes using
techniques of good programming
language and style
overview of Computer
A computer is an amazingly fast but incredibly
stupid machine.
A computer can do anything you tell it (within
reason), but it does exactly what it’s told —
nothing more and nothing less.
computers don’t understand any reasonable
human language — they don’t speak English
either.
Computers understand a language variously
known as computer language or machine
language.
It’s possible but extremely difficult for humans to
speak machine language.
Therefore, computers and humans have agreed
to sort of meet in the middle, using intermediate
languages such as C++, java, Fortran, Pascal
and so on.
Humans can speak C++ (sort of), and C++ is
converted into machine language for the
computer to understand.
What is Computer?
Different categories of people have different
definition of a computer.
To Childs, they defined computer as “a magic
box when it is loaded with a computer games”,
To Mathematician, they consider computer as
“number crunching machine”,
To Engineers they looked at computer as “
integration of transistor, resistors and other
electronic parts assembled together to execute
task”,
To a Students, they defined computer as “a tool
for completing an assigned work”.
In general, computer can be define as “an
electronic device that can accept, process, and
store data and information as well as produce
them when so required”.
It can further be view as a system in which is
referred to a computer system.
Computer system is a group of devices,
commonly called hardware that together with
sets of instructions called programs or
software, perform information processing
functions.
Input/Process/Output
Cycle
When a computer is used, data must be presented
to it in a prescribed form.
This is called data input format.
The form in which data is supplied to the computer
is that in which the program to be used by the
computer is expecting it.
A computer program is also used to determine the
format in which the results are to be supplied. This
is called output.
PROGRAMMING LANGUAGE LEVELS
Programming languages are often categorized in to the
following four groups. These groups basically reflect
the historical development of computer languages.
Machine language
Assembly language
High- level language
Fourth generation language.
In order for a program to run on a computer, it must be expressed in
that computer’s machine language. Each type of CPU has its
language. For that reason, we can’t run a program specifically written
for sun work station with its Sparc processor, or IBM PC, with its
Intel processor.
Problem Solving
Suppose a particular person is giving travel directions to a
friend, that person might explain those directions in any
one of several languages, such as English, Hausa, Yaruba,
or Ibo.
The directions are the same no matter which language is
used to explain them, but the manner in which the
directions are expressed is different. Furthermore, the
friend must be able to understand the language being used
to order to follow the directions.
Similarly, a problem can be solved by writing a program in
one of many programming languages, such as C++, Java,
Pascal, and Smalltalk.
Problem Solving Methodologies
The purpose of writing a program is to solve a
problem. Problem solving, in general, consists of
multiple steps:
Understand the problem.
Breaking the problem in to manageable pieces.
Designing a solution.
Considering alternatives to the solution and refining
the solution.
Implementing the solution.
Testing the solution and fixing any problems that
exist.
COMPILERS AND INTERPRETERS
Several special purpose programs are needed to help
with the process of developing new programs.
They are sometimes called software tools because they
are used to build programs.
Examples of basic software tool include an editor, a
compiler, and an interpreter.
The translation of source code in to (ultimately)
machine language for particular type of CPU can
occur in variety of ways.
COMPILER
A compiler is a program that translates code in one
language to equivalent code in another language.
The original code is called source code, and the language
in to which it is translated is called the target language.
For many traditional compilers, the source code is
translated directly in to a particular machine language.
In that case, the translation process occurs once, and the
resulting executable program can be run whenever needed.
INTERPRETER
An interpreter is similar to a compiler but has an
important difference.
-An interpreter interweaves the translation and
execution activities.
-A small part of the source code, such as one
statement, is translated and executed. Then another
statement is translated and executed, and so on.
-One advantage of this technique is that, it
eliminates the need for a separate compilation phase.
However, the program generally runs more slowly
because the translation process occurs during each
execution.
ERRORS
Several different kinds of problems can occur in
software particularly during program development.
From the user’s point of view, anything that goes
away when interacting with a machine is often
called a computer error.
A computer follows the commands we give and
operates on the date we provide.
If our programs are wrong or our data are
inaccurate, then we can not expect the results to
be correct.
Types of Error
You will encounter three kinds of errors as you develop
program:
Compile – time error: This is the error identified
during compilation stage.
Runtime error: it occur during program execution.
Logical error: it produce incorrect results.
Brief History of C++
As object-oriented analysis, design, and
programming began to catch on
Bjarne Stroustrup took the most popular
language for commercial software development,
C, and extended it to provide the features
needed to facilitate object-oriented
programming.
Brief History
He created C++ in the early 1980s, and in
less than a decade it has gone from being
used by only a handful of developers at
AT&T to being the programming language of
choice for an estimated one million
developers worldwide.
C++ is a difficult language for at least two
reasons: it inherits from the C language an
economy of expression that novices often
find cryptic.
Brief History
And a object – oriented language, its
widespread use of classes and templates
presents a challenge to those who have not
thought in those terms before.
C++ AS AN OBJECT – ORIENTED PROGRAMMING
C++ fully supports object-oriented
programming, including the four pillars of
object-oriented development:
Encapsulation
Data Hiding
Inheritance
Polymorphism
HOW TO WRITE AND RUN PROGRAMS
A program is a sequence of instructions that
can be executed by a computer. Every program
is written in some programming language.
To write and run C++ programs, you need to
have a text editor and a C++ compiler
installed on your computer.
A text editor is a software system that allows
you to create and edit text files on your
computer. Programmers use text editors to write
programs in a programming language such as
C++.