What is a Computer?
Computer
Device capable of performing
computations and making logical
decisions
Computers process data under the
control of sets of instructions called
computer programs
Hardware
Various devices comprising a computer
Keyboard, screen, mouse, disks, memory,
CD-ROM, and processing units
Software
Programs that run on a computer
Common Softwares
Operating System
An interface between the hardware and the
user.
Provides an easy and efficient use of the system
resources.
Compilers
Assemblers
Interpreters
Programming Language : Definition
A vocabulary and set of
grammatical rules for instructing a
computer to perform specific tasks.
Evolution of Programming languages
First Generation : Machine languages
Strings of numbers giving machine specific instructions
Example:
+1300042774
+1400593419
+1200274027
Second Generation : Assembly languages
English-like abbreviations representing elementary
computer operations (translated via assemblers)
Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
Third Generation : High-level languages
Codes similar to everyday English
Use mathematical notations (translated via compilers)
Example: grossPay = basePay + overTimePay
Assembler
Instructions written in assembly language
must be translated to machine language
instructions :
Assembler does this
One to one translation : One AL instruction is
mapped to one ML instruction.
AL instructions are CPU specific.
Compiler
Instructions written in high-level language
also must be translated to machine
language instructions :
Compiler does this
Generally one to many translation : One
HL instruction is mapped to many ML
instruction.
HL instructions are not CPU specific but
compiler is.
Translation from HLL to ML
Interpreter
An interpreter translates high-level instructions
into an intermediate form, which it then executes.
In contrast, a compiler translates high-level
instructions directly into machine language.
Compiled programs generally run faster than
interpreted programs.
The advantage of an interpreter, however, is that
it does not need to go through the compilation
stage during which machine instructions are
generated.
This process can be time-consuming if the
program is long. The interpreter, on the other
hand, can immediately execute high-level
programs. For this reason, interpreters are
sometimes used during the development of a
program, when a programmer wants to add small
Structured Programming
Structured programming
Disciplined approach to writing
programs
Clear, easy to test and debug and easy
to modify
Structured programming is hard
and takes time to master
Structured Programming contd..
A technique for organizing and coding
computer programs in which a hierarchy
of modules is used, each having a single
entry and a single exit point, and in which
control is passed downward through the
structure without unconditional branches
to higher levels of the structure.
Three types of control flow are used:
sequential, test, and iteration
Object Oriented Programming
It is a programming paradigm that relies on the
concept of classes and objects. It is used to
structure a software program into simple, reusable
pieces of code blueprints (usually called classes.
There are many object-oriented programming
languages including JavaScript, C++, Java, and
Python.
A class is an abstract blueprint used to create more
specific, concrete objects. Classes often represent
broad categories, that share attributes. These
classes define what attributes an instance of this type
will have, like color, but not the value of those
attributes for a specific object.
Classes can also contain functions,
called methods available only to objects of that type.
These functions are defined within the class and
perform some action helpful to that specific type of
object.
C++ program
#include <iostream>
using namespace std;
class Fibonacci{
public:
int a, b, c;
void generate(int); };
void Fibonacci::generate(int n){
a = 0; b = 1;
cout << a << " " <<b;
for(int i=1; i<= n-2; i++){
c = a + b;
cout << " " << c;
a = b;
b = c;
}}
int main(){
cout << "Hello world! Fibonacci series" << endl;
cout << "Enter number of items you need in the series: ";
int n; cin >> n;
Fibonacci fibonacci;
fibonacci.generate(n);
return 0;
}