Documente Academic
Documente Profesional
Documente Cultură
Computer ?
There are four main equipment functions of a computer system: Input, Processing, Storage and Output
Input the component through which a user instructs a computer about what to do Processor the engine that processes the instructions given by the user Memory where the processor stores information that is required during its computations Storage where information that is required to be used much later is stored Output the component that communicates the results of a computation to the user
Hardware/ Software
Hardware - the "machinery" - computer equipment - the CPU, the monitor, the keyboard, the mouse, the external speakers, the scanner, the printer, etc. The physical, touchable parts of a computer system. Software - the program instructions that make the computer do some task, such as word process, manage databases, play games, etc.
CIIT ATTOCK SADIA EJAZ
Hard Copy - a paper printout of the program code or data displayed on the screen. Soft Copy - copy of a program stored on a hard drive, diskette, or CD. Network - a hardware and software data communication system. Usually a group of computers that are linked to share memory and programs. Control Unit - the unit inside of the CPU which "directs the traffic" - makes decisions. It performs the functions of fetch, decode, execute, and store.
CIIT ATTOCK SADIA EJAZ
Data Structure
Computer data is in what is called binary format. This means that it is always a 0 or a 1. It only has these two states and must be in one of them. There are several fundamental data units which include: Bit - A data unit which must be in one of the two binary states described above. It is the smallest data unit that exists. Byte - 8 bits of data which has a possible value from 0 to 255. Word - Two bytes or 16 bits of data with a possible unsigned value from 0 to 16535. Long word = 8 bytes = 64 bits Quad word = 16 bytes = 128 bits
Bits, Bytes
Symbol KB MB GB TB
Number of Bytes 210 = 1024 220 (over 1 million) 230 (over 1 billion) 240 (over 1 trillion)
INPUT
The devices used to give the computer data or commands are called Input devices. Includes keyboard, mouse, scanner, etc
PROCESSOR
Central Processing Unit (CPU) The brain of the computer. This is the component that actually executes instructions Controls all other computer functions In PCs (personal computers) also called the microprocessor or simply processor.. The processor is the logic of a computer
CIIT ATTOCK SADIA EJAZ
Processor
It is the place where the actual execution of the instructions take place during the processing operation. The data and instructions, stored in the primary storage before processing, are transferred as and when needed to the ALU, where processing takes place. All ALU are designed to perform Four basic arithmetic operations
Logic operations or comparisons, such as less than, equal to, or greater than.
13
Control Unit
It acts as a central nervous system for the other components of the computer system. It manages and coordinates the entire computer system. It obtains instructions from the program stored in main memory, interprets the instructions, and issues signals, which cause other units of the system to execute them.
14
Storage Unit
15
Main memory holds information such as computer programs, numeric data, or documents created by a word processor. All programs must be brought into main memory before execution. When power is turned off, everything in main memory is lost Main memory is made up of capacitors. If a capacitor is charged, then its state is said to be 1, or ON. We could also say the bit is set. If a capacitor does not have a charge, then its state is said to be 0, or OFF. We could also say that the bit is reset or cleared
Memory is divided into cells, where each cell contains 8 bits (a 1 or a 0). Eight bits is called a byte. Each of these cells is uniquely numbered. The number associated with a cell is known as its address. Main memory is volatile storage. That is, if power is lost, the information in main memory is lost.
CIIT ATTOCK SADIA EJAZ
Provides permanent storage for information Retains information even when power is off Examples of secondary storage: Hard Disks (sequential access) Floppy Disks (sequential access) Tapes (sequential access) CD-ROMs (random access) DVDs (random access) Secondary storage media store files that contain computer programs data other types of information This type of storage is called persistent (permanent) storage because it is non-volatile.
CIIT ATTOCK SADIA EJAZ
Speed
Primary storage is much faster to access than secondary storage because of the proximity of the storage to the processor or because of the nature of the storage devices. On the other hand, secondary storage can hold much more data than primary storage.
Hard disk
Hard disk is a computer storage device which saves and retrieves the data when required. Its capacity is much greater than the computer memory (RAM, ROM). Data on hard disk is stored. Today we can save huge amount of data on a single hard disk. Now hard disks can contain several billion bytes.
CD
A compact disc [sometimes spelled disk] (CD) is a small, portable, round medium for electronically recording, storing, and playing back audio, video, text, and other information in digital form.
Floppy disk
A diskette is a random access, removable data storage medium that can be used with personal computers. The term usually refers to the magnetic medium housed in a rigid plastic cartridge measuring 3.5 inches square and about 2 millimeters thick. Also called a "3.5-inch diskette," it can store up to 1.44 megabytes (MB) of data.
DVD
DVD (digital versatile disc) is an optical disc technology that is expected to rapidly replace the CDROM disc (as well as the audio compact disc) over the next few years. The digital versatile disc (DVD) holds 4.7 gigabyte of information on one of its two sides, or enough for a 133-minute movie.
USB drive
Tape drive
Zip drive
OUTPUT
The devices to which the computer writes data are called Output devices. Often converts the data into a human readable form. Monitor and printer are output devices.
ROM
ROM is "built-in" computer memory containing data that normally can only be read, not written to. ROM contains the programming that allows your computer to be "booted up" or regenerated each time you turn it on. Unlike a computer's random access memory (RAM), the data in ROM is not lost when the computer power is turned off.
Types of ROM
PROM
PROM stands for Programmable read only memory In PROM chip , the user can write his own instructions but at once If there is any error in writing the instruction the error can not removed from the PROM The chip become unusable
Types of ROM
EPROM
Stands for erasable programmable read only memory User can erase a instruction if any any error occurred Stands for Electronically Erasable Programmable Read Only memory
EEPROM
EXAMPLE
Software Categories
System Software
The system software controls the computer. It communicates with computers hardware (key board, mouse, modem, sound card etc) and controls different aspects of operations. Sub categories of system software are:
Operating System
Operating system is the software responsible for controlling the allocation and usage of hardware resources such as memory, central processing unit (CPU) time, disk space, and peripheral devices. The operating system is the foundation on which applications, such as word processing and spreadsheet programs, are built. (Microsoft)
MS Sadia Ejaz CIIT ATTOCK
The device driver software is used to communicate between the devices and the computer.
Utility software is a program that performs a very specific task, usually related to managing system resources.
Application software
A program or group of programs designed for end users. For example a program for Accounting, Payroll, Inventory Control System, and guided system for planes.
A DBMS is a complex set of software programs that controls the organization, storage, management, and retrieval of data in a database. It is a set of prewritten programs that are used to store, update and retrieve a Database.
36
Computer Viruses
A computer virus is a program which reproduces itself. It may attach to other programs, it may create copies of itself (as in companion viruses). It may damage or corrupt data, change data, or degrade the performance of your system by utilizing resources such as memory or disk space.
37
Computer Network
38
What is programming
Definition: "A program is a precise sequence of steps to solve a particular problem. It means that when we say that we have a program, it actually mean that we know about a complete set activities to be performed in a particular order. The purpose of these activities is to solve a given problem.
Language?
Way of communication When we communicate one another then we need a specific language to express our words Example
Computer Programming
Computer programming is defined as telling a computer what to do through a special set of instructions which are then interpreted by the computer to perform some task(s). These instructions can be specified in one or more programming languages including (but not limited to) Java, PHP, C, and C++.
Programming Language
A set of words, symbols and codes used to write a programs is called program language. Different programming languages are available for writing different types of programs.
Low-Level Languages
These are near to computer hardware and far from human language. Two low-level languages.
Machine Language
In this language, instructions are written in binary from. It is directly understood by the computer. Programs written in this language are machinedependent. It is also known as first generation language.
Assembly Language
Symbolic Language It is mostly used for writing system software. Second generation language.
High-Level Language
Procedural Languages
Third generation languages In these languages, program is a predefined set of instructions. Popular procedural languages .
FORTRAN FORmula TRANslation BASIC Beginner All Purpose Symbolic Instruction Code COBOL Common Business Oriented Language PASCAL C Middle-level language Application Software as well as System Software
Programs are written on the basis of objects. Object Collection of data and functions Easier to learn and modify. C++ and Java
Objects Classes Real-world Modeling Reusability Information Hiding Encapsulation Polymorphism Multiple ways
C++
Object-Oriented Language Developed in 1980 at Bell Lab. Improved version of C language. Powerful language.
History of C++
The C language was developed in late 60s and early 70s, in Bell Laboratories. In those days BCPL and B languages were developed there. The BCPL language was developed in 1967 by Martin Richards as a language for writing operating systems software and compilers. In 1970 Ken Thompson used B language to create early versions of the UNIX operating system at Bell Laboratories. Dennis Ritchie developed a general purpose language, called C language, by using different features of BCPL and B languages. In the early 1980's, also at Bell Laboratories, another programming language was created which was based upon the C language. This new language was developed by Bjarne Stroustrup and was called C++
When he designed C++, he added OOP (Object Oriented Programming) features to C without significantly changing the C component. Thus C++ is a "relative" (called a superset) of C, meaning that any valid C program is also a valid C++ program.
Non-Procedural Languages
Fourth-generation language Need to tell computer what to do not how to do. It is used in database application and report generation. Important Non-procedural languages.
Translator is required.
No translator is required.
Programs in high-level languages Programs in low-level languages are slow in execution. are fast in execution.
Programs in high-level languages Programs in low-level languages are easy to modify. are difficult to modify.
Fifth generation language Very complex Most of these languages are in experimental phase.
Types of Codes
Source Code
Object Code
Computer can not understand source code but directly understands object code.
Object Code
Object code is written in machine language through compilers. Object code is difficult to understand. Object code is difficult to modify. Object code contains more statements than source code.
Language Processor
Compiler
Source Program
Compiler
Object Program
Interpreter
Assembler
Assembler
Object Program
Interpreter
Compiler will stop translating if Interpreter will execute all the it finds an error and there will be lines before error and will stop at no executable code generated. the line which contains the error. Compiler compile the program as It converts one statement of a whole. program at one time.
Compiler generate object file. Interpreter generates no object file.
Programming Techniques
Structured Programming
A program is divided in small units called modules or sub-programs. Sequential Structure Control flows in logical sequence. Conditional/ Selective structure Selection on basis of condition
Iterative / Repetitive Structure Loops Function Call Control moves to block of code
Advantages
Disadvantage
Object-Oriented Programming
C ++ Java
Event-Driven Programming
Statements are executed in response to an event. For Example: Clicking the mouse button.
Visual Programming
Features of C++
It is very convenient language. It is a well-structured language. It is case sensitive language. It provides machine independent. It is an object oriented language. In C++. A program can be divided into small modules.
The format of writing program in C++is known as its structure. It consists of following parts.
Pre-processor Directive
It is an instruction given to the compiler before the execution of actual program. Include preprocessor directive is used in C++ to include header files in the program. # include <iostream.h>
Preprocessor Directive
Header files
Header Files
It is a collection of standard library functions to perform different tasks. There are many header files for different purposes. It must be included in the program before calling any of its function.
Main ( ) Function
It is the starting point of a C++ program. C++ statements are written in the body of the main () function. void main( ) { Body of the main function }
C++ Statements
C++ Statement
Using cout
Purpose of C++
Stroustrup states that the purpose of C++ is to make writing good programs easier and more pleasant for the individual
There are several versions of the C++ language, of which Visual C++ is only one. Other dialects include Borland C++, Turbo C++, and Code Warrior (Mac).
LAB WORK
The Internet
It is a huge network of computers, which links many different types of computers all over the world. It is a network of networks, which share a common mechanism for addressing (identifying) computers, and a common set of communication protocols for communication between two computers on the network.
86
The World Wide Web Electronic mail News File Transfer Protocol Chat Instant Messaging Online- Services Peer-to-Peer Services
87
The World Wide Web (commonly shortened to the Web) is a system of interlinked hypertext documents accessed via the Internet. With a Web browser, a user views Web pages that may contain text, images, videos, and other multimedia and navigates between them using hyperlinks.
88
A Web search engine is a search engine designed to search for information on the World Wide Web.
A search engine lets you search for information by typing one or more words. The engine then displays a list of Web pages that contain information related to your words. Example: Google search engine
89
E - Mail
Electronic mail, often abbreviated to e-mail, is a storeand-forward method of writing, sending, receiving and saving messages over electronic communication systems.
90
Machine languages: first generation Assembly languages: second generation Higher-level languages: third generation (3GLs)
FORTRAN (FORmula TRANslator) COBOL (COmmon Business Oriented Language) BASIC (Beginners All-Purpose Symbolic Instruction Code) Pascal
Builds programs with a front end, which is an interface that hides much of the program from the user Provides prototypes, which are samples of the finished programs
HyperText Markup Language (HTML) Extensible Markup Language (XML) Wireless Markup Language (WML) Dreamweaver Flash Director
Phase 1: Needs analysis Phase 2: Program design Phase 3: Development (also called coding) Phase 4: Implementation Phase 5: Maintenance
Why We Do Programming ?
Computers are used as a tool to solve complex problems by developing computer programs that provide the solution of the problems. Example:
Program : For adding 2 numbers, i.e 3 and 5 Solution: A computer program will be developed for their addition.
Problem-Solving Techniques
Program
A set of instructions that tells a computer what to do is called program. Computer programs are written in programming languages. A person who develops a program is called programmer.
Algorithms
The given problem should be broken down into simple and meaningful steps. The steps should be numbered sequentially. The steps should be descriptive and written in simple English.
Algorithms are written in a language, which is similar to simple English , which is known as pseudo language. The purpose of using pseudo code is that it may be easier for humans to read than conventional programming languages. No standard for pseudo code syntax exists, as a program in pseudo code is not an executable program.
MS Sadia Ejaz CIIT ATTOCK
Logic Design
Logic of the program is designed by specifying different steps required and the sequence of these steps to solve the problem.
Coding
Example
3.
4.
Advantages of Algorithms
Flowchart
It is combination of two words i.e. flow and chart. Flowchart is a graphical representation of an algorithm.
Chart consists of different symbols to display information about any program. Flow indicates the direction of processing that takes place in the program.
Flowchart (contd.)
It is used to represent an algorithm in simple graphical manner. It is used to show the steps of an algorithm in an easy way. It is used to understand the flow of the program. It is used to improve the logic for solving a problem. Programs can be reviewed and debugged easily.
Input/Output Parallelogram symbol is used to represent an input or output step. Input statement is used to get input from the user. The output statement is used to display a message to the use or to display a value.
Input Output
Start/End Oval symbol is used to represent the start or end of the flowchart.
Start
End
Connector Indicates that the flow continues where a matching symbol (containing the same letter) has been placed.
Flow Line Lines indicate the sequence of steps and the direction of flow.
Example
Start
Input A, B
Sum = A+B
Display Sum
End
Defining and Analyzing the Problem. Designing the Algorithm Coding or Writing the Program Test Execution Debugging Final Documentation
Editor
Preprocessor Compiler
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
Linker
Primary Memory
Loader
Disk
Primary Memory
CPU
. . . . . .
CPU takes each instruction and executes it, possibly storing new data values as the program executes.
Editor
First of all we need a tool for writing the code of a program. For this purpose we used Editors in which we write our code.
Debugger
Linker
Most of the time our program is using different routines and functions that are located in different files, hence it needs the executable code of those routines/functions. Linker is a tool which performs this job, it checks our program and includes all those routines or functions which we are using in our program to make a standalone executable code and this process is called Linking.
Loader
Another process which is needed to load the program into memory and then instruct the processor to start the execution of the program from the first instruction (the starting point of every C program is from the main function). This processor is known as loader. Linker and loaders are the part of development environment. These are part of system software.
An error in a computer program is known as bug. The process of finding and removing bugs is known as debugging.
Types of Errors
Syntax Errors
Logical Errors
Run-Time Errors
C++ Statement
The statement of the program are writen under the main() function between the curely bracket{}. These statement are the body of program Each statement of the c++ ends with a semicolon(;) C++ is a case sensitive language The c++ statement are normally written in lowercase letters but in some exceptional but in some exceptional cases, these can also be written in upper case
keyword
The words that are used by the language for special purpose are called keywords e.g. in c++ program, the word main is used to indicate the starting of program, include is used to header files, int to declare an integer data type All these words are keyword of c++ The keyword cannot be used as variable names in program
MS Sadia Ejaz CIIT ATTOCK
Identifiers
The identifiers are the names used to represent variable, constants, types, functions and labels in the program. An identifier in C++ may consist of 31 characters.
Types of Identifiers
Standard Identifiers
A type of identifier that has special meaning in C++ is known standard identifier. For example. cout, cin, etc.
The type of identifier that is defined by the programmer to access memory location is known as user-defined identifier. For example, marks, age, etc.
MS Sadia Ejaz CIIT ATTOCK
User-defined Identifiers
Keywords
Keyword is a word in C++ language that has a predefined meaning and purpose. They are also known as reserved words. The total number of keywords is 63. For example, int, class, etc.
Data Types
The data type defines a set of values and a set of operations on these values. A C++ program may need to process different types of data.
Data Types
Data Type
int float double char
Purpose
to store numeric values to store real values to store large real values to store character values
char data type is used to store character value. It takes 1 byte in memory. The characters are stored in ASCII code form. ASCII American Standard Code for Information Interchange.
Integer Overflow
It occurs when the value assigned to an integer variable is more than maximum possible value. It occurs when the value assigned to an integer variable is less than possible minimum value.
Integer Underflow
Variables
A variable is a named memory location or memory cell. The value stored in a variable is referred by variable name.
Variables Declaration
The process of specifying the variable name and its type is called variable declaration. Syntax
Variable may include letter, numbers and underscore (_). The first character of variable must be a letter or underscore _. The use of underscore is not recommended. The variables 9minute, #home and 2kg are invalid. Blank spaces are not allowed in variable names. The variables my var and your car are invalid.
Both upper and lower cases are allowed. A userdefined variable is conventionally written in lower case. The constants are conventionally written in upper case. Special symbols cannot be used as variable name. Reserved word cannot be used as variable name. The names int, void and while are invalid variables.
MS Sadia Ejaz CIIT ATTOCK
A variable can be up to 31 characters long for many compiler. If a variable consists of more than 31 characters, only first 31 characters will be used. The remaining characters will be ignored. A variable can be declared only for one data type.
Variable Initialization
The process of assigning a value to a variable at the time of declaration is known as variable initialization. Syntax
variable _name n =
= 100
value ; ;
Tokens
A program statement consist of variable names, keywords, constant, operator etc, these elements of statement are called tokens int main(){ e.g.
int x,y; x = 5;
Example
simple program #include< stdio.h > #include< iostream.h > int main(){ int x; x = 5; cout << x; return 0; }