1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague,

Slides:



Advertisements
Similar presentations
COSC 120 Computer Programming
Advertisements

Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction to Computers and C++ 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.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Chapter 1 Introduction to Computers and C++ Programming.
Three types of computer languages
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
Chapter 1: An Overview of Computers and Programming Languages
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: 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.
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.
COMPUTER SCIENCE I C++ INTRODUCTION
Introduction 01_intro.ppt
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
© 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 © 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 1 What is Programming? Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
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,
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.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
1 C++ Programming Basics Chapter 1 Lecture CSIS 10A.
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.
A.Abhari CPS1251 Topic 1: Introduction to Computers Computer Hardware Computer components Connecting Computers Computer Software Operating System (OS)
Computer and Programming. Computer Basics: Outline Hardware and Memory Programs Programming Languages and Compilers.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
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.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
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.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Software Engineering Algorithms, Compilers, & Lifecycle.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
Chapter 1: Introduction to Computers and Programming
Introduction to Computers and C++ Programming
Introduction to Computers and C++ Programming
Introduction to Computers and C++ Programming
Completing the Problem-Solving Process
Programming Introduction to C++.
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Chapter 1: Introduction to Computers and Programming
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

1 Problem Solving with C++ The Object of Programming Walter Savitch Chapter 1 Introduction to Computers and C++ Programming Slides by David B. Teague, Western Carolina University. A Constituent Institution of The University of North Carolina

2 Introduction to Computers and C++ Programming l Computer Systems l Programming and Problem-Solving l Introduction to C++ l Testing and Debugging

3 1.1 Computer Systems l Hardware -- Parts of a computer you can touch »PC »Workstation »Mainframe »Network »input/output »memory –primary, secondary –fixed, removable »CPU

4 1.1 Computer Systems l Software -- Parts of a computer you cannot touch »Operating Systems –Macintosh –Windows –Linux »High-Level Languages –Ada, C++, Java, BASIC, Lisp, Scheme »Compilers –Source program, object program, Linking »Editor: Integrated Development Environments (IDE) –IDEs combine editor, compiler and the execution environment (usually including a debugger)

5 1.2 Programming and Problem Solving l Algorithms »Idea is more general than ‘program’ »Hard part of solving a problem is finding the algorithm l Program Design Process »Problem Solving Implementation phase phase P roblem definition –Algorithm Design Translation to C++ –Desk Testing Testing – – Working Program

6 Software Life Cycle l Analysis and specification of task (problem definition). l Design of the software (algorithm design) l Implementation (coding). l Testing l Maintenance and evolution of the system l Obsolescence

7 1.3 Introduction to C++ l Origins of the C++ Language »Bjarne Stroustrup designed C++ for modeling. »C++ is an OOP extension of the C language. »C was developed as a systems programming language from the B language in the Unix environment. It grew into a general purpose programming language as its libraries were developed.

8 Display 1.8 A Sample C++Program #include using namespace std; int main( ) { int number_of_pods, peas_per_pod, total_peas; cout << "Press return after entering a number.\n"; cout << "Enter the number of pods:\n"; cin >> number_of_pods; cout << "Enter the number of peas in a pod:\n"; cin >> peas_per_pod; total_peas = number_of_pods * peas_per_pod; cout << "If you have "; cout << number_of_pods; cout << " pea pods\n"; cout << "and "; cout << peas_per_pod; cout << " peas in each pod, then\n"; cout << "you have "; cout << total_peas; cout << " peas in all the pods.\n"; return 0; }

9 Some details of a C++ Program #include using namespace std; int main() { l These lines are a complicated way to say “the program starts here” return 0; } l The last two lines say “the program ends here.”

10 Some Details of a C++ Program int number_of_pods, peas_per_pod, total_peas; l This is a variable declaration. (We explain variable later.) l Variable must be declared before they can be used. l Variables are used to store values. l The int in the declaration says the variables can hold integer values. l Other lines are (executable) statements that tell the compute to do some task.

11 Some Details of a C++ Program l cout is the output stream, read See-Out.. It is attached to the monitor screen. << is the insertion operator l cin is the input stream, read see-in, and is attached to the keyboard. >> is the extraction operator. l “Press return after entering a number.\n” is called a cstring literal. It is a message for the user. l cout << “Press return …\n” sends the message to cout l cin >> number_of_pods;

12 Some Details of a C++ Program cout << “Enter the number of peas in a pod.\n”; cin >> peas_per_pod; l The first of these lines sends a request to the user. l The second extracts an integer value (the type of peas_per_pod) into peas_per_pod.

13 Some Details of a C++ Program total_peas = number_of_pods * peas_per_pod; l The asterisk, *, is used for multiplication. l This line multiplies the already entered values of number_of_pods and peas_per_pod to give a value which is stored (assigned to) total_peas.

14 Display 1.9 Layout of a Simple C++ Program #include An include directive using namespace std; More later, for now “do it” int main()Declares main function {Start of main’s block variable _declarations Statement1; Statement2;... Statement_last; return 0;Says “end program here” }End of main’s block l (a

15 Compiling and Running a C++ Program l You write a C++ program using a text editor exactly as you would write a letter home. l Compiling depends on the environment. l You may be using an Integrated Development Environment or IDE. Each IDE has its own way to do things. l Read you manuals and consult a local expert. l You may be using a command line compiler. In that event, you may some thing like write: cc myProgram.cpp l Your compiler may require.cxx..cc or perhaps.C l Linking is usually automatic. Again, read your manuals and ask a local expert.

Testing and Debugging l An error in a program, whether due to design errors or coding errors, are known as bugs. Rear Admiral Grace Hopper is credited with this term. l Program Errors are classified as »design errors -- if you solved the wrong problem, you have design errors. »syntax errors -- violation of language’s grammar rules, usually caught by the compiler, and reported by compiler error messages. »run-time errors -- a program that compiles may die while running with a run-time error message that may or may not be useful. »logic error -- a program that compiles and runs to normal completion may not do what you want. May be a design error.

17 Kinds of Errors l Design errors occur when specifications are do not match the problem being solved. l The compiler detects errors in syntax l Run-time errors result from incorrect assumptions, incomplete understanding of the programming language, or unanticipated user errors.

18 Summary l Hardware physical computing machines. l Software programs that run on hardware. l Five computer components: input and output devices, CPU, main memory, secondary memory. l There are two kinds of memory: main and secondary. Main memory is used when program is running. Secondary memory is usually nonvolatile. l Main memory is divided into bytes, usually individually addressable. l Byte: 8 bits. A bit is 0 or 1.

19 Summary(continued) l A compiler translates high level language to machine language. l Algorithm is a sequence of precise instructions that lead to a solution to a problem. l A solution to a problem begins with algorithm design. l Errors are of several kinds: syntax, run-time, and logic errors. l A variable is used to name a number. l cout << is an output statement l cin >> is an input statement