Vous êtes sur la page 1sur 47

WELCOME

CSC 201
COMPUTER
PROGRAMMING-I
Lecturer
Musa MUHAMMED, PhD

Class Assistant
Mr.Yussuf ABBAS
COURSE SYLLABUS

 COMPUTER PROGRAMMING-I

2
COURSE CONTENTS

 General review of Programming languages


 Topics covered include variables, arithmetic operators, control
structures, arrays, functions, recursion, dynamic memory allocation,
files, pointers, Strings.

3
ATTENDANCE

 Compulsory

 Attendance will be taken in every class

 A test/quiz may be held at any time(Pop Quiz)

 Classes will begin on time(You are expected to be on time)

4
EVALUATION POLICY

 Students will demonstrate their mastery of material by


demonstration of their works by written homework, quizzes and
exams.

 All grade levels evaluate by 100 point matters, final grade will be
assigned according to a weighted average of the scores CA (40%
of final grade) and final (60% of final grade) exam results.

5
OUTLINE OF COURSE TOPICS

 This course schedule is subject-to be changed - all students will be


informed about any changes. The following is a list of topics to be
covered throughout the semester.

6
LIST OF THE COURSES

7
8
Lecture 1

Introduction to
Programming Languages
Goals

By the end of this lecture, you should …

 Understand the different types of programming languages.


 Understand the basic procedures in a program as input, processing
and output.
 Understand the importance of variables.
 Understand a basic map of the program development cycle.
 Understand Compiled and Interpreted Programs
Computer Components

 CPU Central Processing Unit


 RAM (Random Access Memory)
 Mass storage devices
 Input devices
 Output Devices
Storage Capacities

 bit – smallest capacity


 nibble = 4 bits
 byte = 2 nibbles = 8 bits

 storage for one character


 1 kilobyte (KB) = 1024 bytes
 1 megabyte (MB) = 1024 KB
 1 gigabyte (GB) = 1024 MB
Software
Software is comprised of instructions that get a
computer to perform a task.
 Application Software  System Software
 Word Processors  Operating Systems
 Database s/w  Windows
 Spreadsheets  Macintosh OS
 Painting programs  Unix
 Linux
 Web browsers, email
programs  Drivers
Options for Programming Languages
Low level Programming Language

Low level language uses instructions similar to internal


control Unit:
1- move data from one location to another
2- Execute a simple ALU operation
3- Jump to new point is sequences based on test
Low level
High level Language
 A high level language uses more abstract terms invert a matrix,
compute a function.
 In a compiled language, those abstractions are converted back into
low level instructions, then executed.
In an interpreted language, special program converts
source code to internal data structure, then
interpreter sequentially converts each step into low
level machine instruction and executes.

So what is the choice…..?


Programming Languages

 Programming languages allow programmers to code software.


 The three major families of languages are:
 Machine languages
 Assembly languages
 High-Level languages
Machine Languages

 Comprised of 1s and 0s
 The “native” language of a computer
 Difficult to program – one misplaced 1 or 0 will cause the program to
fail.
 Example of code:
1110100010101 111010101110
10111010110100 10100011110111
Assembly Languages

 Assembly languages are a step towards easier


programming.
 Assembly languages are comprised of a set of
elemental commands which are tied to a specific
processor.
 Assembly language code needs to be translated
to machine language before the computer
processes it.
 Example:
ADD 1001010, 1011010
High-Level Languages

 High-level languages represent a giant leap towards easier


programming.
 The syntax of HL languages is similar to English.
 Historically, we divide HL languages into two groups:
 Procedural languages
 Object-Oriented languages (OOP)
Procedural Languages

 Early high-level languages are typically called procedural


languages.
 Procedural languages are characterized by sequential sets of linear
commands. The focus of such languages is on structure.
 Examples include C, COBOL, Fortran, LISP, Perl, HTML, VBScript
Object-Oriented Languages

 Most object-oriented languages are high-level languages.


 The focus of OOP languages is not on structure, but on modeling
data.
 Programmers code using “blueprints” of data models called classes.
 Examples of OOP languages include C++, Visual Basic.NET and
Java.
Compiling

 Regardless of the HL Language, all HL


programs need to be translated to machine code
so that a computer can process the program.
 Some programs are translated using a
compiler. When programs are compiled, they
are translated all at once. Compiled programs
typically execute more quickly than interpreted
programs, but have a slower translation speed.
Interpreting

 Some programs are translated using an interpreter. Such programs


are translated line-by-line instead of all at once (like compiled
programs). Interpreted programs generally translate quicker than
compiled programs, but have a slower execution speed.
Programming Example
 Simple programming problem: Convert a price from British pounds
into Dollars.
 Pseudocode
