Problem Solving and Software Engineering Chapter 1.

Slides:



Advertisements
Similar presentations
Types and Variables. Computer Programming 2 C++ in one page!
Advertisements

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.
Computer Programming 1 Problem Solving and Software Engineering.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Computer Science 1620 Programming & Problem Solving.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
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.
Basic Elements of C++ Chapter 2.
Software Engineering 1 (Chap. 1) Object-Centered Design.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
COMPUTER SCIENCE I C++ INTRODUCTION
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
1 Programming and Problem Solving — Software Engineering (Read Chap. 2)
Programming and Problem Solving — Software Engineering (Read Chap. 2) 1.
Problem Solving and Software Engineering Chapter 1.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
General Programming Introduction to Computing Science and Programming I.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Chapter 1 Introduction to Computers and C++ Programming Goals: To introduce the fundamental hardware and software components of a computer system To introduce.
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,
Week 1 Algorithmization and Programming Languages.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
1 Chapter-01 Introduction to Software Engineering.
Selection Chapter 6. C++ An Introduction to Computing, 3rd ed. 2 Objectives Expand on introduction to structures Examine if statement in more detail Study.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
1 Program Planning and Design Important stages before actual program is written.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Software Engineering Object-Centered Design. Problem Solving Does anyone scuba dive? Let’s solve this scuba-diving problem: Write a program that, given.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Lesson - 2. Introduction When we make a program we must follow some steps, called Programming Development Life Cycle (PDLC). Programming steps are five:
Simple Functions Writing Reuseable Formulas. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
1 Chapter-01 Introduction to Software Engineering.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
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.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Software Engineering Algorithms, Compilers, & Lifecycle.
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
Introduction to Computers and C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Completing the Problem-Solving Process
Basic Elements of C++.
Writing Reuseable Formulas
Chapter 2 part #3 C++ Input / Output
Basic Elements of C++ Chapter 2.
Chapter 2 – Getting Started
Chapter 3: Input/Output
Chapter 2 part #3 C++ Input / Output
Chapter 1 c++ structure C++ Input / Output
Object-Centered Design
Presentation transcript:

Problem Solving and Software Engineering Chapter 1

C++, An Introduction to Computing, 3rd Ed. 2 Objectives Indicate uses of computers First look at a C++ program Basic phases of software life cycle Object-centered design Issues, ethical principles First look: classes and object-oriented design

C++, An Introduction to Computing, 3rd Ed. 3 Uses of Computers Industry Robots, CAD, project management and control Government Defense, space, compile data, weather Medicine Medical records, life support systems, CAT scan, MR scan Entertainment Animation, colorization, special effects Science Simulations, molecule analysis, food quality testing Information Technology Digital libraries, online art

C++, An Introduction to Computing, 3rd Ed. 4 What is Programming? Computer Program A sequence of statements that instruct a computer in how to solve a problem. Programming The act of designing, writing and maintaining a program Programmers People who write programs

C++, An Introduction to Computing, 3rd Ed. 5 The World of C++ Sample program /* greeting.cpp greets its user. * * Input: The name of the user * Output: A personalized greeting *********************************************************/ #include // cin, cout, > #include // string using namespace std; int main() { cout << "Please enter your first name: "; string firstName; cin >> firstName; cout << "\nWelcome to the world of C++, " << firstName << "!\n"; } Comment Compiler directives Specifies standard related names Main portion of program. Contains C++ statements.

C++, An Introduction to Computing, 3rd Ed. 6 The World of C++ C++ statements int main() { cout << "Please enter your first name: "; string firstName; cin >> firstName; cout << "\nWelcome to the world of C++, " << firstName << "!\n"; } Output statement to prompt user Variable declaration Input from keyboard stored in variable Output character string and value stored in variable

C++, An Introduction to Computing, 3rd Ed. 7 Problem Solving through Software Engineering Phases Design Analysis, specify algorithms to solve problem Coding Write solution in syntax of language Testing, Execution, Debugging Get rid of “bugs” Maintenance Update, modify to meet changing needs

