Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 1 C++ Programming - Introduction

Similar presentations


Presentation on theme: "CHAPTER 1 C++ Programming - Introduction"— Presentation transcript:

1 CHAPTER 1 C++ Programming - Introduction
Lecturer: Dept. of Electrical and Electronic Engineering

2 Objectives: In this chapter, you will learn about: Computer systems
Simple program logic The steps involved in the program development cycle Pseudocode statements and flowchart symbols Using a sentinel value to end a program Programming and user environments The evolution of programming models

3 1.1 Computer Systems How is a computer defined?
What is a COMPUTER? How is a computer defined? A computer is an electronic device that stores and processes data Includes both hardware and software Hardware Physical aspect of the computer that can be seen Software Invisible instructions that control the hardware and make it work Computer programming consists of writing instructions for computer to perform

4 1.1 Computer Systems Component of a Computer (HW)

5 1.1 Computer Systems Component of a Computer (HW) System Unit CPU
Motherboard RAM Expansion cards Output devices monitor Communication devices Storage Devices Input devices Optical disc drive mouse Hard disk drive keyboard Modem, network interface card (NICs), cable, wireless, etc…

6 1.1 Computer Systems Component of a Computer (HW) – 1. System Unit
The motherboard also known as the main board or system board or planar board. It contains most of the important components, including the chipset, which controls essential functions inside a Computer. The key components of a motherboard are: CPU socket / slot, BIOS - ROM chip, Chipset (North / South Bridge or memory and I/O Controller hubs), Expansion slots, and Memory area - SIMMs or DIMMs (RAM). The motherboard directly interacts with other components of the Computer, and is responsible for the stability, feature support, expandability and upgrading ability of any system to a maximum extent. Alternatively referred to as a bus slot or expansion port, an expansion slot is an opening located inside a computer on the motherboard or riser board that allows additional boards to be connected to it. For example, if you wanted to install a new video card in the computer you'd purchase a video expansion card and install that card into the compatible expansion slot. Single Inline Memory Module (SIMM) SIMM is a memory module with 72 or 30 pins, as shown in Figures and . SIMMs are considered legacy components and can be found in older machines. SIMMs with 72 pins can support 32-bit transfer rates and 32-pin SIMMs can support 16-bit transfer rates. Dual Inline Memory Module (DIMM) DIMM is a memory module with 168 pins as shown in Figure . DIMMs are commonly used today and support 64-bit transfer.

7 1.1 Computer Systems Component of a Computer (HW) – 1. System Unit
Processor: AKA Central Processing Unit (CPU) A CPU is on a chip called a microprocessor CPU interprets and carries out the basic instructions that operate the computer A Place where calculations and comparisons are performed The brain of a computer, retrieve instructions from memory and executes them It continuously follows the fetch-decode-execute cycle:

8 1.1 Computer Systems Component of a Computer (HW) – 1. System Unit
Processor: The CPU contains: Control unit controls and coordinates the actions of the other components Logic unit performs numeric operations(+,-x,/) and logical operations (comparisons) Processor Speed: The speed of a CPU is controlled by the system clock The system clock generates an electronic pulse at regular intervals The faster the clock speed, the more instructions are executed in a given period of time.

9 1.1 Computer Systems Component of a Computer (HW) – 1. System Unit
Memory: Store data and program instructions for the CPU to execute. Memory unit is an ordered sequence of bytes, each holding eight bits. Using a byte as minimum storage unit Random access memory (RAM): Hold changing data and programs which do not have to be permanently available. require a constant source of power to retain the information (volatile memory) 2. Read only memory (ROM): Contains program that always present – for example BIOS – code needed to start computer. does not require a constant source of power to retain the information (non volatile memory)

10 1.1 Computer Systems Component of a Computer (HW) – 2. Storage Device
Programs and data are permanently stored on storage devices and are moved to memory when the computer actually uses them. Non-volatile – data retain when power off Example hard disks and floppy disk CD-R and CD-RW Tape

