0% found this document useful (0 votes)
37 views

EMT 101 - Engineering Programming

This document provides an introduction to programming and computer programming concepts. It discusses what programming is, different types of programming languages like machine language, Fortran, C/C++, and Java. It also covers procedural vs object-oriented programming and provides examples of sample C++ code to get user input. The document is intended to help students understand basic programming concepts as part of an EMT 101 engineering course.

Uploaded by

Ahmad Ikhwan
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

EMT 101 - Engineering Programming

This document provides an introduction to programming and computer programming concepts. It discusses what programming is, different types of programming languages like machine language, Fortran, C/C++, and Java. It also covers procedural vs object-oriented programming and provides examples of sample C++ code to get user input. The document is intended to help students understand basic programming concepts as part of an EMT 101 engineering course.

Uploaded by

Ahmad Ikhwan
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

Week 1

EMT 101 – Engineering


Programming

Dr. Farzad Ismail

School of Aerospace Engineering


Universiti Sains Malaysia
Nibong Tebal 14300 Pulau Pinang

1
What Can You Do with Programming?

As a database control

Web based application

Machine or Electronics control

Systems control (UAV)

Software development

Solve Engineering Problems (Simulation)

2
What is Programming?

A computer needs ‘something’ to tell it what to do to


perform certain tasks

The tasks may require precise details and multiple steps

That ‘something’ is called a computer program.

The process of developing and executing the computer


program is called computer programming.

3
Computer User versus Computer Programmer

You can use a computer without doing any programming

A Facebook user does not need to know how the


software has been programmed to be able to use
Facebook

Analogy: You can ride a motorcyle without being a


mechanic, operate a TV without being an electrician

Most computer users may never have to perform


programming!

4
Computer User versus Computer Programmer

A programmer develops a software(s) for computer users


to use

Programmers not only come from computer engineers or


scientists but also other engineering or scientific disciplines

Programming is a very interesting and rewarding activity:


write a computer game with sound and motion

Programmers fully direct the computer as their slaves to


extend their brain capabilities

5
What is a Program

Program = Data + Algorithm

All in source code

Written in various languages

High level languages requires:


1- Compile
2- Link or Build
3- Execute

6
Choices of Programming Language

Machine language

Fortran

C++

Java

7
Machine Language

The most primitive yet the most efficient way of communicating


with the computer

Task:
1) Move contents of memory location 10000 into location ET
2) Add the value 3000 from memory location ET
3) If the outcome is negative, proceed with instruction located in
memory location 5432

In machine language the instruction reads:


161 10000 45 3000 127 5432

8
Fortran Language

The first high level language developed in 1957, mainly for solving
mathematical problems

In FOTRAN 77 the task now reads:


REAL*8 X10000
REAL*8 ET
X10000= 10.d0
ET = X10000 + 3000.d0
IF (ET.LT. 0.d0)
CALL F(X5432)
ENDIF

9
C, C++ Language

C developed in 1970 (Dennis Ritchie) followed by C++ in 1980 (Bjaern


Stroustrup)

In C++ the task now reads


X10000 = 10.0;
float ET;
ET = X10000 + 3000;
If (ET < 0)
{
F(X5432);
}

10
Differences between these languages

The machine language is the most ‘direct’ form of communication


between human and computer, but it is very difficult to use

FORTRAN and C/C++ are easier to be understood and used by humans


compared to machine language but the computer does not understand it
-> needs a compiler to convert them to object file (machine language
form)

Based on current problem (set-up), the difference between C++ and


FORTRAN is just the syntax.

11
Procedural vs. Object Oriented Programming
Procedural: need to know the details of each part of
program to use the code

Object Oriented (OOP): just need to know at higher level to


be able to use the code

OOP is slightly less efficient in terms of running time versus


procedural but easier to manage

Most research codes and libraries are written in procedural


programming

12
What Scientific Programming can Do?

Movie 23 - P/H: Below

Movie 5, - Turning Circle

Movie 57 - Propeller

Movie 68 - Rough Sea

13
First, need to understand

The Generic approach of Programming to solve scientific


or engineering problems -> Flow chart

Concept of variables, identifiers, data type, C++ library

Initialization, arrays and memory allocation

Control structure and loops

Function, subroutines, structures and classes

14
A Sample C++ Code
#include <iostream> //to include C++ library for input and output of values

using namespace std; //to be able to use all the standard classes,
c objects and functions in C++

int main () // start of program body, main is a function with no parameters that
returns an int. value
{
int numberOfLanguages; // define an identifier numberOfLanguages as an integer data type

cout << “Hello student.\n "; // program greets the student and go to next line
<< “Welcome to EMT 101.\n”;

cout << “How many programming languages have you used? "; // program asking user to input no of
languages
cin >> numberOfLanguages; // input from user is now saved into
numOfLanguages

return 0; // to return 0 as the integer value of main, most C++ compilers need this

} // end of program body 15


Exercises

Write a C++ program to enter your name and your


student metric number.

16

You might also like