Life is Full of Alternatives

Slides:



Advertisements
Similar presentations
LECTURE 1 CMSC 201. Overview Goal: Problem solving and algorithm development. Learn to program in Python. Algorithm - a set of unambiguous and ordered.
Advertisements

1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 9/15/06CS150 Introduction to Computer Science 1 Combined Assignments, Relational Operators, and the If Statement.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 9/26/08CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Computer Science 1620 Programming & Problem Solving.
1 9/25/06CS150 Introduction to Computer Science 1 Nested Ifs, Logical Operators, exit() Page 194.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
The If/Else Statement, Boolean Flags, and Menus Page 180
1 9/28/07CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
Software Engineering 1 (Chap. 1) Object-Centered Design.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
19/5/2015CS150 Introduction to Computer Science 1 Announcements  1st Assignment due next Monday, Sep 15, 2003  1st Exam next Friday, Sep 19, 2003  1st.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
High-Level Programming Languages: C++
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
Fundamental Programming: Fundamental Programming Introduction to C++
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
1 09/15/04CS150 Introduction to Computer Science 1 Life is Full of Alternatives Part 2.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
1 10/3/05CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
1 9/26/05CS150 Introduction to Computer Science 1 Life is Full of Alternatives.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
CSE202: Lecture 5The Ohio State University1 Selection Structures.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
Problem Solving and Program Design. Problem Solving Process Define and analyze the problem. Develop a solution. Write down the solution steps in detail.
The Ohio State University
Introduction to Computer Programming
Chapter 3 Selection Statements
What Actions Do We Have Part 1
Bill Tucker Austin Community College COSC 1315
Computing Fundamentals
Engineering Problem Solving with C++, Etter/Ingber
CSC113: Computer Programming (Theory = 03, Lab = 01)
1.13 The Key Software Trend: Object Technology
Starting Out with C++: From Control Structures through Objects
1) C program development 2) Selection structure
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Summary Two basic concepts: variables and assignments Basic types:
CS150 Introduction to Computer Science 1
Let’s all Repeat Together
CS150 Introduction to Computer Science 1
Programs written in C and C++ can run on many different computers
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Let’s all Repeat Together
Understanding Conditions
Arithmetic Operations
CS150 Introduction to Computer Science 1
do/while Selection Structure
What Actions Do We Have Part 1
Life is Full of Alternatives
Capitolo 1 – Introduction C++ Programming
Reading from and Writing to Files
Life is Full of Alternatives
Module 3 Selection Structures 6/25/2019 CSE 1321 Module 3.
Life is Full of Alternatives Part 3
Reading from and Writing to Files
Presentation transcript:

Life is Full of Alternatives 9/14/05 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Problem Write a C++ program that allows the user the ability to enter their name and the number of nickels and pennies they have. You are then to print the number of dollars and change that corresponds to. The change should be in the form of nickels and pennies 9/14/05 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Last Time So far we have learned the basic statements in C++. These are Input/output statements Assignment statements Arithmetic statements When we compiled and ran our programs all the statements were executed in sequential order. In other words, the statements were executed in order, one after the other. These are called sequential structures 9/14/05 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Today Today we will begin examining how C++ statements can be executed out of sequence, and some statements could be skipped altogether Specifically, we will be looking at selection structures 9/14/05 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 UML Activity Diagrams UML: Unified Modelling Language Used to represent algorithms that will later be translated into code Give the programmer a visual representation of the solution to a problem Can also help the programmer see a solution to a problem 9/14/05 CS150 Introduction to Computer Science 1

Example Write a program that will read in the current temperature in degrees Fahrenheit and convert it into Celsius display message asking user for temperature in Fahrenheit read in temperature and store it convert temperature to Celsius display temperature in Celsius 9/14/05 CS150 Introduction to Computer Science 1

if Selection Structure The if selection structure allows a program to make a decision based on the truth or falsity of some condition The format is if (some condition is true) execute some statement(s) Example if (weight > 100.0) shipCost = 10.00; 9/14/05 CS150 Introduction to Computer Science 1

if Selection Structure If the condition in the if selection structure evaluates to false, then the statement following the if will be skipped if( grade > 59 ) cout << “passed!”; “passed!” will only be output if the grade is greater than 59. If the grade is 59 or less the passed will not be output and the program will continue 9/14/05 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 UML Activity Diagram if( grade > 59 ) cout << “passed!”; [grade > 59] output “passed!” [grade <= 59] 9/14/05 CS150 Introduction to Computer Science 1

Equality and Relational Operators Conditions in if selection structures are formed using equality and relational operators < less than relational > greater than relational <= less than or equal to relational >= greater than or equal to relational == equal to equality != equal to equality 9/14/05 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Examples if( height >= 6.2 ) if( age == 18 ) Notice the difference between == and = == is only used to compare two values = is used to assign the value to right into the variable on the left 9/14/05 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Example Your local bookstore has asked you to write a program to help them determine the cost of shipping of customers orders. If the order is $30 or less then shipping will cost $5, if the order is over $30 then shipping will be $3. 7.1: Write an algorithm to solve this problem 9/14/05 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Solution #include <iostream> #include “stdafx.h” using namespace std; int main() { double order, shipping; cout << "Enter the total amount of the order: "; cin >> order; if( order <= 30 ) shipping = 5.00; if( order > 30 ) shipping = 3.00; cout << "The cost of shipping is $" << shipping << endl; return 0; } 9/14/05 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Problem The bookstore has now changed it’s shipping policy so that If the order is $30 or less, shipping is $5 If the order is over $30 but less than $50, shipping is $3 If the order is over $50 then shipping is $2 7.2: What would we need to change in the program? 9/14/05 CS150 Introduction to Computer Science 1

CS150 Introduction to Computer Science 1 Summary In today’s lecture we learnt UML activity diagrams Simple if selection structure Relational and equality operators Readings from Chapter 2 P. 34 - 39: simple if, equality and relational operators P. 71 - 77: if, UML, bool 9/14/05 CS150 Introduction to Computer Science 1