Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Similar documents
Python Programming: An Introduction to Computer Science

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 5. Functions for All Subtasks. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 10. Defining Classes. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup Note:

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

Elementary Educational Computer

Chapter 2. C++ Basics. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

CS 11 C track: lecture 1

GE FUNDAMENTALS OF COMPUTING AND PROGRAMMING UNIT III

Baan Tools User Management

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

Appendix D. Controller Implementation

Python Programming: An Introduction to Computer Science

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

CS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Fundamentals of. Chapter 1. Microprocessor and Microcontroller. Dr. Farid Farahmand. Updated: Tuesday, January 16, 2018

. Written in factored form it is easy to see that the roots are 2, 2, i,

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

Computers and Scientific Thinking

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway.

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

One advantage that SONAR has over any other music-sequencing product I ve worked

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

CS 111: Program Design I Lecture # 7: Web Crawler, Functions; Open Access

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers?

COMP Parallel Computing. PRAM (1): The PRAM model and complexity measures

Overview Chapter 12 A display model

Algorithm. Counting Sort Analysis of Algorithms

CS : Programming for Non-Majors, Summer 2007 Programming Project #3: Two Little Calculations Due by 12:00pm (noon) Wednesday June

Getting Started. Getting Started - 1

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Part A Datapath Design

EE 459/500 HDL Based Digital Design with Programmable Logic. Lecture 13 Control and Sequencing: Hardwired and Microprogrammed Control

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

EE University of Minnesota. Midterm Exam #1. Prof. Matthew O'Keefe TA: Eric Seppanen. Department of Electrical and Computer Engineering

Architectural styles for software systems The client-server style

1.2 Binomial Coefficients and Subsets

Lecture 1: Introduction and Strassen s Algorithm

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Analysis of Algorithms

the beginning of the program in order for it to work correctly. Similarly, a Confirm

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

How do we evaluate algorithms?

Chapter 3. More Flow of Control. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

A New Morphological 3D Shape Decomposition: Grayscale Interframe Interpolation Method

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions

Code Review Defects. Authors: Mika V. Mäntylä and Casper Lassenius Original version: 4 Sep, 2007 Made available online: 24 April, 2013

implement language system

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

BAAN IVc/BaanERP. Conversion Guide Oracle7 to Oracle8

top() Applications of Stacks

APPLICATION NOTE PACE1750AE BUILT-IN FUNCTIONS

K-NET bus. When several turrets are connected to the K-Bus, the structure of the system is as showns

9.1. Sequences and Series. Sequences. What you should learn. Why you should learn it. Definition of Sequence

Chapter 4 The Datapath

CMSC Computer Architecture Lecture 12: Virtual Memory. Prof. Yanjing Li University of Chicago

6.854J / J Advanced Algorithms Fall 2008

Lecturers: Sanjam Garg and Prasad Raghavendra Feb 21, Midterm 1 Solutions

Avid Interplay Bundle

n We have discussed classes in previous lectures n Here, we discuss design of classes n Library design considerations

Data Structures and Algorithms. Analysis of Algorithms

Parabolic Path to a Best Best-Fit Line:

Threads and Concurrency in Java: Part 1

Threads and Concurrency in Java: Part 1

Introduction CHAPTER Computers

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Outline. CSCI 4730 Operating Systems. Questions. What is an Operating System? Computer System Layers. Computer System Layers

CSE 111 Bio: Program Design I Class 11: loops

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5.

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

The VSS CCD photometry spreadsheet

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

CSE 111 Bio: Program Design I Lecture 17: software development, list methods

Evaluation scheme for Tracking in AMI

CIS 121 Data Structures and Algorithms with Java Fall Big-Oh Notation Tuesday, September 5 (Make-up Friday, September 8)

CIS 121 Data Structures and Algorithms with Java Spring Stacks and Queues Monday, February 12 / Tuesday, February 13

Definitions. Error. A wrong decision made during software development

TargetLink. Installation Notes. MATLAB R14SP3 Compatibility Update for TargetLink 2.1

A SOFTWARE MODEL FOR THE MULTILAYER PERCEPTRON

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

In this chapter, you learn the concepts and terminology of databases and

Exercise 6 (Week 42) For the foreign students only.

Structuring Redundancy for Fault Tolerance. CSE 598D: Fault Tolerant Software

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

Computer Systems - HS

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5

3.1 Overview of MySQL Programs. These programs are discussed further in Chapter 4, Database Administration. Client programs that access the server:

The Magma Database file formats

From last week. Lecture 5. Outline. Principles of programming languages

Chapter 4 Threads. Operating Systems: Internals and Design Principles. Ninth Edition By William Stallings

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016

Transcription:

Chapter 1 Itroductio to Computers ad C++ Programmig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Overview 1.1 Computer Systems 1.2 Programmig ad Problem Solvig 1.3 Itroductio to C++ 1.4 Testig ad Debuggig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

