Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
COSC 120 Computer Programming
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
Three types of computer languages
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
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.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Basic Elements of C++ Chapter 2.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
CS102 Introduction to Computer Programming
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
Introduction to Programming Dr Masitah Ghazali Programming Techniques I SCJ1013.
COMPUTER SCIENCE I C++ INTRODUCTION
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Introduction to Programming. Our Book in CS Why Program? Lets watch a video
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,
Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
1 12/4/1435 h Lecture 2 Programs and Programming Languages.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Introduction عزيزتي الطالبة : يهدف هذا المبحث من تمكينك من التعرف الى مفهوم لغات البرمجة وتعلم أسياسيات لغة البرمجة من خلال دراسة أجزاء من لغة C++ وكتابة.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming Dr. Halla Abdel Hameed.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Chapter 1: Introduction to Computers and Programming.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming
BASIC PROGRAMMING C SCP1103 (02)
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1: Introduction to computers and C++ Programming
Completing the Problem-Solving Process
BASIC PROGRAMMING C SCP1103 (02)
Basic Elements of C++.
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
Chapter 1. Introduction to Computers and Programming
C++ Programming: From Problem Analysis to Program Design
Computer science By/ Midhat Mohiey. Introduction to Programming using C ++ 2.
Basic Elements of C++ Chapter 2.
Chapter 1: Introduction to Computers and Programming
Programs written in C and C++ can run on many different computers
Chapter 1 c++ structure C++ Input / Output
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 2 Contents 1.3 Programs and Programming Languages 1.4 What Is a Program Made of? 1.5 Input, Processing, and Output 1.6 The Programming Process 1.7 Procedural and Object-Oriented Programming

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 3 Software – Programs That Run on a Computer Categories of software: –Operating system: programs that manage the computer hardware and the programs that run on them. Ex: Windows, UNIX, Linux –Application software: programs that provide services to the user. Ex: word processing, games, programs to solve specific problems

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide Programs and Programming Languages Program: a set of instructions to a computer to perform a task Programming Language: a language used to write programs

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 5 Programs and Programming Languages Types of languages: –Low-level: used for communication with computer hardware directly. Often written in binary machine code (0’s/1’s) directly. –High-level: closer to human language

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 6 Table 1-1

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 7 From a High-level Program to an Executable File a)Code the program with a text editor or using an IDE. b)Run preprocessor to convert source file directives to source code program statements. c)Run compiler to convert source program statements into machine language instructions. d)Run linker to connect hardware-specific code to machine instructions, producing an executable file. -Steps b–d are often performed by a single command or button click. -Errors detected at any step will prevent execution of following steps.

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 8 From a High-level Program to an Executable File Source Code Preprocessor Modified Source Code Compiler Object Code Linker Executable Code

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 9 C and C++ Both languages were developed at Bell Labs C was written by Dennis Ritchie in 1972 C++ was written by Bjarne Stroustrup in the early 1980’s C++ extends the C language to permit object- oriented programming

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide What Is a Program Made Of? Common elements in programming languages: –Keywords –Programmer-Defined Symbols –Operators –Punctuation –Syntax

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 11 Language Elements, Table 1-2

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 12 Example Program #include using namespace std; int main() { string name; cout << "What is your name? "; cin >> name; cout << "Hello there, " << name; return 0; }

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 13 Program 1-1 // This program calculates gross pay. #include using namespace std; int main() { double hours, rate, pay; cout << “How many hours did you work? ”; cin >> hours; cout << “How much do you get paid per hour? ”; cin >> rate; pay = hours * rate; cout << “You have earned $” << pay << endl; return 0; }

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 14 Program Output How many hours did you work? 10 How much do you get paid per hour? 15 You have earned $150

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 15 Key Words Also known as reserved words Have a special meaning in C++ Can not be used for another purpose Examples in program: –using, namespace, int

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 16 Programmer-Defined Symbols ( Identifiers ) Names made up by the programmer Not part of the C++ language Used to represent various things: –variables (memory locations), functions, etc. Example in program: –name, hours, rate, calcPay()

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 17 Operators Used to perform operations on data Many types of operators: Arithmetic: +, -, *, /, % Assignment: = Examples in program: <<stream insertion operator >> stream extraction operator

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 18 Punctuation Characters that mark the end of a statement, or that separate items in a list Examples in program: – ;, ~ () []

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 19 Syntax The rules of grammar that must be followed when writing a program Controls the use of: –key words –operators –programmer-defined symbols –punctuation

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 20 Lines and Statements cout << "How many hours did you work? "; cout << "How many hours " << "did you work? "; There are 2 statements above. The first statement uses one line the second statements spans two lines the semicolon ( ; ) is the statement terminator

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 21 Variable Definitions Two types of information: –numbers and characters Numbers may be integers or floating-point The statement below creates three variables in memory named hours, rate, and pay that each can store a floating- point number double hours, rate, pay;

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide Input, Processing, and Output Three steps many programs perform: 1)Gather input data: -from keyboard -from files on disk drives 2)Process the input data 3)Generate output: -send it to the screen -write it to a file

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide Input, Processing, and Output Output cout << "Enter your hours and rate " << "separated by a space: "; Input: cin >> hours; cin >> rate; Processing: pay = hours * rate; Output cout << “You have earned $” << pay;

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide The Programming Process The programming process consists of several steps, which include: –Design –Code –Test –Debug –Document

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide The Programming Process 1.Clearly define what the program is to do. Inputs / Processing / Outputs 2.Develop logic using a flowchart or pseudocode. 3.Desk check for logical errors. 4.Enter/Edit the code and compile it. 5.Correct any errors found during compilation. Repeat steps 4 and 5 as many times as necessary.

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide 26 The Programming Process 6.Run the program with test data for input. 7.Correct any errors found while running the program. Repeat steps 4 through 7 as many times as necessary. 8.Validate the results of the program.

4 th Ed. Home Page4 th Ed. Home Page Appendices AppendicesChapter 1 slide Procedural and Object-Oriented Programming Procedural programming: focus is on the process. Procedures/functions are written to process data. Object-Oriented programming: focus is on objects, which contain data and the means to manipulate the data. Messages are sent to objects to perform operations.