Вы находитесь на странице: 1из 56

Computer basics

INTRODUCTION

Computers have made great inroads in our everyday life and thinking. They are put to use for all sorts of applications ranging from complex calculations in the field or frontline research, engineering simulations down to teaching, printing books and recreational games. The ease with which computers can process data, store and retrieve it painlessly has made them inevitable in office and business environments. The areas of applications of computers are confined only by limitations on human creativity and imagination. In fact, any task that can be carried out systematically can be performed by a computer. Therefore, it is essential for every educated person today to know about a computer, its strength, its weaknesses and its internal structure.

COMPUTER:

A COMPUTER is an electronic device that can perform a variety of operations in accordance with a set of instructions called program. It can access and process data millions of time faster than humans can. A computer can store data and information in its memory, process them and produce the desired result.

DATA vs INFORMATION:

DATA in computer terminology mean raw facts and figures. Ex: roll no, class

INFORMATION means what we get after processing data.

BLOCK DIAGRAM OF A PC:

INPUT UNIT: an Input unit takes the input and converts into binary form, so that it can be understandable by the computer. It consists of data and instructions.

OUTPUT UNIT: The basic function of output unit is to produce output. It converts binary form into human understandable form.

CPU: CPU is a control centre of the computer or called as a brain of the computer. CPU has 2 components responsible for its various functions:

1 CU: A Control unit gets program instructions from memory and executes them one after another. After getting instructions from memory it decodes and interprets and then asks for the operations to be carried out. It also controls the flow of data from input devices to memory and memory to output devices.

2 ALU performs all the arithmetic functions and it stands for arithmetic logic unit.

3 MEMORY UNIT: Memory of the computer is often called as main memory or primary memory. Its basic function is to store data and instruction that operate on them. It also consists of RAM and ROM.

1 KB 1024 BYTES 1 MB 1024 KB 1 GB- 1024 MB

CHARACTERSTICS OF COMPUTERS:

1 SPEED- Computer has very high speed. It can process million of instructions. Speed is measured in nano second into peco seconds.

2 ACCURACY- Accuracy of computer is extremely high.

3 UNTIRING- It is free from monotony, tiredness and lack of concentration.

4 VERSATILE- It can be used in various fields like education, animation, military, medicine etc.

5 STORAGE- It can store vast amount of data according to storage capability of computer.

6 DECISION CAPABILITY- They are unable to take decision.

7 HUMAN DEPENDENT- They are human dependent machines, they cant perform any instruction by itself.

INPUT DEVICES:

(1) KEYBOARD: In computing, a keyboard is an input device, partially modelled after the typewriter keyboard, which uses an arrangement of buttons or keys, to act as mechanical levers or electronic switches. A keyboard typically has characters engraved or printed on the keys and each press of a key typically corresponds to a single written symbol. However, to produce some symbols requires pressing and holding several keys simultaneously or in sequence. While most keyboard keys produce letters, numbers or signs (characters), other keys or simultaneous key presses can produce actions or computer commands.

(2) MOUSE: In computing, a mouse is a pointing device that functions by detecting two-dimensional motion relative to its supporting surface. Physically, a mouse consists of an object held under one of the user's hands, with one or more buttons. It sometimes features other elements, such as "wheels", which allow the user to perform various system-dependent operations, or extra buttons or features can add more control or dimensional input. The mouses pointer, which allows for fine control of a Graphical User Interface.

(3) TRACK BALL: It is a pointing device that contains ball which can rotate in any direction it works like upside down mouse.

(4) TRACK PAD: A track pad is a pointing device consisting of specialized surface that can translate the motion and position of a user's fingers to a relative position on screen. They are a common feature of laptop computers and also used as a substitute for a computer mouse where desk space is scarce. Touchpad vary in size but are rarely made larger than 40 square centimetres (about 6 square inches)

(5) JOYSTICKS: A joystick is an input device consisting of a stick that pivots on a base and reports its angle or direction to the device it is controlling. Joysticks are often used to control video games, and usually have one or more push-buttons whose state can also be read by the computer. A popular variation of the joystick used on modern video game consoles is the analogue stick.

(6) LIGHT PENS: A light pen is a computer input device in the form of a light-sensitive wand used in conjunction with a computer's CRT TV set or monitor. It allows the user to point to displayed objects, or draw on the screen, in a similar way to a touch screen but with greater positional accuracy. A light pen can work with any CRT-based display, but not with LCD screens, projectors and other display devices.

(7) TOUCH SCREEN: A touch screen is a display that can detect the presence and location of a touch within the display area. The term generally refers to touch or contact to the display of the device by a finger or hand. Touch screens can also sense other passive objects, such as a stylus. However, if the object sensed is active, as with a light pen, the term touch screen is generally not applicable. The ability to interact directly with a display typically indicates the presence of a touch screen.

(8) MAGNETIC INK CHARACTER READER: Magnetic Ink Character Recognition, or MICR, is a character recognition technology used primarily by the banking industry to facilitate the processing of cheques. The technology allows computers to read information (such as account numbers) off of printed documents. Unlike barcodes or similar technologies, however, MICR codes can be easily read by humans.

(9) OPTICAL CHARACTER READER: Optical character recognition, usually abbreviated to OCR, is the mechanical or electronic translation of images of handwritten, typewritten or printed text (usually captured by a scanner) into machine-editable text. It is used to convert paper books and documents into electronic files, for instance, to computerize an old record-keeping system in an office

