Computer Programming 1 Problem Solving and Software Engineering.

Slides:



Advertisements
Similar presentations
Programming Types of Testing.
Advertisements

Types and Variables. Computer Programming 2 C++ in one page!
COSC 120 Computer Programming
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
Chapter 3 Assignment and Interactive Input. 2 Objectives You should be able to describe: Assignment Operators Mathematical Library Functions Interactive.
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.
Three types of computer languages
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
Problem Solving and Software Engineering Chapter 1.
Computer Science 1620 Programming & Problem Solving.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
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.
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
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.
1 4.3 Example: Volume of a Sphere Given the radius r, what is the weight of a ball (sphere) of wound twine?Given the radius r, what is the weight of a.
1 Chapter-01 Introduction to Computers and C++ Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and 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.
High-Level Programming Languages: C++
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
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,
Overview of Programming and Problem Solving Textbook Chapter 1 1.
Beginning C++ Through Game Programming, Second Edition
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
1 Simple Functions Writing Reuseable Formulas. In Math Suppose f (x) = 2 x 2 +5Suppose f (x) = 2 x 2 +5 f(5)=?f(5)=? f(5) = 2* =55f(5) = 2*
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.
A FIRST BOOK OF C++ CHAPTER 3 ASSIGNMENT AND INTERACTIVE INPUT.
1 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
1 Program Planning and Design Important stages before actual program is written.
Software Engineering Object-Centered Design. Problem Solving Does anyone scuba dive? Let’s solve this scuba-diving problem: Write a program that, given.
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Simple Functions Writing Reuseable Formulas. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian.
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.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Software Engineering Algorithms, Compilers, & Lifecycle.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Introduction to Computers and C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Engineering Problem Solving With C An Object Based Approach
Chapter 1: Introduction to computers and C++ Programming
Completing the Problem-Solving Process
Basic Elements of C++.
Writing Reuseable Formulas
C++ Programming: From Problem Analysis to Program Design
solve the following problem...
Basic Elements of C++ Chapter 2.
Chapter 2 Elementary Programming
Chapter 1 c++ structure C++ Input / Output
Object-Centered Design
Presentation transcript:

Computer Programming 1 Problem Solving and Software Engineering

Computer Programming 2 Objectives Review Structure of a program Basic phases of software life cycle – Object-centered design Practice sessions

Computer Programming 3 Review Computer Software Hardware Drivers Applications OS CPU ALU Registers RAM Second memory Bus User programs

Computer Programming 4 Review A program – A sequence of instructions that specifies for the computer how to solve a problem. – Remember that computers are dumb! – Computers only understands machine language: A sequence of ones and zeros Cause the computer to perform a particular action, such as add, subtract, multiply,... Write machine languages is very hard to do, to understand, and correct. Thus the invention of high-level languages such as C++.

Computer Programming 5 Compiler Versus Interpreter Program in high-level language Compiler Machine language  A Compiler translates a file written in a high-level language into a machine language file that can be executed on the computer.  An interpreter executes each high-level statement directly. On fly, the interpreter translates the statement to the corresponding machine language instructions and executes/runs them.

Computer Programming 6 Contrast Assembler and HLL Compiler Assembler translates one mnemonic into one ML statement Compiler translates one HL statement into several ML statements z = x + y; Compiler

Computer Programming 7 First program: Hello World! #include int main() { std::cout << “Hello World!”<<std::endl; return 0; } What is the difference between this program and the one given in the previous lecture?

Computer Programming 8 Structure of program Preprocessor directives – #include – #if – … Namespaces to use New namespaces – variables – Functions – Classes The main function

Computer Programming 9 Structure of a program #include #include “xxx.h” … using namespace xxx; …. namespace ns1 { xxx function1(xxxx) { … } … public class } … int main() { ….. return 0; }

Computer Programming 10 Variables, Functions, and Classes Variables – In C++ all variables must be declared before they are used. Furthermore, variables must be used in a manner consistent with their associated type. – E.g. double radius; Functions – All C++ functions must be declared before being used, their return type defaults to int. However, it is considered good style to fully declare all functions. Use void keyword to specify that a function does not return a value. – E.g. int power(double x, int y) { … return …;} Classes – Combines data objects and functions to provide an Abstract Data Type (ADT). – E.g. class Sphere { …}

Computer Programming 11 From problems to programs Given a problem, how to write a program that solves it? A simplified version of the main steps: Designer Problem Computer program Results programmer design

