1 Original Source : and Problem and Problem Solving.ppt.

Slides:



Advertisements
Similar presentations
Equations as Relations y = 2x is an equation with 2 variables When you substitute an ordered pair into an equation with 2 variables then the ordered pair.
Advertisements

Exercise 2.
Chapter 1: An Overview of Computers and Programming Languages
Introduction to Flowcharting
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
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.
© Janice Regan Problem-Solving Process 1. State the Problem (Problem Specification) 2. Analyze the problem: outline solution requirements and design.
Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
Algorithms. Software Development Method 1.Specify the problem requirements 2.Analyze the problem 3.Design the algorithm to solve the problem 4.Implement.
Chapter 1: An Overview of Computers and Programming Languages
Computer Science 1620 Programming & Problem Solving.
Algorithms. Software Development Method 1.Specify the problem requirements 2.Analyze the problem 3.Design the algorithm to solve the problem 4.Implement.
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Algorithms and Problem Solving
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
CHAPTER 1: AN OVERVIEW OF PROGRAMMING INSTRUCTOR: MOHAMMAD MOJADDAM How to Program in C++
Chapter 1 Pseudocode & Flowcharts
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages Updated by: Dr\Ali-Alnajjar.
CSC103: Introduction to Computer and Programming
Solving Linear Equation Word problems
CHAPTER 1 AN OVERVIEW OF COMPUTERS AND PROGRAMMING LANGUAGES.
Chapter 1: An Overview of Computers and Programming Languages.
Chapter 1 An Overview of Computers and Programming Languages.
Chapter 2: Problem Solving
Looping While-continue.
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
Overview of Programming and Problem Solving. Objectives In this chapter you will: Learn about different types of computers Explore the hardware and software.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
Two equations are equivalent if they have the same solutions. Solving a Linear Equation An equation is a statement in which two expressions are equal.
Chapter 1: An Overview of Computers and Programming Languages
1.3 Solving Linear Equations. Equation: a statement in which two expressions are equal Linear Equation- One variable equation that can be written as ax.
CHAPTER 5 TEST REVIEW SHOW ME THE MONEY!. QUESTION #1 Find the perimeter and area of the figure. 18ft 36ft 18ft 9ft A. 324ft², 72ft B. 162ft², 72ft C.
Controlling Function Behavior Sequence, Selection and Repetition.
Chapter 1: An Overview of Computers and Programming Languages
Solving systems of equations with 2 variables
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
Basic problem solving CSC 111.
1 Original Source : and Problem and Problem Solving.ppt.
Lesson 5.6-Number Problems Obj: To solve # word problems.
Unit conversion The formula for density d is
5.3 – Solving Multi-Step Inequalities. *Just like solving equations*
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 1: An Overview of Computers and Programming Languages.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
The length of a rectangle is 6 in. more than its width. The perimeter of the rectangle is 24 in. What is the length of the rectangle? What we know: Length.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Warm up 1. Convert 5,400 inches to miles. (1 mi = 5280 ft) 2. Convert 16 weeks to seconds 3. Convert 36 cm per second to miles per hour. (1 in = 2.54 cm)
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Chapter 1: An Overview of Computers and Programming Languages
Computer Science Department
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
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
CSC 118: Fundamentals Of Algorithm Development
Equations Test Review Grade 8.
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
Chapter 1: An Overview of Computers and Programming Languages
Creating Equations and Inequalities
Creating Equations and Inequalities
Presentation transcript:

