1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex.

Slides:



Advertisements
Similar presentations
Overview of Programming and Problem Solving ROBERT REAVES.
Advertisements

Chapter 1: An Overview of Computers and Programming Languages
Overview. What is Computer Programming? It is the process of planning a sequence of steps (called instructions) for a computer to follow. 2 STEP 1 STEP.
Computer Science-I (CSIT121) Dr. Junaid Ahmed Zubairi SUNY at Fredonia Room 210, Fenton ,
This set of slides is provided by the author of the textbook1 Introductory Topics (Continued) l Computer Components l Basic Control Structures l Problem.
1 Chapter 1 Introduction to Object-Oriented Programming.
This set of slides is provided by the author of the textbook1 Introductory Topics l Computer Programming l Programming Life-Cycle Phases l Creating an.
Chapter 1 Introduction to Object- Oriented Programming and Problem Solving.
Three types of computer languages
Chapter 16 Programming and Languages: Telling the Computer What to Do.
Computer Science 1620 Programming & Problem Solving.
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:
1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems/Headington Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages Updated by: Dr\Ali-Alnajjar.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CS 115 Chapter 1 Overview of Programming and Problem Solving.
1 Chapter 1 Overview of Programming and Problem Solving Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex Campus.
1 Author: Nell Dale Chip Weems Mark Headington Published By Higher Education Press Jones and Bartlett Publishers.
1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex.
Hello World 2 What does all that mean?.
CHAPTER 1 Overview of Programming and Problem Solving.
Instructor: Tina Tian. About me Office: RLC 203A Office Hours: Wednesday 1:30 - 4:30 PM or .
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
1 Overview of Programming and Problem Solving Chapter 1.
Overview of Programming and Problem Solving. Objectives In this chapter you will: Learn about different types of computers Explore the hardware and software.
Introduction to C++ Programming Language
Chapter 1: An Overview of Computers and Programming Languages
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.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems/Headington.
Chapter 1 Overview of Programming and Problem Solving Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex Campus.
Chapter 1 Overview of Programming and Problem Solving 1.
1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex.
CC112 Structured Programming Lecture 1 1 Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Computer.
1 Chapter 1 Overview of Programming and Problem Solving Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex Campus.
CSE:141 Introduction to Programming Faculty of Computer Science, IBA BS-I (Spring 2010) Lecture 2.
Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving.
Chapter 1 Overview of Programming and Problem Solving CS185/09 - Introduction to Programming Caldwell College.
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.
Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.
1 Overview of Programming Principles of Computers.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Software Engineering Algorithms, Compilers, & Lifecycle.
C++ Programming Chapter 1 Programming & Programs.
1 Chapter 1 Overview of Programming and Problem Solving Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex Campus.
Cosc175 - lec11 Overview History Hardware Software Software Development Life Cycle Programming Languages Structured Programming Defining the Problem.
Structured Programming The Basics
Introduction to Computers and C++ Programming
Chapter 1 Overview of Programming and Problem Solving
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Chapter 1 Overview of Programming and Problem Solving
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Programming We have seen various examples of programming languages
What is Computer Programming?
Overview History Hardware Software Software Development Life Cycle
Presentation transcript:

1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex Campus

2 Chapter 1 Topics l Computer Programming l Programming Life-Cycle Phases l Creating an Algorithm l Problem-Solving Techniques l Machine Language vs. High Level Languages l Compilation and Execution Processes l C++ History l Computing Profession Ethics

3 What is Computer Programming? It is the process of planning a sequence of steps(called instructions) for a computer to follow. STEP 1 STEP 2 STEP 3...

4 Programming Life Cycle Phases Problem-Solving Implementation Maintenance

5 Problem-Solving Phase Analyze the problem and specify what the solution must do Develop a general solution(algorithm) to solve the problem Verify that your solution really solves the problem

6 Sample Problem Suppose a programmer needs to determine an employee’s weekly wages. How would the calculations be done by hand?

7 One Employee’s Wages In one week an employee works 52 hours at the hourly pay rate of $ Assume a 40.0 hour normal work week and an overtime pay rate factor of 1.5. What are the employee’s wages? 40 x $ = $ x 1.5 x $ 24.75= $ ___________ $

8 If hours are more than 40.0 wages = (40.0 * payRate) + (hours ) * 1.5 *payRate otherwise wages = hours * payRate Weekly Wages, in General RECALL EXAMPLE (40 x $ 24.75) +( 12 x 1.5 x $ 24.75) = $

9 An Algorithm An algorithm is a step-by-step procedure for solving a problem with a finite amount of data in a finite amount of time

10 Algorithm to Determine an Employee’s Weekly Wages 1. Get the employee’s hourly payRate 2. Get the hours worked this week 3. Calculate this week’s regular wages 4. Calculate this week’s overtime wages(if any) 5. Add the regular wages to overtime wages(if any) to determine total wages for the week

11 What is a Programming Language? A programming language is a language with strict grammar rules, symbols, and special words used to construct a computer program

