Computer Programming Basic Course, Lecture notes of Advanced Computer Programming

Lecture notes for computer programming basics. It gives step by step from basics to object oriented programming

Typology: Lecture notes

2014/2015

Uploaded on 01/31/2015

amrgody
amrgody 🇪🇬

5

(2)

1 document

1 / 106

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Project No: EE103-FALL-2011 Group No: EE103-FY-2011
Revision: C06
Revision Date: 26/12/2011 Amr M. Gody
Doc No: EE103-AG-FY-2011-C04 Page 1 of 106
Computer Engineering and Programming
EE103 course details
Computer Engineering and Programming
Ref: EE103-FALL-2011
Amr M. Gody
Revision
C01
C02
C03
C04
C05
C06
Purpose
Add
Add
Add
Add
Add
Add
Date
31/10/2011
5/11/2011
18/11/2011
12/12/2011
19/12/2011
26/12/2011
By
Amr M.
Gody
Amr M.
Gody
Amr M.
Gody
Amr M.
Gody
Amr M.
Gody
Amr M.
Gody
Checked
Approved
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Computer Programming Basic Course and more Lecture notes Advanced Computer Programming in PDF only on Docsity!

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

EE103 course details

Computer Engineering and Programming

Ref: EE103-FALL-

Amr M. Gody

Revision C 01 C02 C03 C04 C05 C0 6

Purpose Add Add Add Add Add Add Date 31/10/2011 5/11/2011 18/11/2011 12/12/2011 19/12/2011 26/12/

By

Amr M. Gody

Amr M. Gody

Amr M. Gody

Amr M. Gody

Amr M. Gody

Amr M. Gody Checked Approved

Revision Date: 26/12/2011 Amr M. Gody

Revision Date: 26/12/2011 Amr M. Gody

  • Project No: EE103-FALL-2011 Group No: EE103-FY-
  • Revision: C
  • 1 Chapter 1: Fundamentals of computer systems Table of Contents
    • 1.1 Lecture 1: Numbering Systems
      • 1.1.1 Objectives
      • 1.1.2 Numbering system
        • 1.1.2.1 Decimal numbers
        • 1.1.2.2 Binary numbers
        • 1.1.2.3 Hexadecimal numbers
        • 1.1.2.4 Octal numbers
      • 1.1.3 Relation between numbers in different systems - 1.1.3.1.1 Exercise
      • 1.1.4 Fractions
      • 1.1.5 References.......................................................................................................................
    • 1.2 Lecture 2: Computer Architecture
      • 1.2.1 Objectives
      • 1.2.2 The Static structure of the computer system
      • 1.2.3 The dynamic Structure of the Computer System
      • 1.2.4 The program
      • 1.2.5 The memory
      • 1.2.6 Data Encoding
      • 1.2.7 Interfacing
      • 1.2.8 The operating system
  • 2 Chapter 2: Computer Programming
    • 2.1 Lecture 3: Flow chart...............................................................................................................
      • 2.1.1 Objectives
      • 2.1.2 Concept of flow chart
      • 2.1.3 Popular Shapes in flow chart
        • 2.1.3.1 Start/Termination
        • 2.1.3.2 Data
        • 2.1.3.3 Process
        • 2.1.3.4 Subroutine
        • 2.1.3.5 Branching..................................................................................................................
        • 2.1.3.6 Connectors
      • 2.1.4 Decorative Shapes
        • 2.1.4.1 Input
        • 2.1.4.2 Output
        • 2.1.4.3 Files
        • 2.1.4.4 Storage
    • 2.2 Lecture 4: Programming Styles
      • 2.2.1 Objectives
      • 2.2.2 Batch Job Programming style
      • 2.2.3 Subroutines
      • 2.2.4 Decision
      • 2.2.5 Loops
      • 2.2.6 Recursion
        • 2.2.6.1 Code in C# for the recursion example
    • 2.3 Lecture 5: C# (C sharp) High Level Language basics
      • 2.3.1 Objectives
      • 2.3.2 Program Structure
      • 2.3.3 Function Definition
  • Project No: EE103-FALL-2011 Group No: EE103-FY-
  • Revision: C - 2.3.4 Memory in Windows environment.................................................................................... Revision Date: 26/12/2011 Amr M. Gody - 2.3.5 Fundamental Data Types
    • 2.4 Lecture 6: Program flow control
      • 2.4.1 Objectives
      • 2.4.2 Program Flow Control
        • 2.4.2.1 Conditions
        • 2.4.2.2 Loops
    • 2.5 Sheet 2:
  • 3 Object Oriented Programming (OOP)
    • 3.1 Lecture 7: Philosophy of OOP
      • 3.1.1 Objectives
      • 3.1.2 Why Object Oriented Programming (OOP)
      • 3.1.3 Object declarations
      • 3.1.4 Instantiating object.
    • 3.2 Lecture 8: Advanced topics in OOP
      • 3.2.1 Objectives
      • 3.2.2 Polymorphism
      • 3.2.3 Inheritance
    • 3.3 Lecture 9: Unified Modelling Language UML
      • 3.3.1 Objectives
    • 3.4 Use Case Diagram
    • 3.5 Activity Diagram
    • 3.6 Static Class Diagram.............................................................................................................
    • 3.7 Lecture 10: OOP Design Examples
    • 3.8 Sheet
  • Project No: EE103-FALL-2011 Group No: EE103-FY-
  • Revision: C
  • Figure 1 - 1: Binary, Decimal and Hex equivalents. Figures
  • Figure 1 - 2: Fundamental components of the computer system.
  • Figure 1 - 3: Interfacing layout.
  • Figure 2 - 1: Example: Control algorithm for Simple process.
  • Figure 2 - 2: The ORing shape is used to combine the split flow in the flowchart.
  • Figure 2 - 3: The structure of the main function in C# for windows forms application
  • Figure 2 - 4: The console window.
  • Figure 2 - 5: The process Memory Map in windows operating system.
    • cycle. Figure 2 - 6: The operating system serves each thread in specific time duration along the execution
    • between functions to build the required information. Figure 2 - 7: The program is a series of functions communicating together. The data is bouncing
  • Figure 2 - 8: Screenshot of the program output of calculating the size of the basic types in C#
  • Figure 2 - 9: Screenshot of the program output of calculating the size of the basic types in C#
  • Figure 2 - 10: Flowchart of Math Expression evaluation Example
  • Figure 2 - 11: Text file for batch expressions and the associated output.
  • Figure 2 - 12: Flowchart of batch Math Expression evaluation Example
  • Figure 3 - 1 : Basic Object parameters in OOP
    • the Shape object. Figure 3 - 2 : Inheritance in OOP. The Geometrical objects will inherit the common functionalities from
  • Figure 3 - 3 : Base class is acting as extension for the inherited classes.
  • Table 1 - 1: HEX-Binary-Octal Equivalent for certain number............................................................................ Tables
  • Table 1 - 2: Memory Array of bits
  • Table 2 - 1: Basic Data types in C#

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