OUTPUT DEVICES:

PRINTERS- A most convenient and useful method by which the computer can deliver information is by means of printed characters. Printers can be divided into two distinct categories:

(1) IMPACT PRINTERS- In these printers there is mechanical contact between the print head and paper.

(a) DOT MATRIX PRINTER: Dot matrix printers can either be character-based or line-based, referring to the configuration of the print head. At one time, dot matrix printers were one of the more common types of printers used for general use such as for home and small office use. Such printers would have either 9 or 24 pins on the print head. 24-pin print heads were able to print at a higher quality. Once the price of inkjet printers dropped to the point where they were competitive with dot matrix printers, dot matrix printers began to fall out of favour for general use.

(b) LINE PRINTERS: Line printers, as the name implies, print an entire line of text at a time. Three principal designs existed. In drum printers, a drum carries the entire character set of the printer repeated in each column that is to be printed. In chain printers (also known as train printers), the character set is arranged multiple times around a chain that travels horizontally past the print line. In either case, to print a line, precisely timed hammers strike against the back of the paper at the exact moment that the correct character to be printed is passing in front of the paper. The paper presses forward against a ribbon which then presses against the character form and the impression of the character form is printed onto the paper.

(c) DAISY WHEEL PRINTER: Daisy-wheel printers operate in much the same fashion as a typewriter. A hammer strikes a wheel with petals (the daisy wheel), each petal containing a letter form at its tip. The letter form strikes a ribbon of ink, depositing the ink on the page and thus printing a character. By rotating the daisy wheel, different characters are selected for printing.

(2) NON-IMPACT PRINTERS- In these printers, there is no mechanical contact between the print head and papers.

(a) INK JET- Inkjet printers operate by propelling variably-sized droplets of liquid or molten material (ink) onto almost any sized page. They are the most common type of computer printer for the general consumer due to their low cost, high quality of output, capability of printing in different colours, and ease of use.

(b) LASER- A laser printer is a common type of computer printer that rapidly produces high quality text and graphics on plain paper. As with digital photocopiers and multifunction printers (MFPs), laser printers employ a

xerographic printing process but differ from analogue photocopiers in that the image is produced by the direct scanning of a laser beam across the printer's photoreceptor. (c) THERMAL- A thermal printer (or direct thermal printer) produces a printed image by selectively heating coated thermo chromic paper, or thermal paper as it is commonly known, when the paper passes over the thermal print head. The coating turns black in the areas where it is heated, producing an image. Two-colour direct thermal printers are capable of printing both black and an additional colour (often red), by applying heat at two different temperatures.

PLOTTERS: A plotter is a vector graphics printing device to print graphical plots, that connects to a computer. There are two types of main plotters. Those are pen plotters and electrostatic plotters. These are slow in speed.

MONITORS: A monitor or display is a piece of electrical equipment which displays images generated by devices such as computers, without producing a permanent record. The monitor comprises the display device, circuitry, and an enclosure. The display device in modern monitors is typically a thin film transistor liquid crystal display (TFT-LCD), while older monitors use a cathode ray tube (CRT).

MAIN MEMORY (PRIMARY MEMORY)

~ RAM (Random access memory) ~ROM (Read only memory)

RAM-Random-access memory (usually known by its acronym, RAM) is a form of computer data storage.
Today, it takes the form of integrated circuits that allow stored data to be accessed in any order (i.e., at random). The word random thus refers to the fact that any piece of data can be returned in a constant time, regardless of its physical location and whether or not it is related to the previous piece of data. [1]

By contrast, storage devices such as magnetic discs and optical discs rely on the physical movement of the recording medium or a reading head. In these devices, the movement takes longer than data transfer, and the retrieval time varies based on the physical location of the next item.

The word RAM is often associated with volatile types of memory (such as DRAM memory modules), where the information is lost after the power is switched off. Many other types of memory are RAM, too, including most types of ROM and a type of flash memory called NOR-Flash.

ROM- Read-only memory (usually known by its acronym, ROM) is a class of storage media used in
computers and other electronic devices. Because data stored in ROM cannot be modified (at least not very quickly or easily), it is mainly used to distribute firmware (software that is very closely tied to specific hardware, and unlikely to require frequent updates) Programmable read-only memory (PROM), or one-time programmable ROM, can be written to or programmed via a special device called a PROM programmer. Typically, this device uses high voltages to permanently destroy or create internal links within the chip. Consequently, a PROM can only be programmed once. Erasable programmable read-only memory (EPROM) can be erased by exposure to strong ultraviolet light, and then rewritten with a process that again requires application of higher than usual voltage. Repeated exposure to UV light will eventually wear out an EPROM, but the endurance of most EPROM chips exceeds 1000 cycles of erasing and reprogramming. After programming, the window is typically covered with a label to prevent accidental erasure. Some EPROM chips are factory-erased before they are packaged, and include no window; these are effectively PROM.

Electrically erasable programmable read-only memory (EEPROM) is based on a similar semiconductor structure to EPROM, but allows its entire contents to be electrically erased, and then rewritten electrically, so that they need not be removed from the computer.

CACHE MEMORY- A CPU cache is a cache used by the central processing unit of a computer to
reduce the average time to access memory. The cache is a smaller, faster memory which stores copies of the data from the most frequently used main memory locations. As long as most memory accesses are cached memory locations, the average latency of memory accesses will be closer to the cache latency than to the latency of main memory.

