Lecture1 Introduction

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

Lecture 1: Introduction 1

Mr. Hasan Shehadi


Introduction to Engineering Programming
Reference: [Malik], Chapter 1

1
The figures in this presentation are taken from “Malik, C++ Programming: From Problem Analysis to Program Design,
5th edition.
Rasha Alkhansa GENG212 Spring 2020-21 1 / 23
Syllabus
Main objectives:
To acquire a good understanding of the basic principles
of programming.
Students will learn and practice the application of these programming
principles to the solution of engineering problems using the C++
high-level programming language.

Textbook: C++ Programming: From Problem Analysis to Program


Design, fifth edition, by D.S.Malik.

Prerequisite: None.

Rasha Alkhansa GENG212 Spring 2020-21 2 / 23


Topics

Basic Elements of C++


Input/Output
Control Structures I (Selection)
Control Structures II (Repetition)
User-Defined Functions
Arrays and Strings
Reading and writing files
Recursion
Algorithms and
Complexity/Running
Time
Structs and Classes

Rasha Alkhansa GENG212 Spring 2020-21 3 / 23


Introduction
Many people use the internet and other applications. This is all
made possible by the availability of different software, also known as
computer programs.
Without software, a computer is useless.
Software is developed by using programming languages. The
programming language C++ is especially well suited for
developing software to accomplish specific tasks.
Our main objective is to help you learn how to write programs in
the C++ programming language.

Rasha Alkhansa GENG212 Spring 2020-21 4 / 23


PC Hardware
Central Processing Unit (CPU) is the “brain” of the computer. Arithmetic
and logical operations are carried out inside the CPU.
Main Memory
Secondary Storage
Input/Output Devices

Rasha Alkhansa GENG212 Spring 2020-21 5 / 23


Main Memory, or random access
memory
A set of ordered memory cells, each with a unique location (called
cell address).
Directly connected to the CPU
The content of a cell can be either a programming instruction or
data (stored as sequences of 0s and 1s).
All programs must be loaded into main memory before they can
be executed
All data must be brought into main memory before it can
be manipulated
When computer power is turned off, everything in main
memory is lost

Rasha Alkhansa GENG212 Spring 2020-21 6 / 23


Secondary Storage
Secondary storage: Device that stores information
permanently.

Examples of secondary storage:


Hard disks
Floppy disks
CD-ROMs
Flash
memories ...

Rasha Alkhansa GENG212 Spring 2020-21 7 / 23


Input/Output Devices
Input devices feed data and programs into computers -
Include:
Keyboar
d Mouse
Secondar
y storage

Output
devices
display
results. They
include:
Screen

Printer
Second
ary
storag
Rasha Alkhansa GENG212 Spring 2020-21 8 / 23
Software
Software: Programs that do specific tasks
System programs take control of the computer, such as an
operating system
Application programs perform a specific task (games,...)
The operating system is the program that runs application
programs.

Rasha Alkhansa GENG212 Spring 2020-21 9 / 23


The Language of a
Computer
Digital signals are sequences of 0s and 1s
Machine language: language of a
computer Binary digit (bit): The digit 0
or 1
Binary code: A sequence of 0s and
1s Byte: A sequence of eight bits

Every letter, number, or special symbol (such as * or {) on your


keyboard is encoded as a sequence of bits, each having a unique
representation.

The most commonly used encoding scheme on personal computers is


the seven-bit American Standard Code for Information Interchange
(ASCII).

Rasha Alkhansa GENG212 Spring 2020-21 10 / 23


The Binary Units

Rasha Alkhansa GENG212 Spring 2020-21 11 / 23


Programming Language Evolution
1 Machine language (used by early
programmers):
100100 010001
100110 010010
100010 010011
2 Assembly language: low level
instructions
LOAD rate
MULT hours
STOR
3 wages
High-level language (e.g. C++):
wages = rate * hours;

Rasha Alkhansa GENG212 Spring 2020-21 12 / 23


The Assembler and the
Compiler
A computer cannot execute assembly or high-level
language instructions directly
Assember: A program that translates a program written in
assembly language into an equivalent program in machine language.
Compiler: A program that translates instructions written
in high-level languages into machine code.

Examples of Instructions in Assembly and Machine


Language

Rasha Alkhansa GENG212 Spring 2020-21 13 / 23


High-Level Languages
High-level language: high level statements
int a; //allocate memory for an integer called a
int b; //allocate memory for
b b = 2; //store 2 in b
a = 3*b-1; / / store 3*(value
of b)-1 in a

Include Basic, FORTRAN, Pascal,


C++, C, and Java

Rasha Alkhansa GENG212 Spring 2020-21 14 / 23


Processing a Program
To execute a program written in a high-level language such as C++
Use an editor to create a source program (.cpp) in C++
Use the preprocessor to process preprocessor directives (C++
statements starting with #)
Use the compiler to
Check that the program obeys the rules
Translate into machine language (object program) (.obj)
Software Development Kit (SDK) or Integrated Development
Environments (IDE) (e.g. CodeBlocks, Visual Studio VS,
Xcode, etc.) may be used to create a program
Next slide: examples of available free IDEs.
Linker: Combines object program with other programs provided by
the SDK libraries to create executable code (.exe)
Ex: statement x = cos(y) linked with the cosine function
in the math library
Loader: Loads executable program into main
memory The last step is to execute the program

Rasha Alkhansa GENG212 Spring 2020-21 15 / 23


IDEs and Online Compilers

Many IDEs are available online for free download (e.g. C-Free, Visual
Studio or CodeBlocks)

There are also online compilers that allow you to write and test your C+
+ programs from the browser without installing any IDE.

It is recommended that you install an IDE on your laptops (do not rely
on online compilers); specifically, it is recommended that you install
CodeBlocks because it is the IDE that is used in the University labs. You
can use the following link for download:
http://www.codeblocks.org/downloads/bina
ries You will be given multiple options,
choose codeblocks-20.03mingw-setup.exe
(4th option, the last time I
checked the website), download it, run it, and follow the
istallation instructions.

Rasha Alkhansa GENG212 Spring 2020-21 16 / 23


Processing a Program

Rasha Alkhansa GENG212 Spring 2020-21 17 / 23


Problem Solving
Programming is a process of problem solving

Problem solving techniques


Analyze the problem and outline the problem requirements
Design steps (algorithm) to solve the problem

Algorithm:
Step-by-step problem-solving process
Solution achieved in finite amount of time

Implement algorithm in code and debug

Rasha Alkhansa GENG212 Spring 2020-21 18 / 23


Problem Solving

Rasha Alkhansa GENG212 Spring 2020-21 19 / 23


Design an Algorithm
If problem was broken into
subproblems
Design algorithms for each subproblem

Check the correctness of algorithm


Can test using sample data
Some mathematical analysis might be
required

Rasha Alkhansa GENG212 Spring 2020-21 20 / 23


Write the Code
Once the algorithm is designed and correctness
verified
Write the equivalent code in high-level language

Enter the program using text editor

Rasha Alkhansa GENG212 Spring 2020-21 21 / 23


Compiling and Linking
Run code through compiler

If compiler generates errors


Look at code and remove errors
Run code again through compiler

If there are no syntax errors


Compiler generates equivalent
machine code

Linker links machine code with


system resources

Rasha Alkhansa GENG212 Spring 2020-21 22 / 23


The Loader and Executing
Once compiled and linked, loader can place program into
main memory for execution

The final step is to execute the program

Compiler guarantees that the program follows the rules of


the language
Does not guarantee that the program will run correctly

Rasha Alkhansa GENG212 Spring 2020-21 23 / 23

You might also like