11 1.1 Computer Systems Component of a Computer (HW) – 3. Input Device
Hardware used to enter data and instructions Examples: Keyboard: Similar to typewriter keyboard With extra keys for certain special functions (function keys, numeric keypad, arrow keys, insert, delete, page up, page down keys) Mouse: A pointing device that used to move an electronic pointer called a cursor around the screen

12 1.1 Computer Systems Component of a Computer (HW) – 4. Output Device
Hardware that conveys information to one or more people Examples: Monitor: size measured diagonally, like a television screen Mostly with multimedia capabilities: text, graphics, video, etc. Maximum resolution : indicating the number of picture elements, called pixels, that it can display (such as 1280 by 1024) High resolution (more pixels) produces sharper pictures Printer

13 1.1 Computer Systems Component of a Computer (HW) – 5. Communication Device Hardware component that enables a computer to send and receive data, instructions, and information Examples: Modem (use phone line) DSL( digital subscriber line) Cable modem (use TV cable line) Network interface card (connect computer to LAN)

14 1.1 Computer Systems Component of a Computer (HW) – 5. Communication Device Modulator-Demodulator, aka Modem (use phone line) Data transfer devices allow information to be sent and received between computers Allows information to be moved across a telephone line A data transfer device has a maximum data transfer rate A modem, for instance, may have a data transfer rate of 56,000 bps (bits per second)

15 Check Point 1.1 What are hardware and software?
1.2 List five major hardware components of a computer. 1.3 What does the acronym “CPU” stand for? 1.4 What unit is used to measure CPU speed? 1.5 What is a bit? What is a byte? 1.6 What is memory for? What does RAM stand for? Why is memory called RAM? 1.7 What unit is used to measure memory size? 1.8 What unit is used to measure disk size? 1.9 What is the primary difference between memory and a storage device?

16 Answer: 1.1 What are hardware and software?
In general, hardware is the physical aspect of the computer that can be seen, and software is the invisible instructions that control the hardware and make it work. 1.2 List five major hardware components of a computer. Input Device, Output Device, System Unit, Storage Device & Communications Device. 1.3 What does the acronym “CPU” stand for? CPU stands for Central Processing Unit. It is the brain of the computer. 1.4 What unit is used to measure CPU speed? The unit of measurement of clock speed is the hertz (Hz), with 1 hertz equaling 1 pulse per second. The clock speed of a computer is usually stated in megahertz (MHz) (1 MHz is 1 million Hz).

17 Answer: 1.5 What is a bit? What is a byte?
A bit is a binary digit 0 or 1. A byte is a sequence of 8 bits. 1.6 What is memory for? What does RAM stand for? Why is memory called RAM? Memory is like a work area for programs. Before a program is executed, it is brought into the memory. RAM stands for random-access memory. It is called RAM because a memory cell can be accessed directly.

18 Answer: 1.7 What unit is used to measure memory size?
Memory size is measured in bytes. 1.8 What unit is used to measure disk size? Disk size is measured in bytes. 1.9 What is the primary difference between memory and a storage device? Memory is volatile, because information is lost when the power is turned off. Programs and data are permanently stored on storage devices and are moved, when the computer actually uses them, to memory, which is much faster than storage devices.

19 1.1 Computer Systems Component of a Computer (SW) – Programs
Also called a software, Consists of a series of instructions that tells the computer what to do and how to do it Without programs, a computer is an empty machine Computers ONLY understand machine language

20 1.1 Computer Systems Component of a Computer (SW) – Programs
Types of Software: System software: control or maintain operations of the computer and its devices Serves as the interface between user, application software & computer’s hardware Example: OS, utility program Application software Programs designed to make users more productive Exp: word processing, spreadsheet, presentation graphic, database, internet browser, etc.

21 1.1 Computer Systems Component of a Computer (SW) – Programs Types of System Software: Operating system: Program that coordinates all activities among computer hardware devices Application programs, cannot run without an operating system Example: Windows 98, NT, 2000, XP, or Me Utility program: maintenance-type tasks Example: managing disk drives, printers, other devices

