Overview of Programming and Problem Solving Textbook Chapter 1 1.

Slides:



Advertisements
Similar presentations
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Advertisements

Lecture 1: Overview of Computers & Programming
Overview of Programming and Problem Solving ROBERT REAVES.
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
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.
COSC 120 Computer Programming
1 Chapter 1 Introduction to Object-Oriented Programming.
1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex.
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.
1 Lecture 19 Chapter 4 Program Input and the Software Design Process Dale/Weems/Headington.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
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.
1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems/Headington Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus.
CS1044 – Intro. To Programming in C++ Dr. Craig A. Struble.
CS102 Introduction to Computer Programming
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.
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.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
CSE 1340 Introduction to Computing Concepts Class 2.
1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex.
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.
CHAPTER 1 Overview of Programming and Problem Solving.
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.
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.
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.
No I/O is built into C++ l instead, a library provides input stream and output stream KeyboardScreen executing program istreamostream 1.
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.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
1 Overview of Programming Principles of Computers.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
©2013 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. Introduction to Computers and Computing.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Software Engineering Algorithms, Compilers, & Lifecycle.
Introduction to Programming By: Prof. Muhammad Abu Baker Siddique 2 nd Lecture 1.
1 Chapter 1 Overview of Programming and Problem Solving Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex Campus.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 1: Introduction to Computers and Programming.
Introduction to Computers and C++ Programming
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1 Overview of Programming and Problem Solving
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Chapter 1. Introduction to Computers and Programming
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
SOFTWARE DESIGN & DEVELOPMENT
Chapter 1 Overview of Programming and Problem Solving
No I/O is built into C++ instead, a library provides input stream and output stream Keyboard Screen executing program istream ostream 1.
What is Computer Programming?
Presentation transcript:

Overview of Programming and Problem Solving Textbook Chapter 1 1

Programming Life Cycle Phases 1 Requirements 2Design 3Coding 4Testing/debugging 5 Maintenance 2

Requirements For this class, given to you as a program assignment In the real world, a complex task of extracting and documenting user requirements 3

Design 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 4

An Algorithm is... a step-by-step procedure for solving a problem in a finite amount of time. 5

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

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? 7 40 x $ = $ x 1.5 x $ = $ ___________ $

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

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 9

What is a Programming Language? It is a language with strict grammar rules, symbols, and special words used to construct a computer program. 10

Coding a Program translating your algorithm into a programming language is called CODING 11

Testing/Debugging 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 12

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 13

Software/Hardware A computer program (software) must run on a computer (hardware) A computer can only run “machine language” 14

Machine Language is not portable runs only on specific type of computer is made up of binary-coded instructions (strings of 0s and 1s) is the only language that can be directly used by the computer 15

High Level Languages are portable user writes program in language similar to natural language examples -- FORTRAN, COBOL, C++, Java, Perl, Visual Basic 16

Three C++ Program Stages 17 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

Basic Control Structures a sequence is a series of statements that execute one after another selection (branch) is used to execute different statements depending on certain conditions Looping (repetition) is used to repeat statements while certain conditions are met. a subprogram is used to break the program into smaller units 18

SEQUENCE 19 Statement...

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

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

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

Computer Components Central Processing Unit ( CPU ) 23 Arithmetic Logic Unit Control Unit Auxiliary Storage Device Memory Unit ( RAM & Registers ) Input Device Output Device Peripherals

Memory Unit is an ordered sequence of storage cells, each capable of holding a piece of information each cell has its own unique address the information held can be input data, computed values, or your program instructions. 24

Peripherals are input, output, or auxiliary storage devices attached to a computer – Input Devices include keyboard and mouse. – Output Devices include printers, video display, LCD screens. – Auxiliary Storage Devices include disk drives, scanners, CD-ROM and DVD-ROM drives, modems, sound cards, speakers, and digital cameras. 25

Company Payroll Case Study A small company needs an interactive program to figure its weekly payroll. The payroll clerk will input data for each employee, and each employee’s wages and data should be saved in a secondary file. Display the total wages for the week on the screen. 26

One Employee’s Wages In one week employee ID # 4587 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? x $ = $ x 1.5 x $ = $ ___________ $

Week’s Wages, in General If hours are more than 40.0, then wages = (40.0 * payRate) + (hours ) * 1.5 *payRate else wages = hours * payRate 28 RECALL EXAMPLE ( 40 x $ ) + ( 12 x 1.5 x $ ) = $

Algorithm for Company Payroll Program initialize total company payroll to 0.0 repeat this process for each employee: 1. Get the employee’s ID empNum 2. Get the employee’s hourly payRate 3. Get the hours worked this week 4. Calculate this week’s wages 5. Add wages to total company payroll 6. Write empNum, payRate, hours, wages to file write total company payroll on screen 29

C++ Program 30 // *************************************************** // Payroll program // This program computes each employee’s wages and // the total company payroll // *************************************************** #include // for keyboard/screen I/O #include // for file I/O using namespace std; void CalcPay ( float, float, float& ) ; const float MAX_HOURS = 40.0; // Maximum normal hours const float OVERTIME = 1.5; // Overtime pay factor

C++ Code Continued 31 int main( ) { float payRate; // Employee’s pay rate float hours;// Hours worked float wages; // Wages earned float total;// Total company payroll int empNum;// Employee ID number ofstream payFile;// Company payroll file payFile.open( “payfile.dat” );// Open file total = 0.0;// Initialize total

32 cout << “Enter employee number: “; // Prompt cin >> empNum; // Read ID number while ( empNum != 0 ) // While not done { cout << “Enter pay rate: “; cin >> payRate ; // Read pay rate cout << “Enter hours worked: “; cin >> hours ; // and hours worked CalcPay(payRate, hours, wages); // Compute wages total = total + wages; // Add to total payFile << empNum << payRate << hours << wages << endl; cout << “Enter employee number: “; cin >> empNum; // Read ID number } 32

33 cout << “Total payroll is “ << total << endl; system(“PAUSE”); // ADD FOR DEV-C++ return 0 ;// Successful completion } // *************************************************** void CalcPay ( /* in */ float payRate, /* in */ float hours, /* out */ float& wages ) // CalcPay computes wages from the employee’s pay rate // and the hours worked, taking overtime into account { if ( hours > MAX_HOURS ) wages = (MAX_HOURS * payRate ) + (hours - MAX_HOURS) * payRate * OVER_TIME; else wages = hours * payRate; } 33