Preface Thank you for Dr. Magdy Amer for his contribution in adding problems into the sheets of OOP.

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

1.1.2 Numbering system

Popular numbering systems are: Decimal Binary Hexadecimal Octal

1.1.2.1 Decimal numbers

Base is 10 The number is defined as a multiple of 10 digits 104 103 102 101 100. 10 -^1 10 -^2

Each digit contains a number that define the multiple of the base unit indicated in the above figure. For example 586 5 * 10^2

  • 8 * 10^1 +6 * 10^0 This way we define the number in terms of multiple of base 10. The maximum number that we can fit in one digit is 9.

1.1.2.2 Binary numbers

Base is 2 The number is defined as a multiple of 2

The number is defined as a multiple of 10 digits 24 23 22 21 20. 2 -^1 2 -^2

Each digit contains a number that define the multiple of the base unit indicated in the above figure. For example 101 1 * 2^2

  • 0 * 2^1 +1 * 2^0 This way we define the number in terms of multiple of base 2. The maximum number that we can fit in one digit is 1.

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

1.1.2.3 Hexadecimal numbers

Base is 16 The number is defined as a multiple of 16

The number is defined as a multiple of 10 digits 164 163 162 161 160. 16 -^1 16 -^2

Each digit contains a number that define the multiple of the base unit indicated in the above figure. For example 101 1 * 2^2

  • 0 * 2^1 +1 * 2^0 This way we define the number in terms of multiple of base 16. The maximum number that we can fit in one digit is 15 or in symbolic form is F.

1.1.2.4 Octal numbers

Base is 8 The number is defined as a multiple of 8

The number is defined as a multiple of 10 digits 84 83 82 81 80. 8 -^1 8 -^2

Each digit contains a number that define the multiple of the base unit indicated in the above figure.

This way we define the number in terms of multiple of base 8. The maximum number that we can fit in one digit is 7.

1.1.3 Relation between numbers in different systems

Figure 1-1 illustrates three numbering systems side by side. Numbering systems is used to give different view for the same quantity. The relation should be kept in mind. For example consider the Hex – Binary relation as in Table 1