BASIC APPLICATIONS OF COMPUTERS: ~ BUISNESS ~ MEDICINE AND HEALTH CARE ~ COMMUNICATIONS ~ EDUCATION AND REFERENCE ~ SCIENCE, RESEARCH AND ENGINEERING ~ MANUFACTURING ~ COMPUTERS IN SPORTS ~ GOVERNMENT ~ MILITARY ~ COMPUTERS AT HOME ~ THEATRE FILM AND TELEVISION AND MUSIC

WINDOWS

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an addon to MS-DOS in response to the growing interest in graphical user interfaces (GUIs). Microsoft Windows came to dominate the world's personal computer market, overtaking Mac OS, which had been introduced previously. As of October 2009, Windows had approximately 91% of the market share of the client operating systems for usage on the Internet. The most recent client version of Windows is Windows 7; the most recent server version is Windows Server 2008 R2.

WINDOWS FEATURES:

- Choose between blinking and non-blinking cursors. A Crosshair option to visually assist with text alignment is also available.

- Clipboard Support for the common copy, cut and paste functions. It also provides an APPEND function where data can be appended to data already in the clipboard. A PRINT function allows the clipboard data to be sent to the Windows printer

- Cursor customization including underline, block and vertical bar. A different shape can be displayed when in insert mode.

- Dynamic Data Exchange Support to allow other Windows applications to send data to the 3270 session and receive data from the 3270 session.

- Enhanced Key Functions such as Delete Word, Error Correcting Backspace, Tab to Next Word, Tab to Previous Word

- Entry Assist provides functions that make it easier to enter and edit text material. It includes margins, tabs and an audible end of line signal. Each of these functions acts just like the corresponding functions on a typewriter. Entry Assist includes a word wrap facility, which allows you to type without having to use the New Line key. Word Wrap automatically does a New Line function for you when you need a new line. Word wrap picks up any partially typed word and places it on the next line.

- Extended Mouse support including cursor select function.

- Null to Blank Processing support translates all null characters to blanks before the screen data is sent to the host.

- Record and playback keystrokes. Repetitive typing tasks can now be automated.

OPENING FILES AND FOLDERS:


(1) On the desktop, double-click my computer. My computer window opens.

(2) Double click the drive that contains the file or folder you want to open

(3) Double click the file or folder

SHUTTING DOWN THE COMPUTER:

(1) Click the start button, and then click shut down windows dialog box

(2) Click at shut down radio button and click ok.(to restart your computer, click at restart radio button and click ok).

MS WORD

INTRODUCTION:Let us consider an office scene. Many letters are typed in the office. The officer dictates a letter. The typist first types a draft copy of the letter. The officer goes through it to check mistakes regarding spelling errors, missing words, etc. and suggests corrections. The typist changes the letter as suggested by the officer. This is a simple example of word processing.

There are many software packages to do the job of word processing. Some of them work in DOS environment. Examples are WordStar, Word Perfect and Professional Write. But in these days working in WINDOWS is becoming more and more popular. So let us consider software for word processing which works in WINDOWS. Our choice is MS-WORD because it is the most popular software in these days.

WHAT IS WORD-PROCESSING?

Word Processor is a Software package that enables you to create, edit, print and save documents for future retrieval and reference. Creating a document involves typing by using a keyboard and saving it. Editing a document involves correcting the spelling mistakes, if any, deleting or moving words sentences or paragraphs.

Advantages of Word Processing:-

One of the main advantages of a word processor over a conventional typewriter is that a word processor enables you to make changes to a document without retyping the entire document.

FEATURES OF MS-WORD:-

Ms-Word not only supports word processing features but also DTP features. Some of the important features of Ms-Word are listed below:

(1)Using word you can create the document and edit them later, as and when required, by adding more text, modifying the existing text, deleting/moving some part of it. ii. iii. iv. Changing the size of the margins can reformat complete document or part of text. Font size and type of fonts can also be changed. Page numbers and Header and Footer can be included. Spelling can be checked and correction can be made automatically in the entire document. Word count and other statistics can be generated. Text can be formatted in columnar style as we see in the newspaper. Text boxes can be made. Tables can be made and included in the text. Word also allows the user to mix the graphical pictures with the text. Graphical pictures can either be created in word itself or can be imported from outside like from Clip Art Gallery. Word also provides the mail-merge facility. Word also has the facility of macros. Macros can be either attached to some function/special keys or to a tool bar or to a menu. It also provides online help of any option.

v. vi. vii.

viii. ix.

x.

You can go inside MS-WORD by the following way

1. Take the mouse pointer to START button on the task bar. Click the left mouse button. The monitor will show like as follows:

2 Move the pointer to programs. You will notice another menu coming up to the right.

3 In that menu identify where Microsoft word is placed. Move the cursor horizontally to come out of programs.

4 Move into the rectangular area meant for Microsoft word. Click the left mouse button there. The computer will start ms word. You will find the screen as follows.

Let us discuss the important components of the screen. a. Title Bar The title bar displays the name of the currently active word document. Like other WINDOWS applications, it can be used to alter the size and location of the word window. b. Tool Bars

Word has a number of tool bars that help you perform task faster and with great ease. Two of the most commonly tool bars are the formatting tool bar and the standard tool bar. These two toolbars are displayed just below the title bar. At any point of time any tool bar can be made ON or OFF through the tool bar option of View Menu.

