1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal 14300 Pulau Pinang Week 3.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

Computer Science 1620 Math Library. Remember this program? suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
LECTURE 1 CMSC 201. Overview Goal: Problem solving and algorithm development. Learn to program in Python. Algorithm - a set of unambiguous and ordered.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
Computer Science 1620 Loops.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
Computer Science 1620 Functions. Given a number n, the factorial of n, written n!, is computed as follows: note: 0! = 1 examples: n! = n x (n-1) x (n-2)
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
General Computer Science for Engineers CISC 106 Lecture 34 Dr. John Cavazos Computer and Information Sciences 05/13/2009.
1 9/25/06CS150 Introduction to Computer Science 1 Nested Ifs, Logical Operators, exit() Page 194.
1 CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
General Computer Science for Engineers CISC 106 Lecture 26 Dr. John Cavazos Computer and Information Sciences 04/24/2009.
1 9/26/07CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
Computer Science 1620 Selection Structures. Write a program that accepts the speed of a vehicle, and determines whether that person is speeding assume.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
CSC 1051 M.A. Papalaskari, Villanova University Repetition CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing.
Functions Parameters & Variable Scope Chapter 6. 2 Overview  Using Function Arguments and Parameters  Differences between Value Parameters and Reference.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 1.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 9.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 4.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Subject: Programming in C++ 1. LEARNING OUTCOME  At the end of this slide, student able to:  Know the brief history of C++.  Explore Microsoft Visual.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
1 Discretization of Fluid Models (Navier Stokes) Dr. Farzad Ismail School of Aerospace and Mechanical Engineering Universiti Sains Malaysia Nibong Tebal.
Selection. Flow Chart If selection If/else selection Compound statement Switch.
1 Discretization Methods Dr. Farzad Ismail School of Aerospace and Mechanical Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 9.
Conditional Structures UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
Lecture 8: Making Decisions Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 11.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 2.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
1 Chapter 4: Basic Control Flow ► Chapter Goals  To be able to implement decisions using if statements  To understand statement blocks  To learn how.
1 COMS 261 Computer Science I Title: Functions Date: October 12, 2005 Lecture Number: 17.
Before we get started…. First, a few things… Weighted Grading System Programming Style Submitting your assignments… The char and string variable types.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 6.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
Selection Control Structures 2 (L09) * Nested if Statements * The if-else Chain * Exercise: if, if-else, nested if, and if-else chain Selection Control.
CSIS 113A Lecture 5 Functions. Introduction to Functions  Building Blocks of Programs  Other terminology in other languages:  Procedures, subprograms,
CSE202: Lecture 5The Ohio State University1 Selection Structures.
General Computer Science for Engineers CISC 106 Lecture 27 Dr. John Cavazos Computer and Information Sciences 04/27/2009.
Review 1.
Chapter 3 Control Statements
Bill Tucker Austin Community College COSC 1315
EMT 101 – Engineering Programming
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Chapter 5 Functions.
Introduction to C++ October 2, 2017.
Multi-dimensional Array
Starting Out with C++: From Control Structures through Objects
Summary Two basic concepts: variables and assignments Basic types:
Decision I (if Statement)
Jeff West - Quiz Section 4
Using string type variables
(Dreaded) Quiz 2 Next Monday.
Programming Strings.
Repetition CSC 1051 – Data Structures and Algorithms I Course website:
CSE Module 1 A Programming Primer
Programming Fundamental-1
ㅎㅎ Fifth step for Learning C++ Programming Homework 1 Homework 2
Presentation transcript:

1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 3

2 Overview We have learned the basics of programming. Understand C++ library, data type, basic memory allocation, etc. Use of Main program Now need to understand control structures for decision making procedures in the program

3 Case Study 1 How much money you need to survive in Desasiswa ? Where to start? Use of Flow Chart

4 Decision Making Within a Program Consider a student’s budget control living in USM If(income>= expenses) { cout << “OK” << endl; cout << “OK” << endl; } else else { cout << “Please reduce your expenses!” << endl; cout << “Please reduce your expenses!” << endl; }

5 Math Example int main() { double r; { double r; ….. ….. if(r>= 0) if(r>= 0) { double root = sqrt(r); double root = sqrt(r); } …… …… return 0; return 0; }

6 To use ‘=’ or ‘==’ Recall that ‘x=y’ means you are assigning the value y into x If(income == expenses) { cout << “OK” << endl; cout << “OK” << endl; } else else { cout << “Please reduce your expenses!” << endl; cout << “Please reduce your expenses!” << endl; }

7 Multiple Choices Consider a program that asks a user to specify a coin and its quantities: 1 sen, 5 sen, 10 sen, 20 sen, 50 sen The computer program is supposed to determine the total RM value of the coins

8 Coins Program #include #include using namespace std; int main() { int N; double value=0; int N; double value=0; string coin_type; string coin_type; cout << "enter coin type: " << endl; cout << "enter coin type: " << endl; getline(cin,coin_type); getline(cin,coin_type); cout << "Enter the number of coins: " << endl; cout << "Enter the number of coins: " << endl; cin >> N; cin >> N; if(coin_type == "1 sen") if(coin_type == "1 sen") value = N*0.01; value = N*0.01; else if (coin_type == "5 sen") else if (coin_type == "5 sen") value = N*0.05; value = N*0.05; else if (coin_type == "10 sen") else if (coin_type == "10 sen") value = N*0.10; value = N*0.10; else if (coin_type == "20 sen") else if (coin_type == "20 sen") value = N*0.20; value = N*0.20; else if (coin_type == "50 sen") else if (coin_type == "50 sen") value = N*0.5; value = N*0.5; else else cout << coin_type << " is not a valid coin" << endl; cout << coin_type << " is not a valid coin" << endl; cout << "Coins value is RM " << value << endl; cout << "Coins value is RM " << value << endl; getch(); return 0; } // end of program body

9 Nested Branches Deployed as a way to perform more complex decision making procedure Example USM students performance Need to select if student is from (1) Matriculation OR (2) STPM (2) STPM Define performance criteria as A=4.0, B=3.0, C=2.0, else fail

10 Exercises Write a program i) to input the origin of the students (STPM/Matriculation) i) to input the origin of the students (STPM/Matriculation) ii) and to determine the GPA of the students based on their grades. ii) and to determine the GPA of the students based on their grades. Write a program to i) Enter your total monthly income i) Enter your total monthly income ii) Enter your type of expenses and cost for a month ii) Enter your type of expenses and cost for a month iii) Determine whether you can survive in Desasiswa iii) Determine whether you can survive in Desasiswa

11 Homework 1 Refer to assignment section in website