CS 1400 Jan 10, 2007. What is it? Computer Science is the art and science of writing programs –Users use programs –Programmers create these programs A.

Slides:



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

CS107: Introduction to Computer Science Lecture 2 Jan 29th.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
ITEC113 Algorithms and Programming Techniques
CS 1400 Course Reader Introduction. What is Programming? Designing an appropriate algorithm Coding that algorithm in a computer language.
CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
Program Design and Development
CS 1400 Chapter 1 Introduction and Background
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
ACSE th Conference The Iconic Programmer Stephen Chen.
Chapter 3 Planning Your Solution
Chapter 1 Pseudocode & Flowcharts
Adapted from slides by Marie desJardins
Computer Science 101 Introduction to Programming.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
Chapter 2 - Algorithms and Design
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Writing Program Code in BASIC Write a program to prompt for and accept values into TWO variables, numx and numy. The program should square the value stored.
Coding Design Tools Rachel Gauci. What are Coding Design Tools? IPO charts (Input Process Output) Input- Make a list of what data is required (this generally.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Chapter 2 - Algorithms and Design print Statement input Statement and Variables Assignment Statement if Statement Flowcharts Flow of Control Looping with.
1 Chapter 2 - Algorithms and Design print Statement input Statement and Variables Assignment Statement if Statement Flowcharts Flow of Control Looping.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
Chapter 1 Pseudocode & Flowcharts
Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
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.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
Algorithms and Pseudocode
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
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.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
PROBLEM SOLVING. What is a Problem? A problem is a situation that needs to be resolved.
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Selection Using IF THEN ELSE CASE Introducing Loops.
Pseudocode (pronounced SOO-doh-kohd)  is a detailed yet readable description of what a computer program or algorithm must do, expressed in a formally-styled.
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithms
1-1 Logic and Syntax A computer program is a solution to a problem.
Algorithms and Flowcharts
The Selection Structure
Lecture 2 Introduction to Programming
Introduction To Flowcharting
ALGORITHMS AND FLOWCHARTS
Algorithms & Pseudocode
Programming Right from the Start with Visual Basic .NET 1/e
ALGORITHMS AND FLOWCHARTS
3 Control Statements:.
Introduction to Algorithms and Programming
Understanding Problems and how to Solve them by using Computers
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Basic Concepts of Algorithm
Chapter 2 - Algorithms and Design
Presentation transcript:

CS 1400 Jan 10, 2007

What is it? Computer Science is the art and science of writing programs –Users use programs –Programmers create these programs A program is a logical sequence of instructions that leads to a correct solution to a problem. Programmers are story-problem solvers!

Successful Problem Solvers have or acquire the necessary subject matter knowledge have a positive, objective attitude, viewing the activity as a learning opportunity rather than a “test” of their intelligence are active begin with what they understand draw on other information and sources of knowledge refer to the problem statement frequently employ sequential analysis when a question is initially unclear ask themselves questions and think out loud – (we call this "self talk") brainstorm use physical aids to thinking, such as drawing pictures relate problems to familiar / concrete experiences or to previous problems carefully proceed through a series of steps to reach a conclusion

Less Successful Problem Solvers lack necessary subject-matter knowledge and are willing to allow gaps of knowledge to exist have a poor attitude: an attitude of indifference towards achieving a complete, accurate comprehension of situations and relations demonstrate a lack of objectivity in dealing with problems are passive in their thinking have great difficulty in ascertaining what they are required to do grope blindly toward a solution fail to complete a chain of reasoning use one-shot thinking, rather than building an extended, sequential path to understanding rush through or skip instructions take little time to consider a question or break it down into its component parts are mentally careless and superficial select an answer on the basis of a feeling or guess

Example Program… washing hair 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 into hair until lather covers hair Rinse hair until all lather is removed Repeat the previous eight steps one more time

Programs vs. Algorithms A program contains an algorithm A program must be in a certain format –-- think of a business letter!

Algorithms in Computer Science 1.The instructions must be well ordered. 2.The algorithm must be unambiguous -- clear and incapable of being misunderstood. 3.The process must eventually end. 4.The requested action must be "doable.“ 5.The algorithm must produce a result.

Program Development Step 1 - Analyze the problem Input:Input: Identify what information the program will have to retrieve or will be provided to the program by the user. Values given or known values: Identify any values that appear in the problem statement. These may or may not be used in your solution. Also watch for values or formulas that are not given but that will need to be used to complete the solution. Processing: What will need to be done to produce the desired output? It is important at this stage to focus on what needs to be done, not how it will be accomplished. Output : Identify what is to be produced by this program. This will be a list of the desired results.

Example… “Write a program to calculate the volume of a box, using dimensions provided by the user.” Input: height, width, depth of box Given values: none Processing: calculate volume Output: volume of the box

Step 2 – Outline the solution List steps to be performed in correct order – not concerned with details at this point. Get height, width and depth of the box from user Calculate the volume of the box Output the dimensions entered and the volume of the box

Step 3 – Develop an algorithm in pseudocode Print “Enter the height of the box: “ Get height from user Print “Enter the width of the box: “ Get width from user Print “Enter the depth of the box: “ Get depth from user volume = height * width * depth Print “The volume of the box is “ Print volume

Step 4 – Test the algorithm Pretend you are the computer – hand tracing Step 5 – Code the algorithm into C++ Step 6 – Run and test the program on the computer Step 7 – Document the program

Programming Language Elements Punctuation and spelling Syntax and grammar Semantics Pseudocode allows us to start writing algorithms without worrying about these issues.

English-like Pseudocode Key Words – these words have special meaning Get Print And Or If Else End If Repeat End Repeat While End While

English-like Pseudocode VariablesVariables – one-word name representing a value or a place where a value can be stored Think of a mailbox: –The name on the mailbox represents a variable name, –The contents of the mailbox represent the variable value. A variable only holds one value at a time!

English-like Pseudocode OutputOutput Print “message” Print variable InputInput Get variable from user

English-like Pseudocode OperatorsOperators Arithmetic: *, +, -, / Assignment: = CalculationsCalculations Variable = arithmetic expression (Arithmetic expressions may only use known values and variables)

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

More Examples: “Write a program to calculate a paycheck, using hours worked and a payrate provided by the user” “Write a program to convert a temperature provided by the user in degrees Fahrenheit into degrees Centigrade” “Write a program to calculate the circumference of a circle provided by the user”

Control Structures Sequence Selection (or decision) Repetition

Selection If condition Statements… Else Statements… End If

Conditions A condition is a comparison question whose answer is either true or false (Boolean). The comparison operators are; greater than = greater than or equal == equal!= not equal

Example Selections If age < 18 Print “you cannot vote” Else Print “you can vote!” End If If quantity >= 26 Print “sufficient quantity is available: ” Print quantity End If

Example algorithm Write a program to calculate an employee paycheck using time-and-a-half for overtime Input: hours, payrate Given values: over 40 hours is overtime, overtime rate is 1.5 of payrate Processing: calculate regular pay, overtime pay, and total pay Output: total pay

Outline Get hours_worked and payrate from user If there was overtime, calculate pay using payrate for first 40 hours and 1½ payrate for additional hours Otherwise, calculate pay at payrate Print pay

Pseudocode Print “Enter hours worked: “ Get hours from user Print “Enter pay rate: “ Get payrate from user Overtime_rate = payrate * 1.5 If hours > 40 pay = 40 * payrate + (hours-40) * over_timerate Else pay = hours * payrate End If Print pay

Repetition The counted loop Repeat N times Statements… End Repeat The condition-controlled loop While condition Statements… End While

Examples “Write a program to output the squares of each number input by the user until the user inputs a negative number” “Write a program to accept 10 test scores from the user and output the counts of passing (>=60) and failing scores” “Write a program to output the squares of the integers 1 through 5”

Inputs:none Given values:integers 1 through 5 Processing:calculation squares Outputs:squares of integers 1 through 5

Outline… Start N as 1 As long as N is less than or equal to 5, repeat; Calculate and print the square of n Add 1 to n

N = 1 While N <= 5 square = N * N Print “The square of “, N, “ is “, square N = N+1 End While “Write a program to output the squares of the integers 1 through 5”

Print “The square of 1 is 1” square2 = 2 * 2 Print “The square of 2 is “, square2 square3 = 3 * 3 Print “The square of 3 is “, square3 square4 = 4 * 4 Print “The square of 4 is “, square4 square5 = 5 * 5 Print “The square of 5 is “, square5 Why not this?

“Write a program to accept 10 test scores from the user and output the counts of passing (>=60) and failing scores” Inputs:a list of 10 test scores Give values:a count of 10, a passing score of 60 Processing:find a count of passing and failing test scores Outputs:count of passing/failing scores

Outline… Start the counts of passing and failing scores as 0 Repeat the following 10 times; prompt the user and get a score if this score is passing add 1 to the passing count otherwise add 1 to the failing count Print the counts of passing and failing scores

passing = 0 failing = 0 Repeat 10 times Print “Enter a test score: “ Get score from user If score >= 60 passing = passing + 1 Else failing = failing + 1 End If End Repeat Print “Passing: “, passing, “ Failing: “, failing

“Write a program to output the squares of each number input by the user until the user inputs a negative number” Inputs:a list of positive numbers followed by a negative number Given values:none Processing:square of each positive number Outputs:calculated squares

Outline… Prompt the user and get the first number Repeat as long as the number is positive; calculate the square of this number Print the square Prompt the user and get the next number

Print “Enter the first number: “ Get number from user While number > 0 Square = number * number Print “Square is: “, square Print “Enter the next number: “ Get number from user End While “Write a program to output the squares of each number input by the user until the user inputs a negative number”