(c) Ruler Bar

The Ruler Bar allows you to format the vertical alignment of text in a document.

(d) Status Bar The Status Bar displays information about the currently active document. This includes the page number that you are working, the column and line number of the cursor position and so on.

(e) Scroll Bar

The Scroll Bar helps you scroll the content or body of document. You can do so by moving the elevator button along the scroll bar, or by click in on the buttons with the arrow marked on them to move up and down and left and right of a page.

(f) Workspace The Workspace is the area in the document window was you enter/type the text of your document.

(g) Main Menu The Word main menu is displayed at the top of the screen as shown in the Fig. 9.1. The main menu further displays a sub menu. Some of the options are highlighted options and some of them appear as faded options. At any time, only highlighted options can be executed, faded options are not applicable. Infect if the option is faded you will not be able to choose it. You may not that any option faded under present situation may become highlighted under different situations.

SPELL CHECK
Spelling checking and correction are very useful features of word processors. These features help the user in a big way to produce error free documents. Spell checking is done with the help of internally available dictionaries.

CHECK SPELLING, GRAMMER AND READABILITY ALL AT ONCE: (1) On the tools menu, click options, and then click the spelling and grammar tab. (2) Select the check grammar with spelling and show readability statistics check boxes. (3) Click ok. (4) Click spelling (5) When word finds a possible spelling error, you can make your changes in the spelling and grammar dialog box. You can also edit the error directly in the document.

MAIL MERGE:-

Mail merge is a software function describing the production of multiple (and potentially large numbers of) documents from a single template form and a structured source. This helps to create personalized letters and preaddressed envelopes or mailing labels for mass mailings from a word processing document which contains fixed text, which will be the same in each output document, and variables, which act as placeholders that are replaced by text from the data source. The data source is typically a spreadsheet or a database which has a field or column matching each variable in the template. When the mail merge is run, the word processing system creates an output document for each row in the database, using the fixed text exactly as it appears in the template, but substituting the data variables in the template with the values from the matching columns. This technique of merging data to create mail shots gave rise to the term mail merge.

Step 1: Set Up the Mail Merge Main Document

To create a mail merge to produce several different letters to different people based on a particular set of criteria, you must first create and save the separate letters that contain the merge fields you want to use.

1. On the Tools menu, click Mail Merge. 2. In the Main document section of the Mail Merge Helper dialog box, click Create, and then click Form
Letters. In the next dialog box that appears, click Active Window.

3. To use an existing data source, click Get Data, and then click Open Data Source. In the Open Data
Source dialog box, find your data source, and then click Open.

4. In the message box that appears, click Edit Main Document.


5. Create the first letter. Enter the appropriate merge fields. NOTE: You must know the path to this file; for example, if Letter1 is in the My Documents folder on the C drive, the path is C:\My Documents\Letter1.doc. You will need to enter this information in the main document created later. Change this letter as appropriate for the second letter. Enter merge fields as appropriate and save the file under a different name, such as Letter2.doc. Repeat steps 6 and 7 for each letter that you want to create. When you name the files, use distinct file names, such as "Letter2," "Letter3," and so on.

6. On the File menu, click Save As, and then name the file. For example, type Letter1. Click Save.

7. 8.

Step 2: Modify the Data Source

Once you create all of the letters as separate files, you need to modify your data source to include a field that will be helpful in identifying which letter you will create for a particular record. To do this, follow these steps:

1. With the last mail merge letter that you created in the "Setting Up the Mail Merge Main Document"
section earlier in this article, click Select All on the Edit menu, and then press DELETE to delete everything from the document. 2. On the File menu, click Save As, give it a different file name, such as Main.doc, and then click Save. This document will become the mail merge main document that you will perform the merge from.

3. On the Tools menu, click Mail Merge. Under Data Source, click Edit, and then click the name of the
data file. The Data Form dialog box appears. Click View Source to view the data source in a table format. To create a new field, click the Manage Fields button on the Mail Merge toolbar. In the Field name box, type a field name (for example, type Code), click Add, and then click OK. Enter a code for each of the records to identify which letter will be used during the merge for that particular record. For example, if you created three letters, for each record in your data source, enter a 1, 2, or 3 in the Code field. Code 1 represents Letter1; Code 2 represents Letter2; Code 3 represents Letter3, and so on. 8. Save the data file, and then click the Mail Merge Main Document button on the Mail Merge toolbar to return to the main document.

4. 5. 6. 7.

Step 3: Modify the Main Document

You need to modify the blank main document (Main.doc) to include IF fields that identify which Include Text letter will be merged for each particular record. 1. At the top of the blank document, follow these steps to enter an IF field into the document:

a. Click the Insert Word Field button on the Mail Merge Toolbar.

b. Click If... Then... Else.... c. In the Field Name list, select the field that you created in the data source in the "Step 2:
Modifying the Data Source" section earlier in this article (Code in the example in this article).

d. In the Comparison list, click Equal to. e. In the Compare To box, type a value that you used in the newly created field (Code), such as
1, 2, or 3.

f. Click OK. NOTE: If you do not see the field code instructions in the document, press
ALT+F9 on the keyboard to turn on the field code view.

Step 4: Merge the Documents

With the Main document open, click Mail Merge on the Tools menu, and then click Merge. Choose to merge to a New Document, and then verify that the correct letter is used for the appropriate records in your data source.