C++, An Introduction to Computing, 3rd Ed. 8 Problem World’s largest ball of twine found in Cawker City, Ks. Cawker City, Ks. How much does the ball weigh? How many miles would the twine reach if unrolled?

C++, An Introduction to Computing, 3rd Ed. 9 Object-Centered Design Steps State how you want the program to behave Identify real-world objects, categorize Identify operations needed to solve the problem Develop algorithm – arrange objects, operations in an order which solve the problem

C++, An Introduction to Computing, 3rd Ed. 10 Behavior To find the weight of a ball of string: Enter radius of sphere : 9 Now computing... Weight of ball of string =

C++, An Introduction to Computing, 3rd Ed. 11 Objects Description Software Objects TypeKindName prompt for radius of sphere string constantnone screen ostream variable cout radius of sphere double variable radius keyboard istream variable cin weight of ball double variable weight

C++, An Introduction to Computing, 3rd Ed. 12 Operations Output prompt for radius of sphere to cout Input real value from cin Store it in radius Compute weight Output weight to cout

C++, An Introduction to Computing, 3rd Ed. 13 More Objects Computation of weight requires additional objects Description Software Objects TypeKindName density of sphere double variable density 4.0 double constant π double constant PI 3 integer constant 3.0 double constant

C++, An Introduction to Computing, 3rd Ed. 14 Algorithm 1. Initialize constant PI 2. Output prompt for radius to cout 3. Input real value from cin, store in radius 4. Output prompt for density to cout 5. Input real value from cin, store in density 6. Compute 7. Output weight to cout

C++, An Introduction to Computing, 3rd Ed. 15 Coding First, create a program stub that contains opening documentation Compiler directives that add items in libraries needed for some of the Objects and operations An empty main function Convert each step of the algorithm into code. If it uses a software object that hasn’t already been declared, add a declaration statement that specifies the object’s type and name.

C++, An Introduction to Computing, 3rd Ed. 16 Coding /* sphereWeight.cpp computes the weight of a sphere. * * Input: The radius (feet) and * the density (pounds/cubic foot) of a sphere * Output: The weight of the sphere (pounds) ************************************************/ #include // cin, cout, > #include // pow() using namespace std; int main() { }

