0% found this document useful (0 votes)
64 views8 pages

CBasics Week2

The document discusses key concepts in C++ programming including libraries, data types, identifiers, and a generic programming approach. It provides examples of math libraries, common data types like char and int, and how identifiers are used. It also outlines a typical programming structure of including libraries, declaring variables, writing algorithms, and closing programs. Finally, it shows a sample C++ program to calculate the product of a coefficient and number to demonstrate basic math operations and input/output.

Uploaded by

Ahmad Ikhwan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views8 pages

CBasics Week2

The document discusses key concepts in C++ programming including libraries, data types, identifiers, and a generic programming approach. It provides examples of math libraries, common data types like char and int, and how identifiers are used. It also outlines a typical programming structure of including libraries, declaring variables, writing algorithms, and closing programs. Finally, it shows a sample C++ program to calculate the product of a coefficient and number to demonstrate basic math operations and input/output.

Uploaded by

Ahmad Ikhwan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Week 2

EMT 101 – Engineering


Programming

Dr. Farzad Ismail

School of Aerospace Engineering


Universiti Sains Malaysia
Nibong Tebal 14300 Pulau Pinang

1
C++ Library

To be able to use ‘things’ already available for


programming

Math library

Input/output library

String library

Memory management, stack, many more..

2
Data type

char

int signed: -2147483648 to 2147483647


unsigned: 0 to 4294967295 (4 bytes)

String (depends on the machine and library


implementations)

Float +/- 3.4e +/- 38 (4 bytes)

double (?????)
3
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

4
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

5
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 with no parameters


{
int coefficient; // define an integer identifier coefficient
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
6
How to define a vector?

F1 and F2

Use standard variables

Use array

What about defining a matrix?

7
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

You might also like