When you perform the mail merge, Word produces the letter based on the code the data file has for a particular record. For example, if Record 1 has a Code value of 1, Word produces Letter1. If record 2 has a Code value of 3, Word uses Letter3.

PROGRAMMING LANGUAGE (C++)


INTRODUCTION:-

Here we will touch on many aspects of object-orientation. The word object has surfaced in more ways than you can count. There are OOPLs (Object-Oriented Programming Languages) and OODBs (Object-Oriented Databases), OOA (object-oriented analysis), and OOD (object-oriented design). We are sure you can come up with some OOisms of your own.

Our goal in this column is to explore object-orientation through practical object-oriented programming. This time, we look at C++, but in the future we will explore other areas of object-orientation. Learning an objectoriented language-a whole new way of programming-will pave the way for many exciting topics down the road.

Our intended audience consists of humble beginners to seasoned hackers. We assume that you have programmed in at least one procedural language, such as C or Pascal. Even if you are familiar with C++, please stay with us, you may learn some interesting new language features. Also, we will illustrate our points with many self-contained examples that you may later wish to incorporate into your own program

BASICS OF C++

CHARACTERSTICSA TO Z a to z 0 to 9 SYMBOLS: +, -, *, <, >, {, }, [, ], =, !, (, ), ;, /

TOKENS- A token is the smallest element of a C++ program that is meaningful to the compiler. The C++
parser recognizes these kinds of tokens: identifiers, keywords, literals, operators, punctuators, and other separators. A stream of these tokens makes up a translation unit. Tokens are usually separated by "white space." White space can be one or more: Blanks Horizontal or vertical tabs New lines Form feeds Comments

IDENTIFIERS: An identifier is a sequence of characters used to denote one of the following:


Object or variable name Class, structure, or union name Enumerated type name Member of a class, structure, union, or enumeration Function or class-member function typed name Label name Macro name Macro parameter

KEYWORDS: All programming languages have "reserved words". There are usually less than 50 of these
reserved words in any given programming language. They are reserved because they have been pre-assigned a specific meaning within that programming language, thus the compiler recognizes those words to mean a specific thing or action. Within C++ the reserved words are also known as "keywords"

Programmers use identifier names for a variety of items, to include: functions, variables, named constants, alias names, etc. But, they can't use as identifier names the words that are "reserved to the language".

LITERALS: Invariant program elements are called "literals" or "constants." The terms "literal" and "constant"
are used interchangeably here. Literals fall into four major categories: integer, character, floating-point, and string literals. A literal may be any of the following: Integer-constant Character-constant Floating-constant String-literal

Examples 157 // integer constant 0xFE // integer constant 'C' // character constant 0.2 // floating constant 0.2E-01 // floating constant "Dog" // string literal

OPERATORS: This is a list of operators in the C++ and C programming languages. All the operators listed
exist in C++; the fourth column 'Included in C indicates whether an operator is also present in C. Note that C does not support operator overloading.

When not overloaded, for the operators &&, || ? And, (the comma operator), there is a sequence point after the evaluation of the first operand. C++ also contains the type conversion operators const_cast, static_cast, dynamic cast, and reinterpret cast which are not listed in the table for brevity. The formatting of these operators means that their precedence level is unimportant.

1. Arithmetic Operators

All the basic arithmetic operations can be carried out in C. All the operators have almost the same meaning as in other languages. Both unary and binary operations are available in C language. Unary operations operate on a singe operand, therefore the number 5 when operated by unary will have the value 5. Arithmetic Operators Operator Meaning

Addition or Unary Plus

Subtraction or Unary Minus

Multiplication

Division

Modulus Operator

Examples of arithmetic operators are x+y x-y -x + y a*b+c -a * b etc., here a, b, c, x, y is known as operands. The modulus operator is a special operator in C language which evaluates the remainder of the operands after division.

2. Relational Operators

Often it is required to compare the relationship between operands and bring out a decision and program accordingly. This is when the relational operator comes into picture. C supports the following relational operators.

Operator

Meaning

<

is less than

<=

is less than or equal to

>

is greater than

>=

is greater than or equal to

==

is equal to

!=

is not equal to

It is required to compare the marks of 2 students, salary of 2 persons; we can compare those using relational operators.

A simple relational expression contains only one relational operator and takes the following form.

Exp1 relational operator exp2

Where exp1 and exp2 are expressions, which may be simple constants, variables or combination of them. Given below is a list of examples of relational expressions and evaluated values.

6.5 <= 25 TRUE -65 > 0 FALSE 10 < 7 + 5 TRUE

Relational expressions are used in decision making statements of C language such as if, while and for statements to decide the course of action of a running program.

3. Logical Operators

C has the following logical operators; they compare or evaluate logical and relational expressions.

Operator

Meaning

&&

Logical AND

||

Logical OR

Logical NOT

4. Assignment Operators

The Assignment Operator evaluates an expression on the right of the expression and substitutes it to the value or variable on the left of the expression.

Example x=a+b Here the value of a + b is evaluated and substituted to the variable x.

FLOW OF CONTROL

When a programmer is crafting a program, it is good practice to break the program down into pieces that can be thought of independently. Once the program has been completed, we can think of its execution as being a series of these pieces that work together in a certain sequence. These pieces then pass the control of the program between each other. While one piece has the control, the other pieces are inactive. This is known as the flow of control in a program.

C++ provides two styles of flow control: Branching Looping