1.1 Computer Systems Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Computer Systems A computer program is A set of istructios for a computer to follow Computer software is The collectio of programs used by a computer Icludes: Editors Traslators System Maagers Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Hardware Three mai classes of computers PCs (Persoal Computer) Relatively small used by oe perso at a time Workstatio Larger ad more powerful tha a PC Maiframe Still larger Requires support staff Shared by multiple users Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Networks A umber of computers coected to share resources Share priters ad other devices Share iformatio Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Computer Orgaizatio Five mai compoets Iput devices Allows commuicatio to the computer Output devices Allows commuicatio to the user Processor (CPU) Mai memory Memory locatios cotaiig the ruig program Secodary memory Permaet record of data ofte o a disk Display 1.1 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Computer Memory Mai Memory Log list of memory locatios Each cotais zeros ad oes Ca chage durig program executio Biary Digit or Bit A digit that ca oly be zero or oe Byte Each memory locatio has eight bits Address Number that idetifies a memory locatio Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Larger Data Items Some data is too large for a sigle byte Most itegers ad real umbers are too large Address refers to the first byte Next few cosecutive bytes ca store the additioal bits for larger data Display 1.2 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Data or Code? A may look like 01000001 65 may look like 01000001 A istructio may look like 01000001 How does the computer kow the meaig of 01000001? Iterpretatio depeds o the curret istructio Programmers rarely eed to be cocered with this problem. Reaso as if memory locatios cotai letters ad umbers rather tha zeroes ad oes Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Secodary Memory Mai memory stores istructios ad data while a program is ruig. Secodary memory Stores istructios ad data betwee sessios A file stores data or istructios i secodary memory Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Secodary Memory Media A computer might have ay of these types of secodary memory Hard disk Fast Fixed i the computer ad ot ormally removed Floppy disk Slow Easily shared with other computers Compact disk Slower tha hard disks Easily shared with other computers Ca be read oly or re-writable Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Memory Access Radom Access Usually called RAM Computer ca directly access ay memory locatio Sequetial Access Data is geerally foud by searchig through other items first More commo i secodary memory Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

The Processor Typically called the CPU Cetral Processig Uit Follows program istructios Typical capabilities of CPU iclude: add subtract multiply divide move data from locatio to locatio Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Computer Software The operatig system Allows us to commuicate with the computer Is a program Allocates the computer s resources Respods to user requests to ru other programs Commo operatig systems iclude UNIX Liux DOS Widows Macitosh VMS Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Computer Iput Computer iput cosists of A program Some data Display 1.3 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

High-level Laguages Commo programmig laguages iclude C C++ Java Pascal Visual Basic FORTRAN Perl PHP Lisp Scheme Ada C# Pytho These high level laguages Resemble huma laguages Are desiged to be easy to read ad write Use more complicated istructios tha the CPU ca follow Must be traslated to zeros ad oes for the CPU to execute a program Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Low-level Laguages A assembly laguage commad such as ADD X Y Z might mea add the values foud at x ad y i memory, ad store the result i locatio z. Assembly laguage must be traslated to machie laguage (zeros ad oes) 0110 1001 1010 1011 The CPU ca follow machie laguage Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Compilers Traslate high-level laguage to machie laguage Source code The origial program i a high level laguage Object code The traslated versio i machie laguage Display 1.4 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Likers Some programs we use are already compiled Their object code is available for us to use For example: Iput ad output routies A Liker combies The object code for the programs we write ad The object code for the pre-compiled routies ito The machie laguage program the CPU ca ru Display 1.5 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

History Note First programmable computer Desiged by Charles Babbage Bega work i 1822 Not completed i Babbage s life time First programmer Ada Augusta, Coutess of Lovelace Colleague of Babbage Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Sectio 1.1 Coclusio Ca you List the five mai compoets of a computer? List the data for a program that adds two umbers? Describe the work of a compiler? Defie source code? Defie object code? Describe the purpose of the operatig system? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

1.2 Programmig ad Problem- Solvig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Algorithms Algorithm A sequece of precise istructios that leads to a solutio Program A algorithm expressed i a laguage the computer ca uderstad Display 1.6 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Program Desig Programmig is a creative process No complete set of rules for creatig a program Program Desig Process Problem Solvig Phase Result is a algorithm that solves the problem Implemetatio Phase Result is the algorithm traslated ito a programmig laguage Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Problem Solvig Phase Be certai the task is completely specified What is the iput? What iformatio is i the output? How is the output orgaized? Develop the algorithm before implemetatio Experiece shows this saves time i gettig your program to ru. Test the algorithm for correctess Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Implemetatio Phase Traslate the algorithm ito a programmig laguage Easier as you gai experiece with the laguage Compile the source code Locates errors i usig the programmig laguage Ru the program o sample data Verify correctess of results Results may require modificatio of the algorithm ad program Display 1.7 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Object Orieted Programmig Abbreviated OOP Used for may moder programs Program is viewed as iteractig objects Each object cotais algorithms to describe its behavior Program desig phase ivolves desigig objects ad their algorithms Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

