CHAPTER 1 C++ Programming - Introduction

Slides:



Advertisements
Similar presentations
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Advertisements

Lecture 1: Overview of Computers & Programming
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Programming Logic and Design Fourth Edition, Introductory
An Overview of Computers and Programming
CS102 Introduction to Computer Programming
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Programming Logic and Design Fifth Edition, Comprehensive
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Lesson 3 — How a Computer Processes Data
Topics Introduction Hardware and Software How Computers Store Data
INTRODUCTION TO COMPUTING
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computer Science.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Computer and Operating System.
CPU (CENTRAL PROCESSING UNIT): processor chip (computer’s brain) found on the motherboard.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
CISC105 General Computer Science Class 1 – 6/5/2006.
An Introduction to Computers August 12, 2008 Mrs. C. Furman.
P ROGRAMMING L OGIC AND D ESIGN S IXTH E DITION Chapter 1 An Overview of Computers and Programming.
Lesson 3 — How a Computer Processes Data Unit 1 — Computer Basics.
An Object-Oriented Approach to Programming Logic and Design Chapter 1 An Overview of Computers and Logic.
Liang, Introduction to C++ Programming, (c) Chapter 1 Introduction to Computers, Programs, and C++
Computer Basic Vocabulary
ELEMENTS OF A COMPUTER SYSTEM HARDWARE SOFTWARE PEOPLEWARE DATA.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Programming Logic and Design Seventh Edition
Digital Literacy: Computer Basics
IC 3 BASICS, Internet and Computing Core Certification Computing Fundamentals Lesson 2 How Does a Computer Process Data?
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
CHAPTER 1 Introduction to Computers and Programming Lecturer: Dept. of Electrical and Electronic Engineering 1.
Chapter 1: Introduction to Computers and Programming
Chapter 1 Introduction 2nd Semester H
Introduction to Computers
Chapter 1 Introduction to Computers, Programs, and C++
Section 2.1 Section 2.2 Identify hardware
BASIC PROGRAMMING C SCP1103 (02)
An Overview of the Computer System
Chapter 1: An Overview of Computers and Programming Languages
Topics Introduction Hardware and Software How Computers Store Data
Chapter 1 Introduction to Computers, Programs, and C++
CSCI-235 Micro-Computer Applications
BASIC PROGRAMMING C SCP1103 (02)
DDC 1023 – Programming Technique
Technology Literacy Hardware.
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Course Name: Computer Application Topic: Central Processing Unit (CPU)
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Introduction to Computers
Looking Inside the machine (Types of hardware, CPU, Memory)
Introduction to Computing Lecture # 1
Chapter 1: Introduction to Computers and Programming
An Overview of the Computer System
Topics Introduction Hardware and Software How Computers Store Data
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Introduction to computers
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Data Communications and Computer Networks
Computer and Operating System slides extended from Liang’s Java Programming textbook by Professor Parson for CSC 352.
ICS103 Programming in C 1: Overview of Computers And Programming
Programming Logic and Design Eighth Edition
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

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

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

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

1.1 Computer Systems Component of a Computer (HW)

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…

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. http://www.computerhope.com/jargon/e/expaslot.htm 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. http://www.proprofs.com/mwiki/index.php/Understanding_RAM_Types:_DRAM_SDRAM_DIMM_SIMM_And_More 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.

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:

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.

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)

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

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

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

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)

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)

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?

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).

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.

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.

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

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.

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

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

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…

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

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

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

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 1101101010011010 Machine-dependent Example:

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:

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

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 * 3.1415 Popular high-level languages Java COBOL (Common Business Oriented language) FORTRAN (Formula Translation) Pascal Ada BASIC C Visual Basic Delphi C++

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

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?

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.

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.

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.

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

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

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

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.

1.4 Simple Program Logic

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

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

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

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

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

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

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

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

1.5 Program Development Cycle

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

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

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

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

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

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)

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

1.6 Using Pseudocode Statements & Flowchart Symbols

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

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

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

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

1.7 Using a Sentinel Value to End a Program

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

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

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

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

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

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

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

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

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

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

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

1.9 Programming & User Environment

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

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

1.10 Evolution of Programming Models

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