22 1.1 Computer Systems The major tasks of O.S:
Component of a Computer (SW) – Programs The major tasks of O.S: Controlling and monitoring system activities Sending output to the monitor, keeping track of files and directories on the disk Allocating and assigning system resources Determine what computer resources (CPU, memory, disks) a program needs Scheduling operations Scheduling programs to use the system resources efficiently. Support techniques such as multiprogramming, multithreading, and multiprocessing

23 1.2 Programming Language Programming Language: used to write computer instructions Syntax: rules governing word usage and punctuation in the language (like spelling & grammar) Human language: English, Spanish, French, etc…

24 1.3 Categories of Programming Languages
Low-level language High-level language Machine-dependent - runs only on one type of computer Often machine-independent - can run on many different types of computers and operating systems Not easily portable 1 language instruction = 1 machine instruction 1 language instruction = multiple machine instruction Machine and assembly languages are low-level

25 1.3 Categories of Programming Languages
Types of Programming Language: Machine Language Binary (0, 1) – on-off circuitry Directly recognize by computer Assembly Language Symbolic code – mnemonic High-level Language English-like phrase, easy Machine dependent Machine independent

26 1.3 Categories of Programming Languages
Compiler or interpreter: Software that translates into machine language

27 1.3 Categories of Programming Languages
Low-Level Language – Machine Language 1st generation Most primitive (basic) The only language computer directly recognizes The instructions are in the form of binary code Machine-dependent Example:

28 1.3 Categories of Programming Languages
Low-Level Language – Assembly Language 2nd generation Symbolic instruction codes, meaningful abbreviations and codes (English-like phrases) - mnemonic For example, to add two numbers in assembly code ADDF3 R1, R2, R3 An assembler is used to convert assembly language programs into machine code Machine-dependent Example:

29 1.3 Categories of Programming Languages
Low-Level Language – Assembly Language Assembly code Machine code Assembler

30 1.3 Categories of Programming Languages
High-Level Language English-like and easy to learn program To overcome the platform-specific problem and make programming easier. For example, computes the area of a circle with radius 5 in high-level languages Area = 5 * 5 * Popular high-level languages Java COBOL (Common Business Oriented language) FORTRAN (Formula Translation) Pascal Ada BASIC C Visual Basic Delphi C++

31 1.3 Categories of Programming Languages
High-Level Language Source program is a program written in a high-level language Compiler is used to translate the source program into a machine-language program called object program Object file is linked with other supporting library code to form an executable file

32 Check Point 1.10 What language does the CPU understand?
1.11 What is an assembly language? 1.12 What is an assembler? 1.13 What is a high-level programming language? 1.14 What is a source program? 1.15 What is an interpreter? 1.16 What is a compiler? 1.17 What is the difference between an interpreted language and a compiled language?

33 Answer: 1.10 What language does the CPU understand?
Machine language. The machine language is a set of primitive instructions built into every computer. 1.11 What is an assembly language? Assembly language is a low-level programming language in which a mnemonic is used to represent each of the machine language instructions. 1.12 What is an assembler? Assembler is a software that translates assembly language into machine language. 1.13 What is a high-level programming language? The high-level languages are English-like and easy to learn and program.

34 Answer: 1.14 What is a source program? 1.15 What is an interpreter?
The program written in a programming language is called a source program. 1.15 What is an interpreter? An interpreter is a software that reads one statement from the source code, translates it to the machine code or virtual machine code, and then executes it right away. 1.16 What is a compiler? A compiler is a software that translates a program in high-level language into machine language code.

35 Answer: 1.17 What is the difference between an interpreted language and a compiled language? An interpreter reads one statement from the source code, and translates it to the machine code or virtual machine code, and then executes it right away. A compiler translates the entire source code into a machine code file, and the machine code file is then executed.

36 1.4 Simple Program Logic Program execute or run
Program execution process: IPO Programs with syntax errors cannot execute