OOP Characteristics Ecapsulatio Iformatio hidig Objects cotai their ow data ad algorithms Iheritace Writig reusable code Objects ca iherit characteristics from other objects Polymorphism A sigle ame ca have multiple meaigs depedig o its cotext Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Software Life Cycle Aalysis ad specificatio of the task (problem defiitio) Desig of the software (object ad algorithm desig) Implemetatio (codig) Maiteace ad evolutio of the system Obsolescece Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Sectio 1.2 Coclusio Ca you Describe the first step to take whe creatig a program? List the two mai phases of the program desig process? Explai the importace of the problem-solvig phase? List the steps i the software life cycle? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

1.3 Itroductio to C++ Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Itroductio to C++ Where did C++ come from? Derived from the C laguage C was derived from the B laguage B was derived from the BCPL laguage Why the ++? ++ is a operator i C++ ad results i a cute pu Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

C++ History C developed by Deis Ritchie at AT&T Bell Labs i the 1970s. Used to maitai UNIX systems May commercial applicatios writte i c C++ developed by Bjare Stroustrup at AT&T Bell Labs i the 1980s. Overcame several shortcomigs of C Icorporated object orieted programmig C remais a subset of C++ Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

A Sample C++ Program A simple C++ program begis this way #iclude <iostream> usig amespace std; it mai() { Ad eds this way } retur 0; Display 1.8 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Explaatio of code (1/5) Variable declaratio lie it umber_of_pods, peas_per_pod, total_peas; Idetifies ames of three variables to ame umbers it meas that the variables represet itegers Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Explaatio of code (2/5) Program statemet cout << Press retur after eterig a umber.\ ; cout (see-out) used for output to the moitor << iserts Press a umber.\ i the data boud for the moitor Thik of cout as a ame for the moitor << poits to where the data is to ed up \ causes a ew lie to be started o the moitor Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Explaatio of code (3/5) Program statemet ci >> umber_of_pods; ci (see-i) used for iput from the keyboard >> extracts data from the keyboard Thik of ci as a ame for the keyboard >> poits from the keyboard to a variable where the data is stored Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Explaatio of code (4/5) Program statemet total_peas = umber_of_pods * peas_per_pod; Performs a computatio * is used for multiplicatio = causes total_peas to get a ew value based o the calculatio show o the right of the equal sig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Explaatio of code (5/5) Program statemet cout << umber_of_pods; Seds the value of variable umber_of_pods to the moitor Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Program Layout (1/3) Compiler accepts almost ay patter of lie breaks ad idetatio Programmers format programs so they are easy to read Place opeig brace { ad closig brace } o a lie by themselves Idet statemets Use oly oe statemet per lie Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Program Layout (2/3) Variables are declared before they are used Typically variables are declared at the begiig of the program Statemets (ot always lies) ed with a semi-colo Iclude Directives #iclude <iostream> Tells compiler where to fid iformatio about items used i the program iostream is a library cotaiig defiitios of ci ad cout Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Program Layout (3/3) usig amespace std; Tells the compiler to use ames i iostream i a stadard way To begi the mai fuctio of the program it mai() { To ed the mai fuctio retur 0; } Mai fuctio eds with a retur statemet Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Ruig a C++ Program C++ source code is writte with a text editor The compiler o your system coverts source code to object code. The liker combies all the object code ito a executable program. Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

C++11 C++11 (formerly kow as C++0x) is the most recet versio of the stadard of the C++ programmig laguage. Approved o August 12, 2011 by the Iteratioal Orgaizatio for Stadardizatio. C++11 laguage features are ot supported by older compilers Check the documetatio with your compiler to determie if special steps are eeded to compile C++11 programs e.g. with g++, use extra flags of std=c++11 Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Ru a Program Obtai code i Display 1.10 Compile the code Fix ay errors the compiler idicates ad re-compile the code Ru the program Display 1.10 Now you kow how to ru a program o your system Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Sectio 1.3 Coclusio Ca you Describe the output of this lie? cout << C++ is easy to uderstad. ; Explai what this lie does? ci >> peas_per_pod; Explai this? #iclude <iostream> Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

1.4 Testig ad Debuggig Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Testig ad Debuggig Bug A mistake i a program Debuggig Elimiatig mistakes i programs Term used whe a moth caused a failed relay o the Harvard Mark 1 computer. Grace Hopper ad other programmers taped the moth i logbook statig: First actual case of a bug beig foud. Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Program Errors Sytax errors Violatio of the grammar rules of the laguage Discovered by the compiler Error messages may ot always show correct locatio of errors Ru-time errors Error coditios detected by the computer at ru-time Logic errors Errors i the program s algorithm Most difficult to diagose Computer does ot recogize a error Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Sectio 1-4 Coclusio Ca you Describe the three kids of program errors? Tell what kid of errors the compiler catches? What kid of error is produced if you forget a puctuatio symbol such as a semi-colo? Tell what type of error is produced whe a program rus but produces icorrect results? Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Chapter 1 -- Ed Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Display 1.1 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Display 1.2 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Display 1.3 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Display 1.4 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Display 1.5 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Display 1.6 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Display 1.7 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Display 1.8 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Display 1.9 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.

Display 1.10 Back Next Copyright 2015 Pearso Educatio, Ltd.. All rights reserved.