Input the price of the item, PoundPrice, in pounds
Compute the price of the item in dollars:
Set DollarPrice = 1.62 * PoundPrice
Write DollarPrice

 Translating to Basic:
INPUT PoundPrice
LET DollarPrice = 1.62 * PoundPrice
PRINT DollarPrice
END
Types of Data
 Numeric Data
 Integer data, I.e., whole numbers, 10 25 -45
0
 Floating point data – have a decimal point
23.0, -5.0
 Character data (alphanumeric)
 Allthe characters you can type at the keyboard
 Letters & numbers not used in calculations
 Boolean data
 TRUE/FALSE
Data Processing and Output

Set DollarPrice = 1.62 * PoundPrice


 The above statement is a processing statement.
Take the value in the variable PoundPrice,
multiply by 1.62, and set the variable
DollarPrice to the result of the multiplication.

Write DollarPrice
 Output the value in DollarPrice to the
monitor.
Assignment Operations

Set counter = counter + 1


 Assignment statements change the value in a
variable Take the value of counter, add 1, and
store the result back in the same variable.
Arithmetic Operations
Name Symbol Example Result
Exponentiation ^ 4^2 16
Multiplication * 16*2 32
Division / 16/2 8
Addition + 16+2 18
Subtraction - 16-2 14
Data Hierarchy

1. Parenthesis
2. Exponentiation
3. Multiplication/Division
4. Addition/Subtraction
Hierarchy of Operations Example
3 * (6 + 2) / 12 – (7 – 5) ^ 2 * 3 ( ) first
= 3 * 8 / 12 – 2 ^ 2 * 3 ^ next
= 3 * 8 / 12 – 4 * 3 Mult/Div (L to R)
= 24 / 12 – 4 * 3 Mult/Div (L to R)
= 2 – 12 Add/Subtr
= -10
Data Output
 Send information from the program to the screen,
or printer, or disk file.
Write DollarPrice
 The computer displays the value of the variable
DollarPrice to the screen and the cursor goes
to the next line.
Data Output
Write “The price in Dollars is”,
DollarPrice

 The output looks like this:


The price in Dollars is 162

 The text inside the “ ” is output to the user “as is,”


and it is the value in the variable that is output.
Programming as Problem Solving
 Problem solving  Developing a
principles: Program:
1. Completely understand 1. Analyze the problem
the problem 2. Design the program
2. Devise a plan to solve it 3. Code the program
3. Carry out the plan 4. Test the program
4. Review the results

An example of programming as problem solving,


1) Analyze the Problem

 The problem: Mr.Lamda wants to invest


money at a local bank. There are many
options such as interest rates, terms of
deposit, compounding frequencies. He needs
a program to compute, for any given initial
investment, the final maturity (value) of the
deposit.
 What are the inputs? (given data)
 What are the outputs? (required data)
 How will we calculate the required outputs from the given inputs?
2) Design the Program

 Create an outline of the program


 An algorithm – a step by step procedure that will provide the
required results from the given inputs.
 Algorithm Examples: Instructions on how to make a cake, use the
bank’s ATM, etc.
3) Code the Program

 Once the design is completed, write the program code.


 Code is written in some programming language such as BASIC,
Pascal, C++, Java, etc.
4) Testing the program

 Locate any errors (bugs)


 Testing is done throughout the development
cycle
 Desk-checking, or code walkthrough is
performed to locate errors in the code.
 Pretend you are the computer and execute your own code.
 Ultimate test is to run the program to see if the
outputs are correct for the given inputs.
Coding

 Coding is done in a specific programming


language. In this part of the course, we will use
pseudocode. Later, we’ll adapt our pseudocode
to write in Java.
 Coding before finishing a solid algorithm is a lot
like putting the cart before the horse and usually
spells disaster. Time well-spent in the design
phase will head off problems in coding!
Types of Errors

 Syntax – wrong grammar, i.e., breaking the rules


of how to write the language
 Forgetting punctuation, misspelling keyword
 The program will not run at all with syntax
errors
 Logic - the program runs, but does not produce
the expected results.
 Using an incorrect formula, incorrect
sequence of statements, etc.
Structured Programming

 A method for designing and coding programs in a


systematic, organized manner.
 It combines the principles of top-down design, modularity
and the use of the three accepted control structures of
sequence, repetition and selection.
Control Structures
 Sequence –in sequential order.
 The simplest of control structures – start at
the beginning and continue in sequential
order.
 Selection – selectively execute statements
 Called a branch, it requires a condition to
determine when to execute statements.
Control Structures
 Repetition – repeat statements more than once
 Called a loop, it needs a stop condition, I.e,
the program will continue to loop until some
condition is met.
QUESTIONS?

 NOTE: Always review the Material


before coming to the next Class in
order not to be surprised by
Mr.QUIZ

Vous aimerez peut-être aussi