1 / 8

EMT 101 – Engineering Programming

Week 2. EMT 101 – Engineering Programming. Dr. Farzad Ismail. School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal 14300 Pulau Pinang. C++ Library. To be able to use ‘things’ already available for programming Math library Input/output library String library

taurus
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 2 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering UniversitiSains Malaysia NibongTebal 14300 Pulau Pinang

  2. C++ Library • To be able to use ‘things’ already available for programming • Math library • Input/output library • String library • Memory management, stack, many more..

  3. Data type • char • int signed: -2147483648 to 2147483647unsigned: 0 to 4294967295 (4 bytes) • String (depends on the machine and library implementations) • Float +/- 3.4e +/- 38 (4 bytes) • double (?????)

  4. Identifier • Names that you have assigned to represent ‘something’ • Cannot be identical to standard define identifiers in C++ • Example cout, for, if, else, main, class, double, float, etc

  5. Generic Approach • Including C++ library & header files • Declare global variables & main function • Initialization process: define variables, identifiers, memory allocation for variables • Algorithm • Plot, output, close program

  6. A Sample C++ Math #include <iostream> • #include <cmath>//to include math library • using namespace std; //to be able to use all the standard classes, objects and functions in C++ int main () // start of program body, main is a function withno parameters { • intcoefficient; // define an integer identifiercoefficient float X; float Y; cout << “This is a simple math program.” << endl; cout << “Please enter an integer value: ”<< endl; //computer asking an INTEGER value cin >> coefficient; cout << “Please enter any number: " << endl; // program asking any number cin >> X; Y= coefficient*X; cout << “The product of coefficient and X is:” << Y << endl; return 0; } // end of program body

  7. How to define a vector? • F1 and F2 • Use standard variables • Use array • What about defining a matrix?

  8. Exercises • Write a program to estimate the slope of the function F= sin x log x between [2, 5] • Write a program to find the resultant force of two input forces

More Related