CS 1400 Course Reader Introduction. What is Programming? Designing an appropriate algorithm Coding that algorithm in a computer language.

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Lecture 2.
Advertisements

CS107: Introduction to Computer Science Lecture 2 Jan 29th.
JAVA Coursework (the same for 2A and 2B). Fundamental Information The coursework is 30 marks in your O’Level = 15% of the exam Must be word processed.
Chapter 2: Problem Solving
Chapter 3 IFTHENELSE Control Structure © 2008 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved. Marilyn Bohl/Maria Rynn Tools for Structured.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Chapter 1 Pseudocode & Flowcharts
ITEC113 Algorithms and Programming Techniques
CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
CS107 Introduction to Computer Science Lecture 2.
Program Design and Development
Chapter 2: Input, Processing, and Output
CS101- Lecture 11 CS101 Fall 2004 Course Introduction Professor Douglas Moody –Monday – 12:00-1:40 – – –Web Site: websupport1.citytech.cuny.edu.
Program design example Task: Develop an algorithm expressed in pseudocode for a specified problem specified problem.
CS 1400 Chapter 1 Introduction and Background
Programming Fundamentals (750113) Ch1. Problem Solving
Pseudocode.
CS 1400 Jan 10, What is it? Computer Science is the art and science of writing programs –Users use programs –Programmers create these programs A.
Pseudocode.
Chapter 3 Planning Your Solution
Review Algorithm Analysis Problem Solving Space Complexity
Chapter 1 Pseudocode & Flowcharts
Introduction to Programming (in C++) Introduction Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Chapter 2: Problem Solving
Chapter 2: Problem Solving
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
An ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time Let's examine the four parts of this.
Looping While-continue.
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
Overview of Programming and Problem Solving Textbook Chapter 1 1.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Introduction to Algorithms. What is Computer Science? Computer Science is the study of computers (??) This leaves aside the theoretical work in CS, which.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Procedural Programming. Programming Process 1.Understand the problem 2.Outline a general solution 3.Decompose the general solution into manageable component.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 2 I Am Not a Control Freak!
Chapter 1 Pseudocode & Flowcharts
Control Structures (B) Topics to cover here: Sequencing in C++ language.
1 Program Planning and Design Important stages before actual program is written.
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
INTRODUCTION TO PROGRAMMING. Program Development Life Cycle The program development life cycle is a model that describes the stages involved in a program.
Data Structures & Algorithms CHAPTER 1 Introduction Ms. Manal Al-Asmari.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
CS Jan 2007 Chapter 2 sections 1, 2, 4 – 6, 8,
The Hashemite University Computer Engineering Department
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
Algorithms and Pseudocode
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
MIT App Inventor Lesson 3 Algorithms Variables Procedures.
Lecture Notes 1/20/05 Pseudocode.  Pseudocode standard which we will follow in this class: - Statements are written in simple English; - Each instruction.
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
PROBLEM SOLVING. What is a Problem? A problem is a situation that needs to be resolved.
Introduction to Flowcharts
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Introduction to Algorithms
1-1 Logic and Syntax A computer program is a solution to a problem.
An Introduction to Programming and VB.NET
Chapter 1 Pseudocode & Flowcharts
Introduction to pseudocode
Programming Right from the Start with Visual Basic .NET 1/e
Chapter 1 Pseudocode & Flowcharts
Algorithm and Ambiguity
Chapter 1 Pseudocode & Flowcharts
Nate Brunelle Today: Pseudo-Code
Presentation transcript:

CS 1400 Course Reader Introduction

What is Programming? Designing an appropriate algorithm Coding that algorithm in a computer language

What is an algorithm? Def: An algorithm is a logical sequence of instructions to accomplish a task. important points: 1.instructions must be well ordered 2.instructions must be unambiguous 3.the process must eventually end 4.the actions must be doable 5.the algorithm must produce the required result

from a shampoo bottle… lather rinse repeat –algorithm critique: too ambiguous doesn’t end

A more detailed algorithm for a shampoo bottle… Wet hair Pick up shampoo bottle Open the bottle Pour some shampoo on your hand Close the shampoo bottle Set bottle down Put shampoo on hair Rub shampoo through hair until lather covers hair Rinse hair until all lather is removed Repeat the previous eight steps one more time

