Professional Documents
Culture Documents
C++/UNIX tutorial
C++/UNIX tutorial
Introduction
What is a Computer? Up until the late 1940s, a Computer was a person who performed calculations. What about now?
Programs Programs are sequence of step by step instructions to the computer Programs, and the data values processed by programs, are called software.
Programming languages
Low-Level Programming Languages Machine language Assembly language
High-Level Programming Languages Instructions look more like English and Math Generally result in multiple low level commands, for a single high level statement.
Machine Language
Used by early computers Executable by machines, almost incomprehensible to
11001010000100101000010101110100 11000101010001110010101000110010
Assembly Language
Mnemonics used for instruction codes and memory locations Not directly understandable by machine. They must be translated Easier for humans to use and still in use today. Ex:
mathematical notation and English Easy for humans to understand. Not understandable by machines, must be translated using a compiler or an interpreter. Programming tools such as integrated programming environment with a debugger are available to aid in programming process.
Assemblers Interpreters
Compilers
Interpreters
Translate and execute each high-level statement, one at a
time
the source code, to machine language and store the result. Machine language code produced by compilers is called object code
10
Programming Paradigms
Procedural Paradigm
Object-Oriented Paradigm
11
System Software
Operating System
Memory and resource management Job scheduling Security
12
Analyze the problem Develop a solution Code the solution Test and debug
Documentation
Internal documentation Comments Notes to the reader of the program Identifiers should represent the information they hold or the task they define. External documentation Users manual Test plan Design document
Maintenance
Correcting new problems Adding new features Modifications due to change in requirements
13
Algorithms
An Algorithm is a step by step sequence of
instructions.
It must be unambiguous It must be doable Each step must terminate, and the entire
14
Example of Algorithm
Write an algorithm that will determine the largest value of four values.
15
A flowchart solution
INPUT first value, STORE value
start
Count =0
in Largest. Loop to determine if any other numbers are larger. DISPLAY Largest.
count < 3
TRUE
Input Number
TRUE
end
FALSE
16
A pseudocode solution
INPUT first value, STORE value in Largest Repeat three times INPUT next value, store in Number IF Number >Largest,
DISPLAY largest
17
Control Structures
Sequence
Execute sequence of statements in order given.
This is the default control structure.
Selection
Select between alternative paths.
Iteration
Repeat a statement or collection of statements over
Invocation
Execute a complex task, which is written separately
18
19
20
21
More on Comments
Line comments begin with // and continue for the rest
of the line.
Delimited comments begin with /* and end with */ Only delimited comments can be used in C.
22
Preprocessor Command
#include <iostream>
When using classes or functions that are stored in different files from the one you are writing, include the header file for those classes. The header file containing the class needed for the object cout is iostream.h
#include <iostream>
23
Preprocessor Command
using namespace std;
The keyword namespace is used to define a scope. std is a namespace that is defined by C++. The object cout is part of the scope defined by std To access the object cout, you need to type std::cout The directive/keyword using is used to simplify the access.
24
Welcome to SLIIT -
cout is an object which displays whatever is to it on the screen. << is the insertion operator used to send information to cout
sent
25
Free Format
A language has free format if statements can appear anywhere on one or several lines. Blank lines are ignored. Extra spaces are ignored. Multiple statements can be placed on the same line. Statements can be broken over more than one line anywhere other than in the middle of a string
26
Program Style
Use blank lines to separate parts of the program. Use indentation to align curly braces and match the opening and closing braces by placing them under each other. Note: When using the vi editor, use 3 spaces for every indentation. Use blank spaces to separate the parts of a statement to make it easier to read.
27