37 1.4 Simple Program Logic Types of Errors: Syntax errors: Sth that violates programming rules Program cannot run Logic errors (semantic errors): Errors in program logic produce incorrect output Program executed with wrong result. Logic: Sequence of specific instructions in specific order Logic errors are more difficult to locate than syntax errors

38 1.4 Simple Program Logic What’s wrong with this logic for making a cake?

39 1.4 Simple Program Logic Logic for multiplying a number by 2 (includes input, processing and output statements) Get inputNumber. Compute calculatedAnswer as inputNumber times 2. Print calculatedAnswer.

40 1.4 Simple Program Logic

41 1.5 Program Development Cycle
Six programming phases: 1 7 2 6 3 5 4

42 1.5 Program Development Cycle
1. Understand the problem One of the most difficult aspects of programming Users or end users People for whom a program is written Users may not be able to articulate their needs well User needs may be changing frequently Programmers may have to learn the user’s functional job tasks Failure to understand the problem is the major cause of most project failures articulate - clearly

43 1.5 Program Development Cycle
2. Planning the logic Plan the steps that the program will take Heart of the programming process Most common planning tools Flowcharts: a pictorial representation of the logic steps Pseudocode: English-like representation of the logic IPO charts: input, processing, and output chart TOE charts: tasks, objects, and events chart Desk-checking Walking through a program’s logic on paper before you actually write the program

44 1.5 Program Development Cycle
3. Coding the logic Writing the instructions Hundreds of programming languages available Choose based on features Similar in their basic capabilities Easier than the planning step

45 1.5 Program Development Cycle
4. Translate into machine language (compiler) Translator program Compiler or interpreter Changes the programmer’s English-like high-level programming language into the low-level machine language Syntax error Misuse of a language’s grammar rules Identified by the compiler or interpreter Programmer corrects listed syntax errors Might need to recompile the code several times

46 1.5 Program Development Cycle
4. Translate into machine language (compiler) Creating an executable program

47 1.5 Program Development Cycle
5. Testing the program Testing the program: Execute it with sample data and check results Identify logic errors and correct them Choose test data carefully to exercise all branches of the logic Logical error Results when a syntactically correct statement, but the wrong one for the current context, is used Debugging process of finding and correcting program errors

48 1.5 Program Development Cycle
6. Deploy the program Do this after testing is complete and all known errors have been corrected May require coordination with other related activities or software 7. Maintaining the program Maintenance Making changes after the program is put into production Common first programming job Maintaining previously written programs Make changes to existing programs Repeat the development cycle

49 1.5 Program Development Cycle

50 1.6 Using Pseudocode Statements & Flowchart Symbols
Pseudocode: English-like representation of the logic Flowchart: pictorial representation of the logic

51 1.6 Using Pseudocode Statements & Flowchart Symbols
Writing Pseudocode Pseudocode representation of a number-doubling problem start input myNumber set myAnswer = myNumber * 2 output myAnswer stop Beginning statement: start Terminating statement: stop Flexible planning tool

52 1.6 Using Pseudocode Statements & Flowchart Symbols
Drawing flowchart Create a flowchart Draw geometric shapes that contain the individual statements Connect shapes with arrows Input & Output symbol Indicates input & output operation Parallelogram Processing symbol Processing statements such as arithmetic Rectangle

53 1.6 Using Pseudocode Statements & Flowchart Symbols
Drawing flowchart Flowlines Arrows that connect steps Terminal symbols Start/stop symbols Shaped like a racetrack Also called lozenges

54 1.6 Using Pseudocode Statements & Flowchart Symbols
Drawing flowchart Flowchart and pseudocode of program that doubles a number

55 1.6 Using Pseudocode Statements & Flowchart Symbols
Drawing flowchart Repeating Instructions: Previous program Only works for one number Not feasible to run repeatedly (1000 times) Not feasible to add 10,000 lines of code to a program Solution: Create a loop (repetition of a series of steps) instead Avoid an infinite loop (repeating flow of logic that never ends)

