Pages - Menu

Monday, November 26, 2012

C++

First C++ Program
//File: welcome.cpp

//A program to print a welcoming message

#include <iostream>

using namespace std;

int main()

{

    cout << “Welcome to C++” << endl;

    return 0;

} //main


Note the following:
The include file is iostream
Therefore no .h in the header
The use of using namespace std will be discussed later
The main() function has a return value
The use of cout for outputting to the monitor
The use of endl for new line.



// File: welcome.cpp
// A program to print a welcoming message
  Comments provide information to the people who read
     the program.
•  Comments are removed by the preprocessor,
     therefore the compiler ignores them.

•  In C++ there are two types of comments
 *Line comments
 *Delimited comments

More on Comments
•Line comments begin with // and continue for the rest of the line.
Delimited comments begin with /* and end with */

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>

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.


count<<Welcome to C++
<< endl;
Produces output:
Welcome to C++
-
cout   is an object which displays whatever is   sent to it on the screen.
<<   is the insertion operator used to send   information to cout



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 literal, operator,
or identifier.
















programming languages

Introduction

What is a Computer?
Up until the late 1940’s, 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 humans

Programming in machine language is very tedious and prone to errors

Ex

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:
ADD X, Y, Reg1
ADD Reg1, Z, Reg2
STORE Reg2 SUM

High Level Programming Language
Uses syntax resembling combination of 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.

High Level Programming Languages
Pascal  RESULT := X + Y+ Z;

FORTRAN  RESULT = X + Y + Z

COBOL  COMPUTE RESULT = X + Y + Z.

C  RESULT = X + Y + Z;

C++  RESULT = X + Y + Z;

Ada  RESULT := X + Y + Z;

PL/1  RESULT = X + Y + Z;


Programming Language Translation
Assemblers
Interpreters
Compilers


•Assemblers
–Translate statement from assembly language to machine language
–Generally use table look-up techniques

•Interpreters
–Translate and execute each high-level statement, one at a time




Translate the entire high level language program, called the source code, to machine language and store the
  result.

Machine language code produced by compilers is called object code


Programming Paradigms 
Object-Oriented Paradigm


System Software
Operating System
  –Memory and resource management
  –Job scheduling
  –Security

Command Line vs. Graphical User Interface
  –Note: the vi editor

Problem Solving and Software Development

Development and Design

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

•User’s manual

•Test plan

•Design document



•Maintenance

–Correcting new problems

–Adding new features

–Modifications due to change in requirements

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 algorithm must terminate

Expressions of Algorithms are
Pseudocode
Flowcharts

Example of Algorithm 
Write an algorithm that will determine the largest value of four values.  

A flowchart solution
INPUT first value, STORE value in Largest.

Loop to determine if any other numbers are larger.
 DISPLAY Largest

A pseudocode solution
INPUT first value, STORE value in Largest

Repeat three times

INPUT next value, store in Number

IF Number >Largest,

STORE Number in Largest

DISPLAY largest

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 and over again.

Invocation

Execute a complex task, which is written separately





































Sunday, November 25, 2012

COMPUTER FUNDAMENTALS


pComponents of the Computer

pDifferent usages of the computers

pVon Neumann  Architecture

pData and information

pHow to store the data in a computer

pBasic Data Types

pNumber Representation

pFloating Point Representation

pData Representation in Computers
   
  Binary Code Transmission



Objectives



pDifferentiate between data and Information 
pIdentify the basic functions of the computer
pData representation inside computers




Components of the Computer
1. Monitor
2. Motherboard
3.CPU (Microprocessor)
4.Primary storage (RAM)
5.Expansion cards
6.Power supply
7.Optical disc drive
8.Secondary storage (Hard disk)
9.Keyboard
10.Mouse

A Modern Computer System



Von Neumann Architecture


pAll computers share the same basic architecture, whether it be a multi-million dollar mainframe or a Palm Pilot.

pAll have memory, an I/O system, and arithmetic/logic unit, and a control unit.

ain components of theVon 
   Neumann architecture



   (1) CPU – Central Processing Unit
       arithmetic-logic unit (ALU)
        performs the computer's computational                  and  logical functions
   (2) control unit
      directs other components of the     computer to   perform certain actions
   (3) input and output devices
       main-machine interfaces; i.e.,
    (2) memory
    the computer's main, or fast, memory, such as   random access memory (RAM)

Data and Information

pWhat is Data ?
pData is a collection of facts
§Numbers
§Words
§Measurements
§Observations
§Description of things


pWhat is Information?
processed outcome of data. (it is derived from data)


How do we store data in a computer?
pComputer is a digital device which is capable to handle discrete data/information
pTherefore, we need to convert these analog signals to digital signals after capturing them by the input devices
pThis is done with the converter – Analogue to Digital Convertor (ADC)
pDigital signals are represented by numbers (Binary Digits) and need to be stored in the main memory
p8 Bits = 1 Byte
p1024 Bytes = 1KB
p1024 KB = 1 MB
p1024 MB = 1 GB
p1024 GB = 1 TB

The memory is made up of BYTES
Each BYTE can be addressed uniquely
When the address is expressed in Binary, 
     the number of   maximum BITs used to    write 
     the address specifies the total number of 
     locations available
f n number of BITs are available then the total number of locations available is 2n
If we have 32 BITs then we can have 4GB of Memory (232 = 4 GB)

Programmers point of view
pProgrammers need to use  data in their programs

pThe architecture says, it is required to store them in the main memory before use

pTherefore, it is required to find a way to put them in memory

pAs there may have differences in the data He sets his requirement through what we call a DATA TYPE
pThrough a data type, architecture tells the computer that data must be stored in a particulaway in the main memory

pFor that, the data must have a representation 


Basic Data Types: Character Data

pNumeric
n0 1 2 … 9

pAlphabetic
na b c …… z

pSpecial
n# @ % ( $ & 
Basic Data Types: Numeric data
pInteger
n+ & - whole numbers
n      4251  -582

pReal
nAll numbers including everything between integers
n 0.23, 0, 5½-2.3,


pFixed Point Representation
n12.548
pFloating Point Representation
nScientific Notation
p12.054 à 1.2054 * 101
nComputer Notation
p12.65 à  0.1265*102

Parity: Odd & Even Parity
pComputers can sometimes make errors when they
transmit data.

pEven/odd parity:
nis basic method for detecting if an odd number of bits has been switched by accident.

pOdd parity:
nThe number of 1-bit must add up to an odd number
pEven parity:
The number of 1-bit must add up to an even number

Parity: Odd & Even Parity(Contd.)
pIt is useful when an odd number of 1-bits is flipped.

pSuppose we have an 7-bit binary word (7-digits).
nIf you need to change the parity you need to add 1 (parity bit)  to the binary word

nYou now have 8 digit word.
nHowever, the computer knows that the added  bit is a parity bit and therefore ignore it. 
Parity Checking
pAssume we are using even parity with 7-bit ASCII.
pThe letter V in 7-bit ASCII is encoded as 0110101.
pHow will the letter V be transmitted?
nBecause there are four 1s (an even number), parity is set to zero.
nThis would be transmitted as: 01101010.

pIf we are using an odd parity:
The letter V will be transmitted as 01101011