You are on page 1of 30

COM 235

Engineering Computer Programming


I
(3 Credits)
Lecture 1
Warming Up
Dr. Eng. Essam Abdrabou

Course Prerequisites
Prerequisites:
No prior programming experience
required

Who should be taking this course

Course Description
This course is designed to provide students with
an in depth coverage of the basics of
programming in C++, which is needed for
application development.
It is planned to make the students well
acquainted with the syntax and semantics of the
C++ programming language.
This is done through teaching the Input/output
instructions, the different data type used in the
language, the different arithmetic operations,
control structures, arrays, and functions.

What the class is really


about
There are two main goals of this course:
Basics of C++
We will learn how to program in C.
We will cover all the fundamentals: Variables, For
Loops, While Loops, Arrays, Functions.

Core Concepts of Programming Languages


There are lots of programming languages
available: Pascal, Java, C#, Fortran.
All of these languages share core concepts.
By focusing on these concepts, you are better
able to learn any programming language.

Administrative Issues
Course web site is available at:
Book:
Programming in C++, McGraw Hill,
2009.

Software

Grading
Your grade will be determined as
follows:
One Midterm (20%)
One Final Exam (40%)
Course Work (40%)
Quizzes, Attendance, Participation,
Homework (15%)
Practical Exam. (15%)
Labs. (10%)

A Word About Cheating


Cheating is defined as:
Copying all or part of others homework,
project or exam.
Others include your colleagues and/ or the
cyberspace
Allowing another student to copy all or part of
your homework, project, or exam.

Discussing homework concepts is fine, but


you must submit your own work.
If you are caught cheating
you will receive an immediate FAILURE
for the course.

Discipline
Please be on time to class!
Please do not talk to your friends and
neighbors in class!
It disturbs everyone, and makes it hard
to concentrate.
If you have a question, just ask me!

Please turn your cell-phones off!

The Lego Theory


The Lego Theory:
Complex software
is built with simple,
basic building blocks.

Lego Theory Applied: Basic


Example

Suppose you want to print your name five times.


Main Lego Block: For
Coordinating everything

Lego Block: For loop


for repeating actions.

Lego Block: std::cout


for displaying your
name

How we will use the Lego


Theory
Each week, we will introduce a new
basic building block.
By combining these blocks, we can
start creating more and more
powerful programs.
By the end of the semester, you will
have all the basic blocks for building
a sophisticated software.

Syllabus

Week
Week
Week
Week
Week
Week
Week
Week
Week

1: Missed
2: This Introduction
3: Variables, Basic Mathematics
4: Decision (If/Else)
5-6: Iterations (Loops)
7-8: Mid Term
9-12: Arrays
13-14: Functions
15: Final

What is a Computer?
Computer
Device capable of performing computations
and making logical decisions
Computers process data under the control of
sets of instructions called computer programs

Hardware
Various devices comprising a computer
Keyboard, screen, mouse, disks, memory, CDROM, and processing units

Software
Programs that run on a computer

Computer Organization
Six logical units in every computer:
Input unit
Obtains information from input devices (keyboard, mouse)

Output unit
Outputs information (to screen, to printer, to control other
devices)

Memory unit
Rapid access, low capacity, stores input information

Arithmetic and logic unit (ALU)


Performs arithmetic calculations and logic decisions

Central processing unit (CPU)


Supervises and coordinates the other sections of the computer

Secondary storage unit


Cheap, long-term, high-capacity storage
Stores inactive programs

Evolution of Operating
Systems
Batch processing
Do only one job or task at a time

Operating systems
Manage transitions between jobs
Increased throughput
Amount of work computers process

Multiprogramming
Computer resources are shared by many jobs or
tasks

Timesharing
Computer runs a small portion of one users job
then moves on to service the next user

Personal Computing,
Distributed Computing, and
Client/Server Computing

Personal computers

Economical enough for individual

Distributed computing
Computing distributed over networks

Client/server computing
Sharing of information across computer
networks between file servers and
clients (personal computers)

Machine Languages, Assembly


Languages, and High-level
Languages

Three types of programming languages


Machine languages
Strings of numbers giving machine specific
instructions
Example:
+1300042774
+1400593419
+1200274027

Assembly languages
English-like abbreviations representing elementary
computer operations (translated via assemblers)
Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY

Machine Languages, Assembly


Languages, and High-level
Languages
High-level languages

Codes similar to everyday English


Use mathematical notations (translated via
compilers)
Example:
grossPay = basePay + overTimePay

History of C and C++


History of C
Evolved from two other programming languages
BCPL and B
Typeless languages

Dennis Ritchie (Bell Laboratories)


Added data typing, other features

Development language of UNIX


Hardware independent
Portable programs

1989: ANSI standard


1990: ANSI and ISO standard published
ANSI/ISO 9899: 1990

19

History of C and C++


History of C++
Extension of C
Early 1980s: Bjarne Stroustrup (Bell Laboratories)
Provides capabilities for object-oriented
programming
Objects: reusable software components
Model items in real world

Object-oriented programs
Easy to understand, correct and modify

Hybrid language
C-like style
Object-oriented style
Both

20

C++ Standard Library


C++ programs
Built from pieces called classes and
functions

C++ standard library


Rich collections of existing classes and
functions

Building block approach to creating


programs
Software reuse
21

Structured Programming
Structured programming
Disciplined approach to writing
programs
Clear, easy to test and debug and easy
to modify

Main focus of this course.

Basics of a Typical C+
+ Program
Development
Environment
Phases of C++ Programs:
1. Edit
2. Preprocess
3. Compile
4. Link
5. Load
6. Execute

A Simple Program:
Printing a Line of Text
Comments
Document programs
Improve program readability
Ignored by compiler
Single-line comment
Begin with //

Preprocessor directives
Processed by preprocessor before
compiling
Begin with #
24

25

A Simple Program:
Printing a Line of Text
Standard output stream object
std::cout
Connected to screen
<<

Stream insertion operator


Value to right (right operand) inserted into output
stream

Namespace

std:: specifies using name that belongs to


namespace std
std:: removed through use of using statements

Escape characters

\
Indicates special character output

26

A Simple Program:
Printing a Line of Text
Escape Sequence

Description

\n

Newline. Position the screen cursor to the


beginning of the next line.
Horizontal tab. Move the screen cursor to the next
tab stop.
Carriage return. Position the screen cursor to the
beginning of the current line; do not advance to the
next line.
Alert. Sound the system bell.

\t
\r

\a
\\
\"

Backslash. Used to print a backslash character.


Double quote. Used to print a double quote
character.

27

28

Homework #1
Write the following program and
check how it is working.

29

30

You might also like