Computer Programming 12 Problem Solving through Software Engineering Phases (V model) Requirements & Specifications Design Implementation Testing Maintenance

Computer Programming 13 Problem Solving through Software Engineering Phases Requirements & specifications – Formally specify and document the problem we are solving Design – Analysis, specify algorithms to solve problem Implementation – Write solution in syntax of language Testing – Execution and Debugging – Get rid of “bugs” Maintenance – Update, modify to meet changing needs

Computer Programming 14 Problem World’s largest ball of twine found in Cawker City, Ks.Cawker City, Ks. – How much does the ball weigh? – What is the length of the twine when unrolled?

Computer Programming 15 Object-Centered Design Steps State how you want the program to behave Identify and categorize the objects involved in the problem Identify operations needed to solve the problem Develop algorithms by arranging objects and operations in an order which solves the problem Implement your algorithm using C++

Computer Programming 16 Behavior To find the weight of a ball of string: Enter radius of sphere : 9 Enter the density of twine: 1 Now computing... Weight of ball of string =

Computer Programming 17 Objects Description Software Objects TypeKindName prompt for radius of sphere string constantnone screen ostream variable cout radius of sphere double variable radius Twine density double variable density keyboard istream variable cin weight of ball double variable weight

Computer Programming 18 Operations Output prompt for radius of sphere to cout Input real value from cin Store it in radius Output prompt for density of twine to cout Input real value from cin Store it in density Compute weight Output weight to cout

Computer Programming 19 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

Computer Programming 20 Algorithm (Recipe!) 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

Computer Programming 21 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.

Computer Programming 22 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() { }

Computer Programming 23 Coding int main() { const double PI = ; cout << "Enter the sphere's radius (feet): "; double radius; cin >> radius; cout << "Enter its density (pounds/cubic feet): "; double density; cin >> density; double weight = density * 4.0 * PI * pow(radius, 3) / 3.0; cout << "\nThe weight of the sphere is approximately " << weight << " pounds.\n"; }

Computer Programming 24 Testing Enter radius of sphere (feet) : 6.5 Enter its density (pounds/cubic feet) : 14.6 The weight of the sphere is approximately pounds

Computer Programming 25 Testing, Execution, Debugging Common error sources Syntax errors – Violations of grammar rules of the high level language Semantics/run-time errors – Errors that occur during execution Logic errors – Errors in the design of the algorithm

Computer Programming 26 Syntax Errors Example: double radius – Missing semi-colon Compiler finds most of this kind of errors Different compilers give varying degrees of helpful diagnostics Do many but learn from them!

Computer Programming 27 Run-time Errors Not detected until program runs Examples – Division by zero – Taking square root of negative numbers Program must be modified to prevent such run-time errors from happening

Computer Programming 28 Logic Errors Program compiles, runs without crashing, but gives incorrect results These are the 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

Computer Programming 29 Maintenance Student programs run only a few times Real-world programs are used for many years – Due to significant investment of resources – They may need to be upgraded or/and changed New features may be required during life of program usage Upgrading is called “maintenance”

Computer Programming 30 Problem Session A maintenance question?

Computer Programming 31 Problem Upgrade the program we previously wrote to solve the following problem: What is the length of the twine when unrolled? Follow the OCD steps: State how you want the program to behave Identify and categorize the objects involved in your problem Identify operations needed to solve the problem Develop algorithms by arranging objects and operations in an order which solves the problem

Computer Programming 32 Describe Behavior of Program In addition to the behavior already described, Program should display prompt for the weight of 1 foot of the twine User enters values from keyboard Program computes, displays on screen the length (in feet) of the twine when unrolled

Computer Programming 33 Behavior Envisioned … Enter the weight of 1 foot of twine: xxx... The length of the twine when unrolled is: xxxx

Computer Programming 34 Objects Use description to fill in chart for objects. Description Software Objects TypeKindName prompt for mass density per foot string constantnone screen ostream variable cout Density per foot double variable lengthDensity keyboard istream variable cin Length of the twine when unrolled double variable length

Computer Programming 35 Operations Description Name Predefined?LibraryOperator Display string using cout Yes iostream<< Read the density per foot using cin Yes iostream>> Compute the length using weight of ball divided by the density per foot Yes / Output the result using cout YesIostream << Use description to fill in chart for operations

Computer Programming 36 Algorithm and Coding Work together to determine the steps necessary to have the objects manipulated by the operations Write the program – Compile and link to fix syntax errors – Test the program to fix run-time and logical errors.