1 / 11

EMT 101 – Engineering Programming

Week 3. EMT 101 – Engineering Programming. Dr. Farzad Ismail. School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal 14300 Pulau Pinang. Overview. We have learned the basics of programming. Understand C++ library, data type, basic memory allocation, etc.

jetta
Download Presentation

EMT 101 – Engineering Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 3 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering UniversitiSains Malaysia NibongTebal 14300 Pulau Pinang

  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; } else { cout << “Please reduce your expenses!” << endl; }

  5. Math Example int main() { double r; ….. if(r>= 0) { double root = sqrt(r); } …… 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; } else { 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 <iostream> #include <string> #include <conio.h> using namespace std; int main() { int N; double value=0; string coin_type; cout << "enter coin type: " << endl; getline(cin,coin_type); cout << "Enter the number of coins: " << endl; cin >> N; if(coin_type == "1 sen") value = N*0.01; else if (coin_type == "5 sen") value = N*0.05; else if (coin_type == "10 sen") value = N*0.10; else if (coin_type == "20 sen") value = N*0.20; else if (coin_type == "50 sen") value = N*0.5; else cout << coin_type << " is not a valid coin" << 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 • 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) ii) and to determine the GPA of the students based on their grades. • Write a program to determine how much money you need to survive in Desasiswa

  11. Homework 1 • Refer to assignment section in website

More Related