Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.

Slides:



Advertisements
Similar presentations
C++ Introduction.
Advertisements

Copyright © 2003 Pearson Education, Inc. Slide 1.
Introduction to Programming in C++ John Galletly.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
INTRODUCTION T.Najah Al_Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System CS240.
COSC 120 Computer Programming
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
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.
Chapter 1 Introduction to Computers and C++ Programming.
Three types of computer languages
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
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.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
Chapter 1: Introduction to Visual Basic.NET: Background and Perspective Visual Basic.NET Programming: From Problem Analysis to Program Design.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Introduction to Computers and C++ Programming.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Instructor: Tina Tian. About me Office: RLC 203A Office Hours: Wednesday 1:30 - 4:30 PM or .
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Copyright © 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1 Introduction to Computers and C++ Programming.
Computer Programming TCP1224 Chapter 3 Completing the Problem-Solving Process and Getting Started with C++
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Chapter 1 Introduction to Computer and C++ Programming.
Copyright © 2015 Pearson Education, Ltd.. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Mohamed Iqbal Pallipurath Slide 1. Mohamed Iqbal Pallipurath Slide 2 Basics Introduction to Computers and C++ Programming.
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)
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Copyright © 2012 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
12/18/2015 CSI Chapter 1 1 Compiler + Linker = Ready to run code Compiler translates high-level language source code into an intermediate object.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Agenda Computer Languages How to Write a Simple C Program
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 © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
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.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Software Engineering Algorithms, Compilers, & Lifecycle.
Algorithms, problem solving and Introduction to C++
Foundations of Computer Science C & C++ programming lecture 2
Introduction to Computers and C++ Programming
Introduction to Computers and C++ Programming
Algorithms, problem solving and Introduction to C++
Introduction to Computers and C++ Programming
Chapter 2 Introduction to C++ Programming
Completing the Problem-Solving Process
Chapter 2 – Getting Started
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Programs written in C and C++ can run on many different computers
Programming Fundamentals (750113) Ch1. Problem Solving
Capitolo 1 – Introduction C++ Programming
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ Programming

Our textbook

The Slides These will be posted and left on the web for review purposes. These will be posted and left on the web for review purposes. The slides are NOT a substitute for class attendance and participation. The slides are NOT a substitute for class attendance and participation. Many of these slides are provided by the author of the text. I have frequently revised or added information to existing slides as well as created new slides. I have frequently revised or added information to existing slides as well as created new slides.

Slide 1- 4 Overview - We'll cover this rather quickly 1.1 Computer Systems -review this in the text on your own as it was covered in and is not essential for this course. 1.2 Programming and Problem Solving 1.3 Introduction to C Testing and Debugging

Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1.2 Programming and Problem- Solving

Slide 1- 6 Algorithms Algorithm A sequence of precise instructions that leads to a solution A sequence of precise instructions that leads to a solutionProgram An algorithm expressed in a language the computer can understand An algorithm expressed in a language the computer can understand

Slide 1- 7 Program Design Programming is a creative process No complete set of rules for creating a program exist. No complete set of rules for creating a program exist. Program Design Process Problem Solving Phase Problem Solving Phase Result is an algorithm that solves the problem Implementation Phase Implementation Phase Result is the algorithm is translated into a programming language

Slide 1- 8 Problem Solving Phase Be certain the task is completely specified What is the input? What is the input? What information is in the output? What information is in the output? How is the output organized? How is the output organized? Develop the algorithm before implementation Experience shows this saves time in getting your program to run. Experience shows this saves time in getting your program to run. Test the algorithm for correctness Test the algorithm for correctness

Translate the algorithm into a programming language Easier as you gain experience with the language Easier as you gain experience with the language Compile the source code Locates errors in using the programming language Locates errors in using the programming language Run the program on sample data Verify correctness of results Verify correctness of results Results may require modification of the algorithm and program Slide 1- 9 Implementation Phase