Branching is deciding what actions to take and looping is deciding how many times to take a certain action.

Branching:

Branching is so called because the program chooses to follow one branch or another.

If statement This is the simplest form of the branching statements.

It takes an expression in parenthesis and an statement or block of statements. If the expression is true then the statement or block of statements gets executed otherwise these statements are skipped.

NOTE: Expression will be assumed to be true if its evaluated values are non-zero.

If statements take the following form:

Example if (expression) statement; or if (expression) { Block of statements; } or if (expression) { Block of statements; } else { Block of statements; } or if (expression) { Block of statements; } else if(expression) { Block of statements; } else { Block of statements; }

? : Operator The? : Operator is just like an if ... else statement except that because it is an operator you can use it within expressions. ? : is a ternary operator in that it takes three values, this is the only ternary operator C has. ? : takes the following form:

Example If condition is true? then X return value : otherwise Y value;

Switch statement: The switch statement is much like a nested if. else statement. Its mostly a matter of preference which you use; switch statement can be slightly more efficient and easier to read.

Example switch( expression ) { case constant-expression1: statements1; [case constant-expression2: statements2;] [case constant-expression3: statements3;] [default : statements4;] } Using break keyword: If a condition is met in switch case then execution continues on into the next case clause also if it is not explicitly specified that the execution should exit the switch statement. This is achieved by using break keyword. What is default condition? If none of the listed conditions is met then default condition executed.

LOOPING

Loops provide a way to repeat commands and control how many times they are repeated. C provides a number of looping way.

While loop

The most basic loop in C is the while loop. A while statement is like a repeating if statement. Like an If statement, if the test condition is true: the statements get executed. The difference is that after the statements have been executed, the test condition is checked again. If it is still true the statements get executed again. This cycle repeats until the test condition evaluates to false.

Basic syntax of while loop is as follows:

Example while ( expression ) { Single statement or Block of statements; }

For loop

For loop is similar to while, it's just written differently. For statements are often used to process lists such a range of numbers:

Basic syntax of for loop is as follows:

Example for( expression1; expression2; expression3) { Single statement or Block of statements; }

In the above syntax: expression1 - Initialises variables. expression2 - Conditional expression, as long as this condition is true, loop will keep executing. expression3 - expression3 is the modifier which may be simple increment of a variable.

Do...while loop

Do ... while is just like a while loop except that the test condition is checked at the end of the loop rather than the start. This has the effect that the content of the loop are always executed at least once.

Basic syntax of do...while loop is as follows:

Example do { Single statement or Block of statements; }while(expression);

Break and continue statements

C provides two commands to control how we loop: Break -- exit form loop or switch. Continue -- skip 1 iteration of loop.

You already have seen example of using break statement. Here is an example showing usage of continue statement.

Programs of flow of control:-

(1) Wap to print largest of three numbers #include<iostream.h> Void main( ) { int a,b; cout<<enter two numbers; cin>>a>>b; if(a>b) { Cout<<you are pass; } Else Cout<<you are fail; }

(2) #include<iostream..h> Void main ( ) { Int a, b, c; cout<<enter the numbers; cin>>a>>b>>c; if(a>b)&&(a>c) cout<<largest is<<a; else { If(b>c) Cout<<largest is<<b; }} Else Cout<<largest is<<c; }

(3) #include<iostream.h> Void main( ) { Int i; For (i=1, i<10, i++) { Cout<<i<<endl; } }

(4) Wap to print sum of 1st n numbers #include<iostream.h> Void main( ) { Int i, sum, n; For(i=0,i<n,i++) { Cout<<i<<endl; } }

(5) #include<iostream.h> Void main( ) { Int i, num, fact=1; Cout<<enter the number; Cin>>num; I=num; While(num>0) { Fact=fact*num; --num; } Cout<<factorial of<<i<<is<<fact; }

(6) #include<iostream.h> Void main( ) { For(i=1;i<5;i++) { For(j=1;j<=i;j++) { Cout<<* } Cout<<endl; } getch( ); } The following output will be generated: * ** *** ****

(7) #include<iostream.h> Void main( ) { Int a,b,c; For(i=0;i<20;i++) { Cout<<enter 2 numbers; Cin>>a>>b; If(b==0) { Cout<<denominator cant exist<<enter again; Continue; Else C=a/b Cout<<c<<endl; } Getch( ); }

(8) Program to check whether the number is prime or not

#include<iostream.h> #include<process.h> int main( ) { Int num, i; Cout<<enter the number<<endl; Cin>>num; For(i=2;i<num/2;i++) If (num%i==0) { Cout<<not a prime number<<endl; Exit(0); } Cout<<it is a prime number; Return 0; }

ARRAYS

An array is a data structure which allows a collective name to be given to a group of elements which all have the same type. An individual element of an array is identified by its own unique index (or subscript).

An array can be thought of as a collection of numbered boxes each containing one data item. The number associated with the box is the index of the item. To access a particular item the index of the box associated with the item is used to access the appropriate box. The index must be an integer and indicates the position of the element in the array. Thus the elements of an array are ordered by the index.

SYNTAX: Datatype arrayname [size]; Example:#include<iostream.h> Void main( ) { Int i; For(i=0;i<=10;i++) Cout<<marks[i]; { For(i=0;i<=10;i++); Cin>>marks[i];

MULTI-DIMENSIONAL ARRAY
A Multidimensional array is an array of arrays.