1 Original Source : and Problem and Problem Solving.ppt

 Programming is a process of problem solving  Problem solving techniques ◦ Analyze the problem ◦ Outline the problem requirements ◦ Design steps (algorithm) to solve the problem  Algorithm: ◦ Step-by-step problem-solving process ◦ Solution achieved in finite amount of time 2

 Step 1 - Analyze the problem ◦ Outline the problem and its requirements ◦ Design steps (algorithm) to solve the problem  Step 2 - Implement the algorithm ◦ Implement the algorithm in code ◦ Verify that the algorithm works  Step 3 - Maintenance ◦ Use and modify the program if the problem domain changes 3

 Problem: Design an algorithm to find the perimeter and area of a rectangle.  Information: The perimeter and area of the rectangle are given by the following formulas: perimeter = 2 * (length + width) area = length * width 4

 Requirements: ◦ Input: length and width of the rectangle ◦ Output: perimeter and area of the rectangle ◦ Process: perimeter = ???, area =??? 5

 Algorithm: ◦ Get length of the rectangle ◦ Get width of the rectangle ◦ Find the perimeter using the following equation: perimeter = 2 * (length + width) ◦ Find the area using the following equation: area = length * width ◦ Display the result perimeter and area 6

7 A car park has the following charges: The 1 st hour costs RM2.00. The subsequent hours cost RM1.00 per hour. Write an algorithm to calculate the charges based on a vehicle’s entry and exit time. Entry_time Exit_time Exit_time Charge???? Input Process Output

8 YesNo

cin >> entry_time >> exit_time; period = exit_time – entry_time; if (period > 1) charge = 2 + ( period *1); else charge = 2; cout <<charge; 9 YesNo

void main() { int entry_time, exit_time, period, charge; cin >>entry_time >>exit_time; period = exit_time – entry_time; if (period > 1) charge = 2 + (period * 1); else charge = 2; cout <<charge; } 10

 Problem: Design an algorithm to calculate a paycheck of a salesperson.  Information: ◦ Every salesperson has a base salary. ◦ Salesperson receives $10 bonus at the end of the month for each year worked if he or she has been with the store for five or less years. ◦ The bonus is $20 for each year that he or she has worked there if over 5 years. 11

 Information (continue): Additional bonuses are as follows: ◦ If total sales for the month are $5,000- $10,000, he or she receives a 3% commission on the sale ◦ If total sales for the month are at least $10,000, he or she receives a 6% commission on the sale 12

 Requirements: ◦ Input: base salary, number of years work, total sale ◦ Output: amount of paycheck (total salary) ◦ Process: ??? 13

 Algorithm: ◦ Get baseSalary ◦ Get noOfServiceYears ◦ Calculate bonus using the following formula: if (noOfServiceYears <= 5) bonus = 10 * noOfServiceYears otherwise bonus = 20 * noOfServiceYears ◦ Get totalSale 14

◦ Calculate additionalBonus as follows: if (totalSale < 5000) additionalBonus = 0 otherwise if (totalSale>=5000 and totalSale<10000) additionalBonus = totalSale x(0.03) otherwise additionalBonus = totalSale x (0.06) 15

◦ Calculate payCheck using the equation payCheck = baseSalary + bonus + additionalBonus 16

 Problem: ◦ 10 students in a class ◦ Each student has taken five tests and each test is worth 100 points. ◦ Design an algorithm to calculate the grade for each student as well as the class average.  Design an algorithm to find the average test score.  Design an algorithm to determine the grade. ◦ Data consists of students’ names and their test scores. 17

 Algorithm 1: to find test score ◦ Get the five test scores. ◦ Add the five test scores. Suppose sum stands for the sum of the test scores. ◦ Suppose average stands for the average test score. Then average = sum / 5; 18

 Algorithm 2: to determine the grade. if average > 90 grade = A otherwise if average >= 80 and < 90 grade = B otherwise if average >= 70 and < 80 grade = C otherwise if average >= 60 and < 70 grade = D otherwise grade = F 19

 Main algorithm: ◦ totalAverage = 0; ◦ Repeat the following steps for each student in the class.  Get student’s name.  Use algorithm 1.  Use the algorithm 2.  Update totalAverage by adding current student’s average test score. ◦ Determine the class average as follows: classAverage = totalAverage / 10 20