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

Week 4 Programming Language

The document discusses programming languages, the software development process including writing, editing, compiling and linking programs, and provides an example case study of writing a program to calculate and output the area and circumference of a circle given a radius input by the user. Pseudocode and flowcharts are presented as ways to design algorithms before implementation in an actual programming language like C++.

Uploaded by

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

Week 4 Programming Language

The document discusses programming languages, the software development process including writing, editing, compiling and linking programs, and provides an example case study of writing a program to calculate and output the area and circumference of a circle given a radius input by the user. Pseudocode and flowcharts are presented as ways to design algorithms before implementation in an actual programming language like C++.

Uploaded by

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

ECC3191

COMPUTER
PROGRAMMING
AND
APPLICATION
PROGRAMMING LANGUAGE

Dr. Aidi Hizami bin Ales @ Alias


PRESENTATION OUTLINE

Programming Language

Software Development Environment

Introduction to C++ Language

Case Study
PROGRAMMING LANGUAGES

What is a programming language?


• computer language engineered to create a standard form of
commands
• these commands can be interpreted to a set of code understood
by the machine
• Programs are created programming languages to control the
behaviour and output of a machine through accurate algorithms,
similar to the human communication process
• An algorithm is described using the programming language
• Since the oldest forms of programming languages like COBOL and
FORTRAN, thousands of computer languages have been developed
PROGRAMMING LANGUAGES

Two categories: low level and high level language

Low level language


• Machine language
• a string of binary (0 & 1)

• Assembly language
• Operations must be specified in detail
• Use mnemonics instruction and symbolic names
• More efficient in memory space and run faster

High level language


• e.g.: FORTRAN, Basic, Pascal, Cobol, C++, JAVA
• easier to use
• one statement generates a number of low level instructions
WRITING, EDITING, COMPILING AND
LINKING PROGRAMS

Basic high-level language development environment consists of:

• Editor
• To enter program at terminal
• Use editor or word processor
• Create source file (.cpp file)

• Compiler/ Assembler
• Translate program into machine language
• Detects syntax error
• Create object file
WRITING, EDITING, COMPILING
AND LINKING PROGRAMS

• Linker
• Link other object file or library routines
• Create load file

• Loader
• Put load file in main memory
• For execution
• Create executable program .exe

• Debugger
• Detect, diagnose and correct errors in programs
• Run one instruction at a time
• Bugs = errors
The process:

• Program is created in the editor and stored on disk

• Preprocessor program processes the code

• Compiler creates object code and stores it on disk

• Linker links the object code with the libraries, creates a .out file
and stores it on disk

• Loader puts program in primary memory

• CPU takes each instruction and executes it, possibly storing new
data values as the program executes
A SIMPLE PROGRAM

header files

using namespace std;

int main ()

statements

return 0;

}
A SIMPLE PROGRAM

#include <iostream>

using namespace std;

int main ()

//Display Hello World!

cout << “Hello World!\n”;

return 0;

}
A SIMPLE PROGRAM
#include <iostream>

- is a preprocessor directives: tells compiler to include iostream library


in this program

using namespace std;

- Tells compiler to find names in standard library, i.e. cout

int main ()

- heart of the program: Program execution starts here


A SIMPLE PROGRAM

// Display Hello World!

- comments, ignored by the compiler (i.e. //, /* and */)

cout << “Hello World!\n”;

- cout<< is console output. Sends a string “Hello World\n” to the


console

return 0;

- placed at end of main function, 0 will terminate the program


successfully
SOFTWARE DEVELOPMENT
ENVIRONMENT

Programming is a problem-solving activity

Normally, programmers use these processes to develop a program


• Problem
• Analysis
• Design Algorithm
• Implementation
• Testing
SOFTWARE DEVELOPMENT
ENVIRONMENT

Problems
• Converting miles to kilometers

Analysis
• Data requirements
• Input : miles
• Output : kilometers
• Formula : 1 mile = 1.609 kilometers

Algorithms
• Computing problems
• All can be solved by executing a series of actions in a specific order
• Algorithm is a procedure in terms of:
• Actions to be executed
• The order in which these actions are to be executed
SOFTWARE DEVELOPMENT
ENVIRONMENT

• Top down design - breaking program into subprograms


• Example:
• Get the distance in miles
• Convert the distance to kilometers
• Display the distance in kilometers

Implementation
• Writing a program
• Convert each algorithm step into a statement in a programming
language

Testing
• Run the program several times using different set of data to make
sure it works correctly
PSEUDOCODE
Pseudocode is
• Artificial, informal language that helps us develop algorithms
• Similar to everyday English
• Not actually executed on computers
• Helps us “think out” a program before actually writing it

Easy to convert into a corresponding C++ program

Consists only of executable statements

Example of pseudocode
Initialize n to fifty
Initialize sum to zero
Initialize f1 and f2 to zero
repeat n times
add f1 and f2, store this value in sum
assign f1's current value to f2
assign sum`s current value to f1
end loop
FLOWCHART

What is a flowchart
• Graphical representation of an algorithm
• Drawn using certain special-purpose symbols connected by arrows
called flow lines
• A graphical way to describe the solution of a problem

Start and end


Selection

Data flow

Input / Output Calculation


Example: Compute and print the summation of two numbers

Start

Input
a,b

S=a+b

Output
S

End
Exercise: Read any number from the user, then print positive if it is
positive
Start

Input
num

Num True
>0
Output
“+ve”
False

End
CASE STUDY

Problem
• Take the radius of a circle and compute and print its area and
circumference

Analysis
• Data requirements
• Problem constant
• Pi 3.14159
• Problem input
• radius
• Problem output
• area, circumference
• Relevant formulas
• Area of a circle = pi x r2
• Circumference of a circle = 2 x pi x r
CASE STUDY

Design
• Initial algorithm
• get circle radius
• calculate area
• calculate circumference
• display area and circumference

• Refine the algorithm


• Could be transferred to pseudocode or flowchart form, or both
CASE STUDY

Pseudocode
• Get circle radius from user
• Calculate area
• Assign product of Pi and radius to area
• Find circumference
• Assign product of two times Pi and radius to circumference
• Display the area and circumference
CASE STUDY

Flowchart

Start

Get
radius

Calculate
area

Calculate
circum.

Print
result

End
// Calculate and display the area and circumference of a circle
#include <iostream>
#define Pi 3.14159
using namespace std;

int main ()
{
double radius, area, circum;
cout << “Enter radius>”; //Get the circle radius
cin >> radius

area = Pi*radius*radius// Calculate the area


circum=2*Pi*radius// Calculate the circumference

// Display area and circumference


cout << “The area is” << area << “\n”;
cout << “ The circumference is” <<circum<< “\n”;

return 0;
}
CASE STUDY

Implementation

Output

Enter radius> 5
The area is 78.539750
The circumference is 31.415900

Testing
• Calculate by using other means to verify the result

You might also like