Anda di halaman 1dari 11

Programming in C++

Dr. M. Ahmadzadeh

Lecture 2
Computers…
• History
– 50s:
• big computers
• used by a limited number of people
– 60s:
• Multi million dollars computers
• Used by big company and a specialist
person
– 70s:
• Smaller in size and faster in process
• Used by ordinary people
– 90s:
• Even smaller in size and faster in
process
• Used by people in all aspect of life
Computers…
• Hardware
– Input
• Keyboard, scanner, hard disk , memory
etc.
– Output
• Screen, printer, hard disk, etc.
– Storage
• Volatile: memory
• Non-volatile: hard disk, floppy disk, CD,
flash memory, etc.
– Process
• CPU
– CU
– ALU
Computers…
• Software
– Is written by programming languages
• Machine Language: sequence of 0 and 1
• Assembly Language, needs assembler
• Mid-level and high-level languages, need
compiler or interpreter
– has two types:
• System program: to control the system
– Operating system
– Linkers
– Loaders
• Application program
– Word Processors, Spread Sheets
– Games
– And of course the programs that you are
going to write in this module.
A program in C++
# include <iostream.h>
int main(){
cout<< "This Is My First"<<"\t";
cout<< "C++ P R O G R A M."<<"\t";
cout<< "Hooray!"<<"\n";
return 0;
}

• Some tips
•Whenever you opened a brace, you need indentation
for next instruction
• your program needs at least one header
How to run this program
• Load Microsoft Visual C++
• Write the code
– File  New  Workspace tab  Blank
Workspace
– File  New  Files tab  C++ Source File
• Compile it
• Build  Compile
• If it has compiler error, correct your
program
• Execute it
– Build  Execute

This is your first lab activity.


Errors
• A compiler error happens when one of
the below fails:
• Syntax Checking (e.g. missing semicolon etc.)
• Semantic Checking (e.g. type checking etc.)

• A runtime error occurs mostly because


of memory issues. (e.g. dividing by
zero or shortage of memory)

• A logical error is a bug that makes


your program to function incorrectly.
Algorithm again…
• To create an algorithm for
the given problem you need:
– To understand the problem
properly.
– Does the program interact with
the user?
– Does it process the data?
– Does it generate an output?
Psuedocode
• A high level manner to describe your
algorithm.

• It has some structure similar to


programming languages.

• Need not to be as detailed as a program.

• It is environment-independent.
Flowchart
• A graphical representation of
a psuedocode
• Different boxes have different
meanings.
– Circle
– Rectangle
– Lozenge
– Parralelogram
Exercise
• Calculate the area and
perimeter of a rectangle using
pseudocode and flowchart

Anda mungkin juga menyukai