56 1.6 Using Pseudocode Statements & Flowchart Symbols
Drawing flowchart Repeating Instructions: Flowchart of infinite number-doubling program

57 1.6 Using Pseudocode Statements & Flowchart Symbols

58 1.7 Using a Sentinel Value to End a Program
Decision: Testing a value Flowchart decision symbol: diamond shape, with two flow lines: Yes & No Sentinel value (dummy value): Does not represent real data Signal to stop Can be used with input from files or from users

59 1.7 Using a Sentinel Value to End a Program
Flowchart of number-doubling program with sentinel value of 0

60 1.7 Using a Sentinel Value to End a Program
Flowchart of number-doubling program with sentinel value of 0

61 1.7 Using a Sentinel Value to End a Program
End-of-file (EOF) marker: Code stored in the file that marks the end of the data Usually used instead of a sentinel value for file input Flowchart using eof

62 1.7 Using a Sentinel Value to End a Program

63 1.8 Three Basic Structure Structure Basic unit of programming logic
3 basic types of structures: Sequence structure Selection structure (decision structure) Loop structure

64 1.8 Three Basic Structure 1. Sequence control structure
Control structure that shows actions following each other in order depicts logical order of program instructions

65 1.8 Three Basic Structure 2. Selection control structure
Tells program which action to take, based on a certain condition Two types Case control structure — Yields one of three or more possibilities If-then-else control structure — yields one of two possibilities: true or false

66 1.8 Three Basic Structure 2. Selection control structure
Case control structure — yields one of three or more possibilities

67 1.8 Three Basic Structure 2. Selection control structure
If-then-else control structure — yields one of two possibilities: true or false

68 1.8 Three Basic Structure 3. Repetition control structure
Enables program to perform one or more actions repeatedly While control structure—repeats as long as condition is true Do-while control structure—repeats until condition is true while Do-while

69 1.9 Programming & User Environment
Many options for programming and user environments Planning Flowchart Pseudocode Coding Text editors Executing Input from keyboard, mouse, microphone Outputting Text, images, sound

70 1.9 Programming & User Environment
Programming environment Use a keyboard to type program statements into an editor Plain text editor Similar to a word processor but without as many features Text editor that is part of an integrated development environment (IDE) Software package that provides an editor, a compiler, and other programming tools

71 1.9 Programming & User Environment
Programming environment Text Editor: A C# number-doubling program in Notepad

72 1.9 Programming & User Environment
Programming environment IDE: A C# number-doubling program in Visual Studio

73 1.9 Programming & User Environment
Ways of executing a program: Command line: Location on your computer screen where you type text entries to communicate with the computer’s operating system Graphical User Interface (GUI): Allows users to interact with a program in a graphical environment Command line GUI

74 1.9 Programming & User Environment

75 1.10 Evolution of Programming Models
Programming began in the 1940s, using memory addresses and machine code directly Higher level languages were developed to allow English-like instructions Older programs were “monolithic,” and ran from beginning to end Newer programs contain modules that can be combined to form programs

76 1.10 Evolution of Programming Models
Two major programming techniques: Procedural programming focuses on the procedures that programmers create Object-oriented programming Focuses on objects, or “things,” and describes their features (or attributes) and their behaviors Both techniques employ reusable program modules This text Focuses on procedural programming techniques

77 1.10 Evolution of Programming Models

78 Summary Hardware and software accomplish three major operations: input, processing, and output Logic must be developed correctly Logical errors are much more difficult to locate than syntax errors Program development cycle: understanding, planning, coding, translating, testing, employ, and maintain. Use flowcharts, pseudocode, IPO charts, and TOE charts to plan the logic Avoid infinite loops by testing for a sentinel value Use a text editor or an IDE to enter your program statements Procedural programmers concentrate on the actions performed with data. Object-oriented programmers focus on objects and their behaviors and attributes


Download ppt "CHAPTER 1 C++ Programming - Introduction"

Similar presentations


Ads by Google