How are Multidimensional Arrays represented in C++ Suppose a programmer wants to represent the two-dimensional array Exforsys as an array with three rows and four columns all having integer elements. This would be represented in C++ as: Int Exforsys[3][4];

COMPARING OF MATRICES:-

#include<iostream.h> Void main( ) Int a[3][3], b[3][3], r , c; Cout<<enter first matrices<<endl; For(r=0;r<3;r++) { For(c=0;c<3;c++) { Cin>>a[r][c]; }} Cout<<enter the second matrices<<endl; For(r=0;r<3;r++) { For(c=0;c<3;c++) { Cin>>b[r][c]; }} Int flag=0; For(r=0;r<3;r++) { For(c=0;c<3;c++) { If(a[r][c]!=b[r][c]) {

Flag=1; Break; } If(flag==1) Break; }} If(flag) Cout<<matrices are unequal; Else Cout<<matrices are equal; Getch( ); }

STRING AS ARRAY

Char a[ ]

String is define as character array that is terminated by null character.

#include<iostream.h> Void main( ) { Int i; Char city[5][10]; Cout<<enter the different city; For(i=0;i<=4;i++) {

Cin>>city[i]; } Cout<<entered cities are; For(i=0;i<=4;i++) { Cout>>city[i]<<endl; }}

STRING OPERATIONS:(1) READING AND WRITING OF STRINGS (2) CANCATENATION OF STRINGS (3) COPY 1 STRING TO ANOTHER (4) COMPARING OF 2 STRINGS

FUNCTIONS OF STRING OPERATIONS(a) strcat( ) (b) strcmp( ) (c) strcopy( ) (d) strlen( )

Strcat:-

Void main( ) { Char str1[20], str2[10]; Cout<<enter 1st string; Gets(str1); Cout<<enter 2nd string;

Gets(str2); Strcat(str1,str2); Cout<<str1; }

FUNCTIONS:-

A Function groups is a number of program statements into a unit and give its name and this unit can be invoked from other part of program.

SYNTAX-

Returntype functionname(datatype arg1,datatype arg2) { Body of function Return statement; }

~ in RETURN TYPE we write a type of value which is return by the function. Ex:- int, float, char etc ~ FUNCTION NAME can be any name confirming the syntax rules ~ DATA TYPE of argument depends upon the application of functions. ~ an ARGUMENT is a data passed from the program to the function ~ BODY OF THE FUNCTION includes a statement or a block of statements enclosed between a curli brackets.

Example: SWAP program revisited

#include<iostream> using namespace std; void swap_ref(int &a,int &b); void swap_val(int a,int b); int main() { int a=3,b=6; printf(\na=%d b=%d,a,b); swap_val(a,b); printf(\na=%d b=%d,a,b); swap_ref(a,b); printf(\n a=%d b=%d,a,b); return 1; } void swap_ref(int &a, int &b) { a=a+b; b=a-b; a=a-b; } void swap_val(int a, int b) { a=a+b; b=a-b; a=a-b; }

OUTPUT: a=3 b=6 a=3 b=6 a=6 b=3

Default arguments C++ provides the option of providing default values to the arguments being passed to a function.

IMPORTANT all the parameters with default values should lie to the right in the signature list i.e. the default arguments should be the trailing argumentsthose at the end of the list. when a function with default arguments is called, the first argument in the call statement is assigned to the first argument in the definition, the 2nd to 2nd and so on. This becomes more clear from the last call to sum() in the above example where value 10 is assigned to n and 2 is assigned to diff and not first_term. the default argument values appear in the prototype as well as definition. You still may omit variable names in the prototypes. The syntax then being int xyz(int =2,char=5);

Function overloading

c++ permits the use of two function with the same name. However such functions essentially have different argument list. The difference can be in terms of number or type of arguments or both.

This process of using two or more functions with the same name but differing in the signature is called function overloading.

But overloading of functions with different return types are not allowed.

In overloaded functions , the function call determines which function definition will be executed.

The biggest advantage of overloading is that it helps us to perform same operations on different datatypes without having the need to use separate names for each version.

EXAMPLE:void area(float a); void area(floatl, floatb); void main( ) { float r,l,b; Cout<<enter the value of r,l,b; Cin>>area of circle is; Area(r); Cout<<area of rectangle is; Area(l,b); } Void area(float r) { float a=3.14*r*r; Cout<<area=<<a<<endl; } Void area(floatl,floatb) { Float a=l*b; Cout<<area<<a<<endl; }

The above function finds the absolute value of any number int, long, float, double.

In C, the above is implemented as a set of different function abs ( )-for int, fabs( )-for double, labs( )-for long.

The use of overloading may not have reduced the code complexity /size but has definitely made it easier to understand and avoided the necessity of remembering different names for each version function which perform identically the same task.

CLASSES:-

A Class is a way to bind the data describing an entity and its associated function together

SYNTAX Class classname { Access specifiers:

Datatype data 1; ```` ```` Datatype data n; Functions/methods( ); }

DATA MEMBERS: - These are the data type properties that describe the characteristics of the class.

MEMBER FUNCTION:- These are the set of operation that can be applied to an object of the class.

ACCESS SPECIFIER:- These are used to control access to members from within the program

These are of 3 types:(1) Private (2) Public (3) Protected

In PRIVATE ACCESS specifier the data member can be accessed and processed by the member function and the friend function of the class Private member cannot be access by outer class or outside the class