The hex number is very important to describe large numbers. Each hex digit is 4 binary digits.

Table 1 - 1 : HEX-Binary-Octal Equivalent for certain number

A 0 B 5 1 0 1 0 0 0 0 0 1 0 1 1 0 1 0 1 1 2 0 2 6 5

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

1.1.4 Fractions

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

1.1.5 References

[1] M. RAFIQUZZAMAN, "Fundamentals of Digital Logic and Microcomputer Design",

Fifth Edition, WILEY-INTERSCIENC, ISBN 0471727849.

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

1.2.2 The Static structure of the computer system

Let us get a close image about computer architecture.

Figure 1 - 2 : Fundamental components of the computer system.

Figure 1-2 illustrates the fundamental components of computer. It consists of three parts

1- Microprocessor.

2- Memory.

3- Peripheral devices.

The control is achieved through three channels each called bus.

1- Address bus.

2- Data bus.

3- Control Bus.

The microprocessor itself consists of almost similar structure.

1- Central processing Unit (CPU)

2- Arithmetic and Logic Unit (ALU).

3- Registers. (Small memory elements)

4- Internal bus structure to make it possible for CPU to control the internal components for

executing the program instructions.

ALU
CPU

Registers

Memory

Peripheral Devices

MAR
MDR

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

1.2.3 The dynamic Structure of the Computer System

Section 2.1 illustrates the static structure of the computer system. The dynamic structure means the active computer running a program. The program is the user algorithm to be run by the computer for solving certain problem.

1.2.4 The program

The program is sequence of instructions that are understood by the computer. Let us discuss the program in more details.

1.2.5 The memory

The program is put into the memory, so what is the memory itself. The memory is a small array of single binary digits. Table 1-2 views a part of memory. This part is 6 bytes.

Table 1 - 2 : Memory Array of bits

Address in hex D7 D6 D5 D4 D3 D2 D1 D 0F235 1 1 0 0 0 0 0 1 0F236 0 0 0 0 0 0 0 0 0F237 1 1 1 1 0 1 0 0 0F238 1 1 1 1 0 1 0 1 0F239 0 0 0 0 0 1 1 1 0F23A 0 0 0 0 0 0 0 0

The byte is a memory measurer. One byte = 8 bits.

Each bit can store a single binary digit. It is one of two states 1- State 1. 2- State 0.

Each state can be encoded into a certain voltage level. For example state 0 = 0 (v) and State 1 = 5 (v)

Each byte is a collection of 8 bits. Each byte has a unique address.

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

1.2.7 Interfacing

Interfacing with PC means connecting devices to the CPU. This is the key of almost all modern technologies that consider the Microprocessor as a smart engine. Adding smart device to the hardware makes it more flexible to make off sure decisions. The device can make the decision based on a program. We can say that adding such smart engines to the devices is the key for the modern age. Figure 2-2 illustrates the layout of the interfacing with CPU. To interface any device to the CPU you should build interfacing circuit to match the electrical signals needed to make the device communicating with the CPU. The Controlled valve in figure 1-3 is controlled by sending appropriate electric signal to the device to control the open or control percentage. The CPU sends required opening percentage to the data memory at specific address. Then it asks the interface board to write that percentage to the valve using the control memory. This is achieved by sending certain word of bits that encodes the required information to the control memory. Then the interface board will de-code the information in control word and the data in the data memory to suitable electric signal to open the valve with the percentage required. The device send the status using some limit switches to the interface circuit, which in turn encode the information to creating pattern of bits and put it into the status memory. Then the interface board notifies the CPU with the status.

Figure 1 - 3 : Interfacing layout.

The Personal computer is a collection of devices that are connected to CPU. They are integrating through the special program called the operating system.

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

1.2.8 The operating system

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

2.1.2 Concept of flow chart

The program is a flow of activities. There are 3 types of activities

1- Batch Process.

2- Branching.

3- Loops.

The program is a sequence of the mentioned activities. The flow chart is invented to provide simple and standard method to express the program flow.

The first step for implementing idea is to express it into flow chart. It is language independent method to express the idea.

2.1.3 Popular Shapes in flow chart

2.1.3.1 Start/Termination

The shape is used to indicate the start and end points in the program flow. Example

Start node

End node

View result

Find enclosing angle

Project No: EE103-FALL-2011 Group No: EE103-FY- Revision: C Revision Date: 26/12/2011 Amr M. Gody

2.1.3.2 Data

This shape is used to express the data for the process and for the subroutines. This makes it easier for the reader to trace the data flow along the program.

Example

A : Vector B : Vector C : Vector N : Vector size