12 Implementation Phase: Program Translating your algorithm into a programming language is called coding With C++, you use Documentation -- your written comments Compiler -- translates your program into machine language Main Program -- may call subalgorithms

13 Implementation Phase: Test Testing your program means running(executing) your program on the computer, to see if it produces correct results If it does not, then you must find out what is wrong with your program or algorithm and fix it--this is called debugging

14 Maintenance Phase Use and modify the program to meet changing requirements or correct errors that show up in using it Maintenance begins when your program is put into use and accounts for the majority of effort on most programs

15 Programming Life Cycle 1 Problem-Solving Phase Analysis and Specification General Solution(Algorithm) Verify 2 Implementation Phase Concrete Solution(Program) Test 3 Maintenance Phase Use Maintain

16 A Tempting Shortcut? GOAL THINKING CODE REVISE DEBUG TEST CODE Shortcut?

17 Problem Solving Techniques l Ask questions -- about the data, the process, the output, error conditions l Look for familiar things -- certain situations arise again and again l Solve by analogy -- it may give you a place to start l Use means-ends analysis -- determine the I/O and then work out the details

18 More Problem Solving Techniques l Divide and conquer -- break up large problems into manageable units l Building-block approach -- can you solve small pieces of the problem? l Merge solutions -- instead of joining them end to end to avoid duplicate steps l Overcome mental block -- by rewriting the problem in your own words

19 Machine Language l Is not portable l Runs only on a specific type of computer l Is made up of binary-coded instructions(strings of 0s and 1s) Is the language that can be directly used by the computer

20 High Level Languages l Are portable l User writes program in language similar to natural language Examples -- FORTRAN, COBOL, Pascal, Ada, Modula-2, C++, Java l Most are standardized by ISO/ANSI to provide an official description of the language

21 Three C++ Program Stages other code from libraries, etc. other code from libraries, etc. written in machine language written in machine language written in machine language written in machine language written in C++ written in C++ via compilervia linker SOURCEOBJECT EXECUTABLE myprog.cppmyprog.objmyprog.exe

22 Basic Control Structures l A sequence is a series of statements that execute one after another l A selection(branch) statement is used to determine which of two different statements to execute depending on certain conditions l A looping(repetition) statement is used to repeat statements while certain conditions are met l A subprogram is a smaller part of another program; a collection of subprograms solves the original problem

23 SEQUENCE Statement...

24 SELECTION(branch) IF Condition THEN Statement1 ELSE Statement2 Statement1 Statement Statement2 Condition... True False

25 LOOP(repetition) Statement Condition... False True WHILE Condition DO Statement1

26 SUBPROGRAM(function) SUBPROGRAM1... SUBPROGRAM1 a meaningful collection of SEQUENCE, SELECTION, LOOP, SUBPROGRAM

27 Some C++ History l 1972 : Dennis Ritchie at Bell Labs designs C and 90% of UNIX is then written in C l Late 70’s : OOP becomes popular l Bjarne Stroustrup at Bell Labs adds features to C to form “C with Classes” l 1983 : Name C++ first used l 1998 : ISO/ANSI standardization of C++

28 Is a year a leap year? Problem You need to write a set of instructions that can be used to determine whether a year is a leap year. The instructions must be very clear because they are to be used by a class of fourth graders, who have just learned about multiplication and division. They plan to use the instructions as part of an assignment to determine whether any of their relatives were born in a leap year.

29 Leap Year Algorithm Prompt the user to enter a four-digit year Read the year If IsLeapYear Write “Year is a leap year” Otherwise Write “Year is not a leap year”

30 IsLeapYear Algorithm Divide the year by 4 If the remainder isn't zero, Return false(The year is not a leap year) Otherwise divide the year by 100 and If the remainder isn't 0, Return true(The year is a leap year) Otherwise, divide the year by 400 and If the remainder isn't 0 Return false(The year is not a leap year) Otherwise, Return true(The year is a leap year)

31 //****************************************************** // LeapYear program // This program inputs a year and prints whether the year // is a leap year or not //****************************************************** #include // Access output stream using namespace std; // Access cout, endl, cin bool IsLeapYear(int);// Prototype for subalgorithm int main() { … } C++ Program

32 Body of Main { int year;// Year to be tested cout << "Enter a year AD, for example, 1997." << endl; // Prompt for input cin >> year; // Read year if(IsLeapYear(year)) // Test for leap year cout << year << " is a leap year." << endl; else cout << year << " is not a leap year." << endl; return 0; // Indicates successful // completion }

33 IsLeapYear bool IsLeapYear(int year) // IsLeapYear returns true if year is a leap year and // false otherwise { if(year % 4 != 0) // Is year not divisible by 4? return false; // If so, can't be a leap year else if(year % 100 != 0) // Is year not a multiple of 100? return true; // If so, is a leap year else if(year % 400 != 0) // Is year not a multiple of 400? return false; // If so, then is not a leap year else return true; // Is a leap year }

34 Computing Profession Ethics l Copy software only with permission from the copyright holder l Give credit to another programmer by name whenever using his/her code l Use computer resources only with permission l Guard the privacy of confidential data l Use software engineering principles to develop software free from errors