In PUBLIC ACCESS specifier data members can be accessed and processed by all the member function of the class and outside the class

In PROTECTED ACCESS specifier data members can be access and processed by the member function of the class in which these are declared. These functions can also be accessed by member functions derived from these classes

Example Class account { Private: Int amount; Float balance=1000; Public: Float deposit(float amount) { Balance=balance+amount Return balance; } Float withdrawl(float amount) {Balance=balance-amount Return balance; } }; Void main ( ) { Account a; int b, c; B=a. deposit (5000); Cout<<b; C=a.withdrawl (500); Cout<<c; }

Friend Functions
A friend function is a function that is not a member of a class but has access to the class's private and protected members. Friend functions are not considered class members; they are normal external functions that are given special access privileges. Friends are not in the class's scope, and they are not called using the member-selection operators (. and >) unless they are members of another class. A friend function is declared by the class that is granting access. The friend declaration can be placed anywhere in the class declaration. It is not affected by the access control keywords. The following example shows a Point class and a friend function, Change Private. The friend function has access to the private data member of the Point object it receives as a parameter.

CALL BY VALUE AND CALL BY REFERENCE:The arguments passed to function can be of two types namely

1. Values passed 2. Address passed

The first type refers to call by value and the second type refers to call by reference. For instance consider program1

main( ) { int x=50, y=70; interchange(x,y); printf(x=%d y=%d,x,y); } interchange(x1,y1) int x1,y1; { int z1; z1=x1; x1=y1; y1=z1; printf(x1=%d y1=%d,x1,y1); }

Here the value to function interchange is passed by value.

Consider program2

main() { int x=50, y=70; interchange(&x,&y); printf(x=%d y=%d,x,y); } interchange(x1,y1) int *x1,*y1; { int z1; z1=*x1; *x1=*y1; *y1=z1; printf(*x=%d *y=%d,x1,y1); }

Here the function is called by reference. In other words address is passed by using symbol & and the value is accessed by using symbol *.

The main difference between them can be seen by analyzing the output of program1 and program2.

The output of program1 that is call by value is

x1=70 y1=50 x=50 y=70

But the output of program2 that is call by reference is

*x=70 *y=50 x=70 y=50

This is because in case of call by value the value is passed to function named as interchange and there the value got interchanged and got printed as

x1=70 y1=50

and again since no values are returned back and therefore original values of x and y as in main function namely x=50 y=70 got printed.

INHERITANCE:-

Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived class.

For example, a programmer can create a base class named fruit and define derived classes as mango, orange, banana, etc. Each of these derived classes, (mango, orange, banana, etc.) has all the features of the base class (fruit) with additional attributes or features specific to these newly created derived classes. Mango would have its own defined features, orange would have its own defined features, banana would have its own defined features, etc.

This concept of Inheritance leads to the concept of polymorphism.

TYPES OF INHERITANCE:-

1. Single class Inheritance:


When class a gas inherited in class has known as base class and B class is know as derived class. Here only two classes have linked to each other.

2. Multilevel Inheritance:
In this type of inheritance, there are number of level and it has used in that cases where we want to use all properties in number of levels according to the requirement. For example, class A inherited in class b and class b has inherited in class c for class b so on. Where class A is base class c. In another way we can say b is derived

class a base class for c and a indirect base class for c is indirect base class for c and c indirect derived class for class A.

3. Multiple Inheritances:

In this type of inheritance, number of classes has inherited in a single class. Where two or more classes are, know as base class and one is derive class.

4. Hierarchical Inheritance:

This type of inheritance helps us to create a baseless for number of classes and those numbers of classes can have further their branches of number of class.

5. Hybrid Inheritance:

In this type of inheritance, we can have mixture of number of inheritances but this can generate an error of using same name function from no of classes, which will bother the compiler to how to use the functions. Therefore, it will generate errors in the program. This has known as ambiguity or duplicity.

CONSTRUCTORS:-

When an object of a class is created, C++ calls the constructor for that class. If no constructor is defined, C++ invokes a default constructor, which allocates memory for the object, but doesn't initialize it.

Why you should define a constructor Uninitialized member fields have garbage in them. This creates the possibility of a serious bug (eg, an uninitialized pointer, illegal values, inconsistent values ...).

Declaring a constructor

A constructor is similar to a function, but with the following differences. No return type. No return statement

EXAMPLE:-

Class xyz { Int a, b; Public: Xyz( ) { A=10; B=5; } } Void main( ) { Xyz obj1; Getch( ); }

It will give the following output:10 5

Destructors:-

Destructors are usually used to reallocated memory and do other cleanup for a class object and its class members when the object is destroyed. A destructor is called for a class object when that object passes out of scope or is explicitly deleted.

A destructor is a member function with the same name as its class prefixed by a ~ (tilde). For example:

Class X { Public: // Constructor for class X X( ); // Destructor for class X ~X( ); };

A destructor takes no arguments and has no return type. Its address cannot be taken. Destructors cannot be declared const, volatile, const volatile or static. A destructor can be declared virtual or pure virtual.

POLYMORPHISM:In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface. The concept of parametric polymorphism applies to both data types and functions. A function that can evaluate to or be applied to values of different types is known as a polymorphic function. A data type that can appear to be of a generalized type is designated polymorphic data type like the generalized type from which such specializations are made.

Вам также может понравиться