What is a computer program? A computer program is just an algorithm expressed in computer language instructions

Program development… Steps: 1.analyze the problem 2.outline the solution 3.develop an algorithm in pseudocode 4.test the algorithm 5.code the algorithm into a computer language 6.run and test the computer program 7.document and maintain the program

Computers are not smart! While instructions to a friend may assume implied understanding and intelligence, instructions to a computer need to be simple, specific, and detailed. The computer will not attempt to determine the purpose of your instructions – it will only blindly carry them out.

Types of user interfaces Graphical Console this semester next semester!

Pseudocode flexible (no rigid syntax rules) English-like, but unambiguous contains: –keywords (words that have special meaning) –variables (representations of a saved value) –operators –punctuation

Keywords GetElse PrintEnd If AndRepeat OrEnd Repeat IfWhile End While

Operators + (addition) - (subtraction) * (multiplication) / (division) = (assignment)

A. Basic Calculations form: = Examples: cost = tax * price (calculate the sum of tax and price, save the result as cost) area = length * width (calculate the product of length and width, save the result as area)

B. Displaying messages and values form: Print “ ” form: Print Examples: Print “Hello!” (display the message “Hello” on the screen) Print cost (display the current value of variable cost on the screen)

C. Getting input form: Get from user Examples: Get price from user (get the value for variable price from the user’s keyboard)

Pseudocode Example 1: “Write a program to calculate the volume of a box, using dimensions provided by the user.” Print “Enter height, width, and depth of box:” Get height from user Get width from user Get depth from user volume = height * width * depth Print “Volume is: “ Print volume

Pseudocode Example 2: “Write a program to calculate a paycheck using regular hours, payrate, and overtime hours provided by the user. Assume overtime is paid at double.”.

D. Conditions form: If Else End If comparisons use:, =, !=, ==, And, Or

Example If age < 21 Print “Sorry, you are too young” Print “Please try again next year” Else Print “You may enter” End If

D. Conditions (alternate) form: If End If Example: If weight < 90 Print “Consider eating more protein” End If

Example Write a program that gets an employee's information from a user and calculates their pay for the week. The input includes the employee total hours worked this week and their hourly wage. The employee is to be paid their basic wage for the first 40 hours worked and time-and- a-half for all hours above 40. Output the regular pay, overtime pay, and total pay for the week to the screen. If the employee worked 40 hours or less, do not output any information about overtime pay.

Step 1: Analyze the problem Inputs: –hours worked, pay rate Given values: –over 40 hours is overtime –overtime is 1.5 of regular pay Calculations: –regular pay, overtime pay, total pay Outputs: –regular pay, overtime pay (if present), total pay

Step 2: Outline solution Get hours worked, and pay rate from a user If there was overtime, calculate regular pay on the first 40 hours and 1½ pay for additional hours Otherwise, calculate all hours worked at regular pay Print regular pay, If there was overtime, print the overtime pay Print total pay

Step 3: Algorithm in Pseudocode 1.Print “Enter hours worked: “ 2.Get hours from user 3.Print “Enter rate of pay: “ 4.Get payRate from user 5.If hours > 40 6.regularPay = 40 * payRate 7.overtimePay = (hours – 40) * payRate * Else 9.regularPay = hours * payRate 10.overtimePay = End If 12. totalPay = regularPay + overtimePay 13.Print "Regular Pay: ", regularPay 14. If overtimePay != 0 15.Print "Overtime Pay: ", overtimePay 16. End If 17. Print "Total for this week: ", totalPay

Step 4: Test algorithm InstrscreennamehourspayRateregularPayovertimePay …

E. Repetition form: Repeat times End Repeat Example: Repeat 5 times Print “Vote for Napoleon!” End Repeat

E. Repetition (alternate) form: While End While Example: Print “Enter a positive number: “ Get number from user While number < 0 Print “Sorry, too low. Try again:” Get number from user End While

Examples Write a program to output the squares of the numbers 1 through 100 Write a program to output the sum of 50 product costs entered by the user Write a program to output the sum of a list of positive numbers entered by the user