Slide Object Oriented Programming Abbreviated OOP Used for many modern programs Program is viewed as interacting objects Each object contains algorithms to describe its behavior Each object contains algorithms to describe its behavior Program design phase involves designing objects and their algorithms Program design phase involves designing objects and their algorithms

Slide OOP Characteristics Encapsulation Information hiding Information hiding Objects contain their own data and algorithms Objects contain their own data and algorithmsInheritance Writing reusable code Writing reusable code Objects can inherit characteristics from other objects Objects can inherit characteristics from other objectsPolymorphism A single name can have multiple meanings depending on its context A single name can have multiple meanings depending on its context

Slide Software Life Cycle Analysis and specification of the task (problem definition) Design of the software (object and algorithm design) Implementation (coding) Maintenance and evolution of the system Obsolescence

Slide Section 1.2 Conclusion Can you… Describe the first step to take when creating a program? Describe the first step to take when creating a program? List the two main phases of the program design process? List the two main phases of the program design process? Explain the importance of the problem-solving phase? Explain the importance of the problem-solving phase? List the steps in the software life cycle? List the steps in the software life cycle?

Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1.3 Introduction to C++

Slide Introduction to C++ Where did C++ come from? Derived from the C language Derived from the C language C was derived from the B language C was derived from the B language B was derived from the BCPL language B was derived from the BCPL language Why the ‘++’? ++ is an operator in C++ and results in a cute pun ++ is an operator in C++ and results in a cute pun

Slide C++ History C developed by Dennis Ritchie at AT&T Bell Labs in the 1970s. Used to maintain UNIX systems Used to maintain UNIX systems Many commercial applications written in C Many commercial applications written in C C++ developed by Bjarne Stroustrup at AT&T Bell Labs in the 1980s. Overcame several shortcomings of C Overcame several shortcomings of C Incorporated object oriented programming Incorporated object oriented programming C remains a subset of C++ C remains a subset of C++

A simple C++ program begins this way #include using namespace std; int main() { And ends this way return 0; } Slide A Sample C++ Program

Note: In order to fit the code comfortably on a few number of slides, I won't always add comments. This does NOT mean that you should do that also!!

<==== Optional

Slide Explanation of code (1/5) Variable declaration line int number_of_pods, peas_per_pod, total_peas; Identifies names of three variables to name numbers Identifies names of three variables to name numbers int means that the variables represent integers int means that the variables represent integers

Slide Explanation of code (2/5) Program statement cout << “Press return after entering a number.\n”; cout (see-out) used for output to the monitor cout (see-out) used for output to the monitor “<<“ inserts “Press…a number.\n” in the data bound for the monitor “<<“ inserts “Press…a number.\n” in the data bound for the monitor Think of cout as a name for the monitor Think of cout as a name for the monitor “<<“ points to where the data is to end up ‘\n’ causes a new line to be started on the monitor ‘\n’ causes a new line to be started on the monitor

Slide Explanation of code (3/5) Program statement cin >> number_of_pods; cin (see-in) used for input from the keyboard cin (see-in) used for input from the keyboard “>>” extracts data from the keyboard “>>” extracts data from the keyboard Think of cin as a name for the keyboard Think of cin as a name for the keyboard “>>” points from the keyboard to a variable where the data is stored

Slide Explanation of code (4/5) Program statement total_peas = number_of_pods * peas_per_pod; Performs a computation Performs a computation ‘*’ is used for multiplication ‘*’ is used for multiplication ‘=‘ causes total_peas to get a new value based on the calculation shown on the right of the equal sign ‘=‘ causes total_peas to get a new value based on the calculation shown on the right of the equal sign

Slide Explanation of code (5/5) Program statement cout << number_of_pods; Sends the value of variable number_of_pods to the monitor Sends the value of variable number_of_pods to the monitor

Slide 1- 27

Slide Program Layout (1/3) Compiler accepts almost any pattern of line breaks and indentation Programmers format programs so they are easy to read Place opening brace ‘{‘ and closing brace ‘}’ on a line by themselves Place opening brace ‘{‘ and closing brace ‘}’ on a line by themselves Indent statements Indent statements Use only one statement per line Use only one statement per line