C++, An Introduction to Computing, 3rd Ed. 17 Coding int main() { const double PI = ; double radius; // double radius, double density; // density, double weight; // weight; //INPUT DATA cout << "Enter the sphere's radius (feet): "; cin >> radius; cout << "Enter its density (pounds/cubic feet): "; cin >> density; // CALCULATE WEIGHT weight = density * 4.0 * PI * pow(radius, 3) / 3.0; // OUPUT WEIGHT cout << "\nThe weight of the sphere is approximately " << weight << " pounds.\n"; }

C++, An Introduction to Computing, 3rd Ed. 18 Testing Enter radius of sphere (feet) : 6.5 Enter its density (pounds/cubic feet) : 14.6 The weight of the sphere is approximately pounds

C++, An Introduction to Computing, 3rd Ed. 19 Testing, Execution, Debugging Common error sources Violations of grammar rules of the high level language Errors that occur during execution Errors in the design of the algorithm

C++, An Introduction to Computing, 3rd Ed. 20 Syntax Errors Example: double radius Missing semi-colon Compiler finds most of these kinds of errors Different compilers give varying degrees of helpful diagnostics

C++, An Introduction to Computing, 3rd Ed. 21 Run Time Errors Not detected until program runs Examples Division by zero causes program to crash Taking square root of negative causes program crash Program must be modified to keep such events from happening

C++, An Introduction to Computing, 3rd Ed. 22 Logic Errors Program compiles, runs without crashing, but gives incorrect results These are hardest errors to find Find by using sample data and hand calculating the correct results, comparing Note: Testing grows increasingly more difficult with larger programs Some will run for years without logic error appearing

C++, An Introduction to Computing, 3rd Ed. 23 Maintenance Student programs run only a few times Real-world programs used for many years Due to significant investment of resources New features may be required during life of program usage Upgrading called “maintenance”

Problem Session Working in groups of two, Solve the following problem...

C++, An Introduction to Computing, 3rd Ed. 25 Problem Sam Splicer installs coax cable for Metro Cable Co. Basic service charge $25.00 Additional $2.00 for each foot of cable Company Pres. wants to compute revenue generated by Sam for given month Example: 263 yards of cable at 27 locations generates $ in revenue

C++, An Introduction to Computing, 3rd Ed. 26 Describe Behavior of Program Program should display prompt for number of installations performed and total number of yards of cable installed User enters values from keyboard Program computes, displays on screen total amount of revenue resulting from these installations

C++, An Introduction to Computing, 3rd Ed. 27 Behavior Envisioned To determine revenue generated, Enter number of installations : 27 Enter number of yards of cable installed : 263 Total revenue generated is $

C++, An Introduction to Computing, 3rd Ed. 28 Objects Use description to fill in chart for objects. Description Software Objects TypeKindName

C++, An Introduction to Computing, 3rd Ed. 29 Operations Description Name Predefined?LibraryOperator Use description to fill in chart for operations.

C++, An Introduction to Computing, 3rd Ed. 30 Algorithm and Coding Work together to determine the steps necessary to have the objects manipulated by the operations Write the source code Compile and Link Test the program

C++, An Introduction to Computing, 3rd Ed. 31 OBJECTive Thinking Spheres as Objects Recall behavioral description concerning the sphere of string: Then note the list of objects:objects No mention made of sphere objects Only used sphere attributes We ignored the central noun … sphere Display prompt for radius. User enters value. Program computes weight, displays it on screen

C++, An Introduction to Computing, 3rd Ed. 32 Creating a New Type : Sphere When no type for an object exists, we create a type Called a class A class provides Space for storing the attributes of an object Operations for manipulation of the object

C++, An Introduction to Computing, 3rd Ed. 33 Operations for Sphere Class Initialize attributes to default values Read in various values for attributes Print various attributes Retrieve various attribute values for use by other routines

C++, An Introduction to Computing, 3rd Ed. 34 Code Example Using Sphere Object #include // cin, cout, > #include "Sphere.h" // Sphere class using namespace std; int main() { cout << "Enter the radius (feet) " << " and density (lbs/sq-ft) of the sphere: "; Sphere aSphere; aSphere.readRadiusAndDensity(cin); cout << "\nThe sphere weighs " << aSphere.getWeight() << " pounds.\n"; } Declaration of Sphere object Sphere object sends message to operation File with Sphere declaration

C++, An Introduction to Computing, 3rd Ed. 35 Calculating Sphere Density using Sphere Class #include // cin, cout, > #include "Sphere.h" // Sphere class using namespace std; int main() { cout << "Enter the radius (feet) " << " and weight (lbs) of the sphere: "; Sphere aSphere; aSphere.readRadiusAndWeight(cin); cout << "\nThe sphere's density is " << aSphere.getDensity() << " lbs/sq-ft\n"; }

C++, An Introduction to Computing, 3rd Ed. 36 Ethics and Issues “To be good is noble, but to show others how to be good is nobler, and no trouble.” Mark Twain Ethics are becoming more of an issue in the area of computers. Professional organizations are adopting, instituting codes of ethics Colleges and universities have policies governing responsible uses of computers

C++, An Introduction to Computing, 3rd Ed. 37 Ethics and Issues Consider the essay by Professor Anne Marchant (see web site of text) Ethics and Society Computer Crime and Security Health Concerns and the Environment Information Ownership “Netiquette” and Hoaxes Internet Content and Free Speech Privacy Quality Control and Risk Reduction The Future