Slide Program Layout (2/3) Variables are declared before they are used Typically variables are declared at the beginning of the program Typically variables are declared at the beginning of the program Statements (not always lines) end with a semi-colon Statements (not always lines) end with a semi-colon Include Directives #include Include Directives #include Tells compiler where to find information about items used in the program Tells compiler where to find information about items used in the program iostream is a library containing definitions of cin and cout iostream is a library containing definitions of cin and cout

Slide Program Layout (3/3) using namespace std; Tells the compiler to use names in iostream in a “standard” way Tells the compiler to use names in iostream in a “standard” way To begin the main function of the program To begin the main function of the program int main() { To end the main function return 0; } Main function ends with a return statement Main function ends with a return statement

Slide Running a C++ Program C++ source code is written with a text editor The compiler on your system converts source code to object code. The linker combines all the object code into an executable program.

Use ssh to connect to the computer on which you have an account. I will use putty for ssh and loki.cs.kent.edu. In the lab you will use a similar version of ssh. However, I want to have be able to set the font larger than that one allows. If you want putty for your machine, go to Choose downloads and download PuTTY (the Telnet and SSH client itself) Slide Running a C++ Program

Make ssh Selections

Optional Selection to Increase Font Size

Press OK and then Open to obtain a window in loki.cs.kent.edu Login with your departmental username and password.

Create a Subdirectory and Move There create cs1 move to cs1 check path to cs1 list contents of cs1 currently empty

Code We Will Run Use vim as the Editor

Invoke vim

Type i to start the insertion of code

To Save and Exit push ESC Then shift : Then wq for write and quit

testing.cpp is written and is listed in the current directory

Compile and Run compile executable file for testing run testing.cpp Output is correct list contents of diretory

To Use a Name Other Than a.out for the Executable

Slide Section 1.3 Conclusion Can you… Describe the output of this line? cout << “C++ is easy to understand.”; Describe the output of this line? cout << “C++ is easy to understand.”; Explain what this line does? cin >> peas_per_pod; Explain what this line does? cin >> peas_per_pod; Explain this? #include Explain this? #include

Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1.4 Testing and Debugging

Slide Testing and Debugging Bug A mistake in a program A mistake in a programDebugging Eliminating mistakes in programs Eliminating mistakes in programs Term used when a moth caused a failed relay on the Harvard Mark 1 computer. Grace Hopper and other programmers taped the moth in logbook stating: “First actual case of a bug being found.” Term used when a moth caused a failed relay on the Harvard Mark 1 computer. Grace Hopper and other programmers taped the moth in logbook stating: “First actual case of a bug being found.”

Slide Program Errors Syntax errors Violation of the grammar rules of the language Violation of the grammar rules of the language Discovered by the compiler Discovered by the compiler Error messages may not always show correct location of errors Run-time errors Error conditions detected by the computer at run-time Error conditions detected by the computer at run-time Logic errors Errors in the program’s algorithm Errors in the program’s algorithm Most difficult to diagnose Most difficult to diagnose Computer does not recognize an error Computer does not recognize an error

Slide Section 1-4 Conclusion Can you… Describe the three kinds of program errors? Describe the three kinds of program errors? Tell what kind of errors the compiler catches? Tell what kind of errors the compiler catches? What kind of error is produced if you forget a punctuation symbol such as a semi-colon? What kind of error is produced if you forget a punctuation symbol such as a semi-colon? Tell what type of error is produced when a program runs but produces incorrect results? Tell what type of error is produced when a program runs but produces incorrect results?

In the Lab You Will Learn About the Following ssh ssh The file structure for UNIX/Linux Simple UNIX/Linux commands - Simple UNIX/Linux commands - lscatmkdirdelrmdirpwd cdcpmvmanmoreg++ gdbexitapropos Using the editor vim Using g++ and the debugger gdb How to submit programs