28795185 fundamentals of computer

Upload: rajalingam-balakrishnan

Post on 14-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 28795185 Fundamentals of Computer

    1/56

    G.K.M COLLEGE OF ENGINEERING AND TECHNOLOGY

    CHENNAI-63

    COMPUTER SCIENCE AND ENGINEERING DEPARTMENT

    LABORATORY MANUAL

    COMPUTER PRACTICE LABORATORY-II

    II SEMESTER

    2008-2009.

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00

  • 7/30/2019 28795185 Fundamentals of Computer

    2/56

    APPROVAL

    The MANUAL of (GE 2155) COMPUTR PRACTICE LABORATORY- II

    UNDER COMPUTR PRACTICE LABORATORY- II IN II SEMESTER

    OF I YEAR (2008-2009) .

    PREPARED BY APPROVED BY

    1. Ms.S.Sudha. Mr.M.Babu.2. Mr.M.Karthikeyan. HOD/CSE.3. Mr.P.Selvakumar.

    4. Mr.E.Senthilkumaran.5. Mr.M.Manickam.6. Mr.N.Kalyanasundaram.7. Mr.Amit Prasad.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00

  • 7/30/2019 28795185 Fundamentals of Computer

    3/56

    I N D E X - II N D E X - I

    S.NOS.NO NAME OF THE EXPERIMENTNAME OF THE EXPERIMENT PAGE NOPAGE NO11 STUDY OF UNIX OPERATING SYSTEM. 11

    22 STUDY OF BASIC UNIX COMMANDS. 88

    33 STUDY OF VI EDITORS. 1414

    4A4A CALCULATING THE GROSS SALARY OF

    AN EMPLOYEE.

    2121

    4B4B FINDING THE AREA OF A CIRCLE. 2323

    5A5A TO IMPLEMENT THE CONCEPT OF

    TWO-WAY BRANCHING USING IF

    STATEMENT.

    2525

    5B5B TO IMPLEMENT THE CONCEPT OF

    MULTI-WAY BRANCHING USING IF-

    ELIF STATEMENT.

    2727

    5C5C TO IMPLEMENT THE CONCEPT OF

    MULTI-WAY BRANCHING USING CASE

    STATEMENT.

    2929

    6A6A TO WRITE A PROGRAM TO PRINT N

    NATURAL NUMBERS.

    3131

    6B6B TO WRITE A PROGRAM TO PRINT FIRST

    N FIBONACCI SERIES.

    3333

    6C6C TO WRITE A PROGRAM TO PRINT THE

    MULTIPLICATION TABLE USING UNTIL

    LOOP.

    3535

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00

    I N D E X -I N D E X - IIII

    S.NOS.NO NAME OF THE EXPERIMENTNAME OF THE EXPERIMENT PAGE NOPAGE NO6D6D TO WRITE A PROGRAM TO PRINT THE 3737

  • 7/30/2019 28795185 Fundamentals of Computer

    4/56

    SUM USING FOR LOOP.

    6E6E TO WRITE A PROGRAM TO

    CALCULATE THE FACTORIAL.

    3939

    77 PROGRAM TO FIND INVERSE OF THE

    GIVEN NUMBER AND FIBONACCISERIES UP TO NEEDED LEVEL USING

    FUNCTIONS.

    4141

    88 PROGRAM FOR THE ILLUSTRATION

    OF POINTERS EXPRESSIONS.

    4444

    99 PROGRAM FOR DYNAMIC MEMORY

    ALLOCATION, REALLOCATION AND

    DELETING.

    4646

    1010 PROGRAM TO CREATE FILE, TO

    STORE INFORMATION IN THE FILE

    AND TO SHOW THE INFORMATION IN

    THE FILE BY USING FILE HANDLING

    FUNCTIONS.

    4949

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00

    EX NO: 1 STUDY OF UNIX OPERATING SYSTEMEX NO: 1 STUDY OF UNIX OPERATING SYSTEM

    AIM:AIM: To study about unix operating system.To study about unix operating system.

    WHAT IS UNIX

  • 7/30/2019 28795185 Fundamentals of Computer

    5/56

    UNIX is an operating system which was developed first in the

    1960s and has under constant development ever since by operating

    system we mean the sui te of programs which make the computer

    work. I t is a stable, mult i-user, mult i- tasking operat ing system for

    servers, desktops and laptops.

    UNIX operat ing system also have graphical user interface (GUI)

    similar to Microsoft windows operat ing system which provides an

    easy to environment. However knowledge of unix is required for

    operations which are not covered by graphical program or for when

    there is no windows interface available.

    TYPES OF UNIX

    There are many different versions of unix, although they

    share the common similar i t ies. The most popular variet ies of unix

    are Sun Solaris, GNU/Linux and Macos X.

    THE UNIX OPERATING SYSTEM

    The Unix Operating system is made up of three parts

    1 . The Kernel

    2 . The She ll

    3 . The ProgramsTHE KERNEL

    The Kernel of Unix is the hub of the operating system. It

    al locates t ime and memory to programs and handles the f i le store

    and communication in response to system calls.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 1 OF 51

    As an i l lustrat ion of the way that the shel l and the kernel work

    together, suppose a user types rm myfi le (which has the effect of

    removing the fi le myfile). The shell scratches the fi lestore for the fi le

    containing the program rm. And then requests the kernel, through

    system cal ls to rm myfi le f inished running, the shel l then returns

  • 7/30/2019 28795185 Fundamentals of Computer

    6/56

    the unix prompt % to the user, indicating execute the program rm

    on myfile. When the process that it is waiting for future commands.

    THE SHELL

    The shell acts as an interface between the user and the

    kernel. When user login, the login program checks the username and

    password, and then star ts another program cal led the shel l . The

    shell is a command line interpreter (CLI). It interprets the commands

    the user t ypes in an a rranges for them to be car ried out . The

    commands are themselves programs. When they terminate, the shell

    gives the user another prompt (% on our system). By typing part of

    the name of a command, f i lename and directory and pressing the

    [tab] key, the shel l wi l l complete the rest of them automatical ly. I f

    shel l f inds more than one name beginning wi th those let ters you

    have typed, it wil l beep, prompting to type a few more letters before

    pressing the tab key again.

    The shel l keeps the l ist of the commands you have typed in, i f you

    need to repeat a command, use the cursor key to scroll up and down

    the l is t or type history for a l is t of previous commands. Di f ferentusers may use dif ferent shel ls. Ini t ial ly, your system administrator

    wil l supply a default shell, which can be overridden or changed.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 2 OF 51

    The most commonly available shells are:

    Bourne shell (sh)

    C shell (csh)

    Korn shell (ksh)

  • 7/30/2019 28795185 Fundamentals of Computer

    7/56

    TC Shell (tcsh)

    Bourne Again Shell (bash)

    Each shel l a lso i ncl udes i ts own prog ramming l anguage.

    Command f i les, cal led "shel l scr ipts" are used to accomplish a

    series of tasks.

    Uti l i t ies :UNIX provides several hundred ut i l i ty programs, often

    referred to as commands.

    Accomplish uni versal functions

    editing f i le maintenance

    printing

    sorting

    programming support

    online info

    Modular : s ingle funct ions can be g rouped to per fo rm more

    complex tasks.

    The Bourne shell i s one o f the o ldest she l ls and is the most

    efficient for background work. However it provides few facil i t ies for

    interactive users.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 3 OF 51

    The C shel l provides sophisticated interactive capabil it ies lacking

    in the Bourne she ll . Features o f this she ll inc lude a command

    history buffer, command aliases and fi le name

  • 7/30/2019 28795185 Fundamentals of Computer

    8/56

    complet ion. The C she ll has a syntax which resembles the C

    programming language.

    The C shell is the default shel l for interact ive work on many UNIX

    systems. I t wi l l be covered in this document, al though most of thebasic commands given here are relat ively standard across al l the

    main shells.

    The Korn shell was writ ten by David Korn from AT&T and in i t he

    attempted to merge the preferred features of both the Bourne and C

    shells as well as adding some additional features.

    Unfor tunately the Korn shel l was not avai lable for f ree, as other

    UNIX shel ls were, so many users and companies did not chose to

    use of it.

    The Bash shell was based on the Bourne shell (Bourne again

    shell) and as with Korn it attempted to combine the best features of

    the other shells which were available at the time. This shell however

    was available for free.

    Bash was init ially adopted for LINUX although several varieties of

    LINUX now exist e.g. RedHat, SuSE and Debian-GNU.

    FILES AND PROCESS

    Everything in unix is either a fi le or a process. A process

    is an execu ting p rogram iden ti fi ed by a unique P ID (Process

    Identif ier).

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 4 OF 51

    A f i le is col lect ion of datas. They are created by users using text

    editors, running, compilers etc.

    Examples of f i les

    Document

  • 7/30/2019 28795185 Fundamentals of Computer

    9/56

    The text of a program written in some high level language.

    All fi les are grouped together in the directory structure. The fi le

    system is arranged in a hierarchical structure, l ike inverted tree. The

    top of the hierarchy is traditionally called root (written [/] slash)

    FEATURES OF UNIX

    1. Mul ti task ing

    Mult i tasking is the capabil i ty of the operating system to

    perform var ious tasks s imul taneously. I .e. A s ingle user can run

    multiple programs (tasks) concurrently.

    2. Mult i -user Capabi l i tyMulti-user capabil ity of UNIX allows several users to use the

    same computer to perform their tasks. Several terminals (keyboards

    and monitors) are connected to a single powerful computer (Unix

    server) and each user can work with their terminals.

    3 . Secu ri ty

    Unix allows sharing of data. Every user must have a login

    name and a password . So, accessing ano ther user s data i s

    impossible without permission.

    I.e. Invalid users cannot access data.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 5 OF 51

    4. Por tabi li ty

    UNIX is portable because it is written in a high level language.

    So, UNIX can be run on different computers.

  • 7/30/2019 28795185 Fundamentals of Computer

    10/56

    5. Communication

    UNIX supports the fallowing communications

    o Between the dif ferent terminals connected to the UNIX

    server.

    o Between the users o f one compute r to the users o f

    another computer located elsewhere in the network.

    6. Programming facil i ty

    UNIX is highly programmable, the UNIX shell programming

    language has all necessary ingredients l ike conditional and control

    structure (Loops) and variables, that establ ish i t as a programming

    language in its own right.

    ADVANTAGES OF UNIX

    UNIX is a very stable operating system.

    UNIX supports the Multi-User feature.

    UNIX is a Multitasking operating system.

    UNIX can be loaded to any type of computer hardware.

    UNIX is optimized for program development.

    UNIX has r ich set of smal l commands and ut il i ties that do

    specific tasks.

    UNIX has a powerful unif ied f i le system, everything in a f i le;

    data, program and all physical devices.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 6 OF 51

    UNIX has the abil ity to string commands and uti l i t ies together

    in unlimited ways to accomplish more complicated tasks.

  • 7/30/2019 28795185 Fundamentals of Computer

    11/56

    UNIX al lows onl y autho ri zed use rs to modi fy f ile s and

    directories.

    UNIX al lows only System Administrators to make changes in

    System Configuration fi les.

    RESULT:

    Thus study of unix operating system was completed.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 7 OF 51

    EX NO: 2 STUDY OF BASIC UNIX COMMANDS

  • 7/30/2019 28795185 Fundamentals of Computer

    12/56

    AIM:To study about basic UNIX commands in UNIX

    GENERAL COMMANDS

    NO COMMAND SYNTAX VARIANCE/OPTIONS DESCRIPTION1 Date Date

    _Displays the current date andtime

    2 Cal cal MMYYYY

    Cal Displays the calendar of thecurrent month

    cal YYYY Displays the calendar of thewhole year specified

    cal MM YYYY Displays the calendar of thespecified month and year

    3 Man man commandname -

    Displays the manual pages ofthe command name specified.

    4 Who Who-

    Displays information aboutpeople who are presentlylogged in

    5 who am i who am i-

    Displays information aboutoneself

    6 Finger finger user-

    Displays information about thespecified user

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 8 OF 51

    FILE MANAGEMENT COMMANDS

  • 7/30/2019 28795185 Fundamentals of Computer

    13/56

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 9 OF 51

    12 Page page file Same as moreexcept that

    NO COMMAND SYNTAX VARIANCE/

    OPTIONS

    DESCRIPTION

    7 Cat cat > filename cat > filename Creates a filewith thespecified name

    cat filename Displays thespecified file inthe console

    cat file1file2filen >filez

    Copies thespecified files tofilez

    cat >> filename Appendscontents to thespecified file

    8 Rm rm filename-

    removes thespecified file

    9 Mv mv filenamedestination

    mv filenamedestination

    Moves the file tothe destination

    mv filenamenewname

    Renames the filewith the newnameRenaming can bedone whilemoving withinthe samedirectory ordifferentdirectory

    10 Cp cp sourcedestination

    Copy SOURCEto DEST, ormultipleSOURCE(s) toDIRECTORY.

    11 More more file More is a filter for pagingthrough text onescreenful at atime for lengthyfiles.

  • 7/30/2019 28795185 Fundamentals of Computer

    14/56

    more requiresspacebar to bepressed forevery pagewhereas page

    requires returnkey to bepressed

    13 Ls Ls -l shows aboutpermission, owner,size etc-a shows all filesincluding hiddenfiles-R displays thecontents of

    subdirectories-r reverses theorder of filesdisplayedls ~ List thecontents of yourhome directoryls / List thecontents ofyourroot directory.

    ls ../ List thecontents of theparent directory.ls */ List thecontents of all subdirectories.ls -d */ Only listthe directories inthe currentdirectory.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 10 OF 51

    http://www.computerhope.com/jargon/r/root.htmhttp://www.computerhope.com/jargon/r/root.htm
  • 7/30/2019 28795185 Fundamentals of Computer

    15/56

    14 File file filename Displays thetype of thespecified file

    15 Wc wc filename Print thenumber of lines,

    words,characters andbytes in the file.

    16 Head head nfilename

    Display the firstn lines from thefile

    17 Tail tail n filename Display the lastn lines from thefile

    18 Sort sort filename -r sort inreverse order

    -fsort ignoringcase-n sortnumerically-b ignoreleading blanks

    Sorts the linesin the text files

    and displaysthem in theconsole

    19 Grep greppatternfilename

    -F for fixedgrep-E for extendedgrep-c print the

    count ofmatching lines-i ignore casefor matching-h prefix eachmatching linewith linenumber

    Grep searchesthe named inputFILEs for linescontaining amatch to the

    givenPATTERN.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 11 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    16/56

    DIRECTORY MANAGEMENT COMMANDS

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 12 OF 51

    20 Chmod chmodfilename users+ permissionsfile/directory

    + for addingpermission- for removingpermissionu stands forownerg stands forgroupo stands forothers

    chmod changesthe permissionsof each givenfile accordingto the modespecified

    NO COMMAND SYNTAX VARIANCE/OPTIONS DESCRIPTION

    21 Mkdir Mkdirdirname

    Creates a directory with thespecified name.

    22 Rmdir Rmdirdirname

    Deletes the specified directoryif not empty

    23 Mv mv dirnamedestination

    Move the directory and all itscontents to the destination. If aname is specified in the

    destination, the directory willbe renamed.

    24 Pwd Pwd Shows the current directory

    25 Cd cdcd ~

    Moves to the home directory

    cd ..

    cd -

    Moves to the parent directoryMoves to the previousdirectory

  • 7/30/2019 28795185 Fundamentals of Computer

    17/56

    RESULT: Thus basic UNIX commands in UNIX was studied.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 13 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    18/56

    EX:NO:3 VI EDITOR

    AIM: To Study of Basic vi Commands

    What isVI?

    The default editor that comes with the UNIX operating system is called vi (visual

    editor). [Alternate editors for UNIX environments include Pico and emacs, a

    product of GNU.]The UNIX vi editor is a full screen editor and has two modes of operation:

    1. Command mode commands which cause action to be taken on the file, and2. Insert mode in which entered text is inserted into the file.

    In the command mode, every character typed is a command that does somethingto the text file being edited; a character typed in the command mode may evencause the vi editor to enter the insert mode.

    In the insert mode, every character typed is added to the text in the file; pressingthe (Escape) key turns off the Insert mode.

    The most basic and useful commands are marked with an asterisk (* or star) in the

    tables below.NOTE: Both UNIX and vi are case-sensitive. Be sure not to use a capital letter

    in place of a lowercase letter; the results will not be what you expect.

    To Get Into and Out OfVI

    To Start vi

    To use vi on a file, type in vi filename. If the file named filename exists, then

    the first page (or screen) of the file will be displayed; if the file does not exist,then an empty file and screen are created into which you may enter text.

    * vi filename editfilename starting at line 1

    vi -r filenameRecoverfilename that was being edited when system crashed

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 14 OF 51

    To Exit vi

  • 7/30/2019 28795185 Fundamentals of Computer

    19/56

    Usually the new or modified file is saved when you leave vi. However, it is also

    possible to quit vi without saving the file.

    Note: The cursor moves to bottom of screen whenever a colon (:) is typed. This

    type of command is completed by hitting the (or) key.

    * :x quitvi, writing out modified file to file named in original invocation

    :wqquitvi, writing out modified file to file named in original invocation

    :q quit (or exit) vi

    * :q!quitvi even though latest changes have not been saved for this vi call

    Moving the Cursor

    Unlike many of the PC and MacIntosh editors, the mouse does not move thecursor within the vi editor screen (or window). You must use the key commands

    listed below. On some UNIX platforms, the arrow keys may be used as well;

    however, sincevi

    was designed with the Qwerty keyboard (containing no arrowkeys) in mind, the arrow keys sometimes produce strange effects in vi and should

    be avoided.If you go back and forth between a PC environment and a UNIX environment,you may find that this dissimilarity in methods for cursor movement is the mostfrustrating difference between the two.In the table below, the symbol ^ before a letter means that the key should

    be held down while the letter key is pressed.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 15 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    20/56

    *jor

    [ordown-arrow]move cursor down one line

    * k [orup-arrow] move cursor up one line

    *hor

    [or left-arrow]

    move cursor left one character

    *lor

    [orright-arrow]move cursor right one character

    * 0 (zero) move cursor to start of current line (the one with the cursor)

    * $ move cursor to end of current line

    w move cursor to beginning of next word

    b move cursor back to beginning of preceding word

    :0or 1Gmove cursor to first line in file

    :nor nGmove cursor to line n

    :$or G move cursor to last line in file

    Screen Manipulation

    The following commands allow the vi editor screen (or window) to move up or

    down several lines and to be refreshed.

    ^f move forward one screen

    ^bmove backward one screen

    ^dmove down (forward) one halfscreen

    ^u move up (back) one half screen

    ^l redraws the screen

    ^rredraws the screen, removingdeleted lines

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 16 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    21/56

    Adding, Changing, and Deleting Text

    Unlike PC editors, you cannot replace or delete text by highlighting it with the

    mouse. Instead use the commands in the following tables.Perhaps the most important command is the one that allows you to back up andundo your last action. Unfortunately, this command acts like a toggle, undoingand redoing your most recent action. You cannot go back more than one step.

    * u UNDO WHATEVER YOU JUST DID; a simple toggle

    The main purpose of an editor is to create, add, or modify text for a file.

    Inserting or Adding Text

    The following commands allow you to insert and add text. Each of thesecommands puts the vi editor into insert mode; thus, the key must be

    pressed to terminate the entry of text and to put the vi editor back into command

    mode.

    * i insert text before cursor, untilhit

    I insert text at beginning of current line, untilhit

    * a append text after cursor, untilhit

    A append text to end of current line, untilhit

    * oopen and put text in a new line below current line, until

    hit

    * O open and put text in a new line above current line, untilhit

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 17 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    22/56

    Changing Text

    The following commands allow you to modify text.

    * r replace single character under cursor (no needed)

    R replace characters, starting with current cursor position, untilhit

    cwchange the current word with new text,

    starting with the character under cursor, untilhit

    cNwchange Nwords beginning with character under cursor, untilhit;

    e.g., c5wchanges 5 words

    C change (replace) the characters in the current line, untilhit

    cc change (replace) the entire current line, stopping when is hit

    NccorcNcchange (replace) the next N lines, starting with the current line,

    stopping when is hit

    Deleting Text

    The following commands allow you to delete text.

    * x delete single character under cursor

    Nx delete N characters, starting with character under cursor

    dw delete the single word beginning with character under cursor

    dNwdelete Nwords beginning with character under cursor;

    e.g., d5wdeletes 5 words

    D delete the remainder of the line, starting with current cursorposition

    * dd delete entire current line

    NddordNddelete N lines, beginning with the current line;

    e.g., 5dddeletes 5 lines

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 18 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    23/56

    Cutting and Pasting Text

    The following commands allow you to copy and paste text.

    yy copy (yank, cut) the current line into the buffer

    NyyoryNy copy (yank, cut) the next N lines, including the current line, into the buffer

    P put (paste) the line(s) in the buffer into the text after the current line

    Other Commands

    Searching Text

    A common occurrence in text editing is to replace one word or phase by another.To locate instances of particular sets of characters (or strings), use the followingcommands.

    /string search forward for occurrence ofstringin text

    ?string search backward for occurrence ofstringin text

    n Move to next occurrence of search string

    NMove to next occurrence of search string in opposite

    direction

    Determining Line Numbers

    Being able to determine the line number of the current line or the total number oflines in the file being edited is sometimes useful.

    :.= Returns line number of current line at bottom of screen

    := Returns the total number of lines at bottom of screen

    ^g

    provides the current line number, along with the total

    number of lines,in the file at the bottom of the screen

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 19 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    24/56

    Saving and Reading FilesThese commands permit you to input and output files otherthan the named file with which you are currently working.

    :r filenameread file namedfilename and insert after current line

    (the line with cursor)

    :w write current contents to file named in originalvi call

    :w newfile write current contents to a new file namednewfile

    :12,35w smallfilewrite the contents of the lines numbered 12 through 35

    to a new file namedsmallfile

    :w! prevfile write current contents over a pre-existing file namedprevfile

    RESULT: Thus the commands related to vi Editor was studied.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 20 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    25/56

    Ex .No: 4A

    CALCULATING THE GROSS SALARY OF AN

    EMPLOYEE

    AIM:

    To write a simple script to calculate the gross salary of an employee.

    ALGORITHM:

    STEP 1 : Start

    STEP 2 : Get the basic salary from the user

    STEP 3 : Calculate the Da , Hra, and gross with the needed formulas namely

    da=`expr $b \* 10 / 100`

    hra=`expr $b \* 20 / 100`

    gross=`expr $b + $da + $hra`

    STEP 4 : Print the gross salary by use of echo command

    STEP 5 : Stop

    .

  • 7/30/2019 28795185 Fundamentals of Computer

    26/56

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 21 OF 51

    PROGRAM

    echo Calculating the gross salary of an employee

    echo Enter the Basic salary

    read b

    da=`expr $b \* 10 / 100`

    hra=`expr $b \* 20 / 100`

    gross=`expr $b + $da + $hra`

    echo Gross Salary=$gross`

    OUTPUT

    Calculating the gross salary of an employee

    Enter the Basic salary

    10000

    Gross Salary= 13000

    Result:Thus the program to find gross salary of an employee is created and

    executed successfully.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 22 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    27/56

    Ex .No: 4 B FINDING THE AREA OF A CIRCLE

    AIM:

    To write a simple script to find the area of a circle.

    ALGORITHM:

    STEP 1 : Start

    STEP 2 : Get the radius from the user

    STEP 3 : Read the radius.

    STEP 4 : Calculate the area by using the formula 3.142857 \* $radius \* $radius | bc

    STEP 5 : Stop

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

  • 7/30/2019 28795185 Fundamentals of Computer

    28/56

    ISSUE: B REV: 00 PAGE NO: 23 OF 51

    PROGRAM

    echo FINDING THE AREA OF THE CIRCLE

    echo "Enter the radius of the circle"

    read radius

    echo "The Area of the circle is"

    echo 3.142857 \* $radius \* $radius | bc

    OUTPUTFINDING THE AREA OF THE CIRCLE

    Enter radius of the circle

    5

    The Area of the circle is 78.571425

    Result:Thus the program to find radius of circle was created and executed

    successfully.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

  • 7/30/2019 28795185 Fundamentals of Computer

    29/56

    ISSUE: B REV: 00 PAGE NO: 24 OF 51

    Ex .No:5 A TWO-WAY BRANCHING

    AIM:

    To implement the concept of two-way branching using if statement.

    ALGORITHM:

    STEP1 :Start

    STEP2 :Declare the variables and its access

    STEP3 :If a is greater than b then print A is Big, else

    STEP4 :Print B is Big

    STEP5 :Stop

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 25 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    30/56

    Program

    echo Concept of two-way branching using if statement

    echo Finding the Biggest of two numbers

    echo Enter the two Numbers

    read a b

    if [ $a gt $b ]

    then

    echo A is Bigelse

    echo B is Big

    fi

    OUTPUT

    Concept of two-way branching using if statementFinding the Biggest of two numbers

    Enter the two Numbers

    12 45

    B is Big

    Result:Thus the program to find biggest of given two numbers by using if statement

    was created and executed successfully.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

  • 7/30/2019 28795185 Fundamentals of Computer

    31/56

    ISSUE: B REV: 00 PAGE NO: 26 OF 51

    Ex .No: 5 B

    MULTI-WAY BRANCHING USING IF-ELIF

    STATEMENT

    AIM:

    To implement the concept of multi-way branching using if-elif statement.

    ALGORITHM:

    STEP 1 : Start

    STEP 2 : Declare the variables and its accessSTEP 3 : If a is greater than b and a is greater than c, then print A is Big, else

    STEP 4 : If b is greater than c then print B is Big, else

    STEP 5 : Print C is Big

    STEP6 :Stop

    .

  • 7/30/2019 28795185 Fundamentals of Computer

    32/56

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 27 OF 51

    Program

    echo Concept of multi-way branching using if-elif statementecho Finding the Biggest of three numbersecho Enter the three Numbersecho a=read aecho b=read becho c=read c

    if [ $a gt $b ]then

    if [ $a gt $c ]then

    echo A is Bigelse

    echo C is Bigfi

    elif [ $b gt $c ]then

    echo B is Big

    elseecho C is Bigfi

    OUTPUT

    Concept of multi-way branching using if-elif statementFinding the Biggest of three numbersEnter the three Numbersa=14

    b=23c=10B is Big

    Result:Thus the program to find highest number among given three numbers by using

    if-elif statement was developed and executed successfully..

  • 7/30/2019 28795185 Fundamentals of Computer

    33/56

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 28 OF 51

    Ex .No: 5C

    MULTI-WAY BRANCHING USING CASE STATEMENT

    AIM:

    To implement the concept of multi-way branching using case statement.

    ALGORITHM:

    STEP 1 : Start

    STEP 2 : Initialize the number of choices

    STEP 3 : If the choice is present corresponding result will be displayed otherwise

    STEP 4 : The statement of the default will be displayed

    STEP 5 : Stop

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 29 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    34/56

    Program

    echo Concept of multi-way branching using case statement

    clear

    echo 1. To know Your current Directory

    echo 2.Todays Date

    echo 3.List of Users

    echo Enter your choice

    read choice

    case $choice in1) pwd;;

    2) 2)date;;

    3) who;;

    *) echo Only give inputs from 1 to 3

    esac

    OUTPUTConcept of multi-way branching using case statement1. To know Your current Directory2.Todays Date3.List of UsersEnter your choice2wed march 18 08:25:20 IST 2009

    Result:

    Thus the program for multiway branching by using case statement was createdand executed successfully.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 30 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    35/56

    Ex .No: 6 A PROGRAM TO PRINT N NATURAL NUMBERS

    AIM:

    To write a program to print n Natural numbers

    ALGORITHM:

    STEP 1 : Start

    STEP 2 : Get a number from the user to print n Natural numbers

    STEP 3 : Read the number

    STEP 4 : Start the while loop and write the statements of the loop within do and done

    STEP 5 : Echo the value of i and increment the value of i

    STEP 6 : End the loop

    STEP 7 : Stop

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

  • 7/30/2019 28795185 Fundamentals of Computer

    36/56

    ISSUE: B REV: 00 PAGE NO: 31 OF 51

    PROGRAM

    echo print n natural numbers

    echo Enter a number to get N natural numbers

    read n

    echo The first $n natural numbers are

    i=1

    while [ $i le $n ]

    do

    echo $ii=`expr $i + 1`

    done

    OUTPUT

    print n natural numbers

    Enter a number to get N natural numbers

    5

    The first 5 natural numbers are

    1

    2

    3

    4

    5

    Result:Thus the program to print n natural numbers was created by using while loop

    and executed successfully..

    ISO/CSE/MANUAL/CP LBII GE 2155

  • 7/30/2019 28795185 Fundamentals of Computer

    37/56

    ISSUE: B REV: 00 PAGE NO: 32 OF 51

    Ex .No: 6B PROGRAM TO PRINT FIRST N FIBONACCISERIES.

    AIM:

    To write a program to print first N Fibonacci Series.

    ALGORITHM:

    STEP 1 : Start

    STEP 2 : Get the number of terms of Fibonacci Series the user needs.STEP 3 : Read the number

    STEP 4 : Initialize f1=-1,f2=1 and i=1

    STEP 5 :Start the while loop and write the statements of the loop within do and done

    STEP 6 : calculate the value of the Fibonacci Series with the needed formulas

    STEP 7 : End the loop

    STEP 8 : Stop

    .

  • 7/30/2019 28795185 Fundamentals of Computer

    38/56

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 33 OF 51

    PROGRAM

    echo Enter the number of terms

    read n

    f1=-1

    f2=1

    i=1

    echo The Fibonacci series upto $n terms is

    while [ $i -le $n ]

    do

    f3=`expr $f1 + $f2`

    echo $f3

    f1=$f2

    f2=$f3

    i=`expr $i + 1`

    done

    OUTPUTEnter the number of terms10The Fibonacci series upto 10 terms is011235813

    2134

    Result: Thus the program to display Fibonacci series up to given terms was created byusing while loop and executed successfully.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

  • 7/30/2019 28795185 Fundamentals of Computer

    39/56

    ISSUE: B REV: 00 PAGE NO: 34 OF 51

    Ex .No: 6C PRINT THE MULTIPLICATION TABLE USING

    UNTIL LOOP

    AIM:

    To write a program to print the multiplication table using until loop.

    ALGORITHM:

    STEP 1 : Start

    STEP 2 : Get the number from the user to print its multiplication table.

    STEP 3 : Read the number

    STEP 4 :Start the until loop

    STEP 5 : write the necessity statements within do and done

    STEP 6 : End the loop

    STEP 7 : print the multiplication table .

    STEP 8 :Stop

    .

  • 7/30/2019 28795185 Fundamentals of Computer

    40/56

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 35 OF 51

    PROGRAM

    echo Enter a numberread n

    i=1

    echo The multiplication table of $n is

    until [ $i gt 10 ]

    do

    pro=`expr $i \* $n`

    echo $n x $i=$pro

    i=`expr $i + 1`

    done

    OUTPUT

    Enter a number5

    The multiplication table of 5 is5 x 1=55 x 2=105 x 3=155 x 4=205 x 5=255 x 6=305 x 7=355 x 8=405 x 9=455 x 10=50

    Result: Thus the program for multiplication table was developed and executedsuccessfully by until loop.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 36 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    41/56

    Ex .No: 6D PROGRAM TO PRINT THE SUM USING FOR LOOP.

    AIM:To write a program to print the sum using for loop.

    ALGORITHM:

    STEP 1 : Start

    STEP 2 : Initialize the variable i.e sum=0

    STEP 3 : Start the for loop

    STEP 4 : calculate the sum by using the formula sum=`expr $sum + $i` for all the

    elements in the for loop list

    STEP 5 : End the loop.

    STEP 6 : Print the value of the sum

    STEP 7 : Stop

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 37 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    42/56

    Program

    echo Program implementing For Loop

    sum=0

    for i in 1 2 3 4 10

    do

    sum=`expr $sum + $i`

    done

    echo The sum is $sum

    OUTPUT

    Program implementing For Loop

    The sum is 20

    Result:

    Thus the program to find the sum of the numbers by using for loop wasdeveloped and executed successfully.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 38 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    43/56

    Ex .No: 6E PROGRAM TO CALCULATE THE FACTORIAL

    AIM:

    To write a program to calculate the factorial.

    ALGORITHM:

    STEP 1 : Start

    STEP 2 : Get the number from the user

    STEP 3 : Read the number

    STEP 4 :Initialize the variable i.e f=1

    STEP 5 : Start the for loopSTEP 6 : calculate the factorial

    STEP 7 : End the loop.

    STEP 8 : print the factorial of the given number.

    STEP 9 : Stop

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 39 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    44/56

    Program

    echo "Factorial Program"

    echo "Enter the number"read a

    f=1

    for (( i = 1; i

  • 7/30/2019 28795185 Fundamentals of Computer

    45/56

    EX NO: 7 Program to find inverse of the given number and Fibonacci series

    up to needed level using functions

    AIM:To develop the program to find inverse of the given number and

    Fibonacci series up to needed level using functions

    ALGORITHM:1. Open the UNIX operating system.

    2. Edit the command vi filename in the home directory or in

    the directory created by user. VI stands for visual, a full

    screen editor, indicates most powerful editor. File name

    indicates program name.

    3. Now enter required header files and open main( ) function.

    4. Inside main( ) function declare required variables, declare

    two functions. One function to find inverse of given number

    with return type and one argument of integer data type.

    5. Another function for Fibonacci series with no return type

    and one argument of integer data type.6. Assign the values to given variables at compile or runtime.

    7. Call the two functions inside main ( ) function.

    8. Close main ( ) function. Define two functions outside

    main ( ) function.

    9. To save the program, press Escape button in the keyboard

    and enter :wq command.

    10.To compile the program edit the command cc file name.c.

    11.If no compile time error, to run the program edit the

    command ./a. out.

    12.If no run time error, output of the program is displayed.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

  • 7/30/2019 28795185 Fundamentals of Computer

    46/56

    ISSUE: B REV: 00 PAGE NO: 41 OF 51

    Program#includemain( ){

    int n1,n2;printf(" ENTER THE VALUE FOR N1: ");scanf("%d",&n1);printf(" INVERSE OF THE GIVEN NUMBER %d = %d",n1,inverse(n1));n2=10;printf("\n");printf(" FIBONACCI SERIES . . . . \n ");fibo(n2);

    }inverse(int n){

    int a,d;d=0;while(n>1){

    a=n%10;d=d*10+a;n =n/10;

    }return d;

    }fibo(int m)

    {int a,b,c,i;a=0;b=1;for(i=1;i

  • 7/30/2019 28795185 Fundamentals of Computer

    47/56

    ISSUE: B REV: 00 PAGE NO: 42 OF 51

    OUTPUT

    ENTER THE VALUE FOR N1: 7865INVERSE OF THE GIVEN NUMBER 7865 = 5687FIBONACCI SERIES . . . . .0 1 1 2 3 5 8 13 21 34

    RESULT:

    Thus the program to find inverse of the given number andFibonacci series by using functions is developed and executed successfully.

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 43 OF 51

  • 7/30/2019 28795185 Fundamentals of Computer

    48/56

    EX NO: 8 Program for the illustration of pointers expressions.

    AIM:To develop the program for the illustration of pointers

    expressions.

    ALGORITHM:

    1. Open the UNIX operating system.

    2. Edit the command vi filename in the home directory

    or in the directory created by user. VI stands for visual, a full

    screen editor, indicates most powerful editor. File name indicates

    program name

    3. Now enter required header files and open main ( )

    function.

    4. Inside main ( ) function declare required variables,

    pointers of integer data type.

    5. Give the value for the variables at compile or

    runtime. After given values, assign the address of variables to the

    pointers.

    6. Show the value of the variables and its stored

    address by pointers.

    7. Evaluate more than one expression by pointers and

    show the result.

    8. To save the program, press Escape button in the

    keyboard and enter :wq command.

    9. To compile the program edit the command

    cc filename.c

    10. If no compile time error, to run the program edit the

    command ./a. out.

    11. If no run time error, output of the program is

    displayed.

  • 7/30/2019 28795185 Fundamentals of Computer

    49/56

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 44 OF 51

    Program

    #includemain( )

    {int a,b,*p1,*p2;printf(" ENTER THE VALUE FOR A,B : ");scanf("%d%d",&a,&b);

    p1=&a;p2=&b;printf(" \n %d is stored in the address %u ",*p1,p1);printf(" \n %d is stored in the address %u ",*p2,p2);printf(" \n (*p1+*p2)*(a -*p2) = %d", (*p1+*p2)*(a-*p2));printf(" \n (*p1+*p2)/(*p1-b) = %d",(*p1+*p2)/(*p1-b));printf(" \n *p1*p2/a+b = %d",*p1*p2/a+b);printf("\n");

    }

    OUTPUT Enter the value for a,b: 12 8

    12 is stored in the address 32184666768 is stored in the address 3218466672

    (*p1+*p2)*(a-*p2) = 80(*p1+*p2)/(*p1-b) = 5

    *p1**p2/a+b = 16

    RESULT:

    Thus the program for the illustration of pointer expressions isdeveloped, executed successfully

  • 7/30/2019 28795185 Fundamentals of Computer

    50/56

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 45 OF 51

    EX NO: 9 Program for dynamic memory allocation, reallocation anddeleting.

    AIM:

    To develop the program for dynamic memory allocation to store

    information and the reallocating dynamically the same memory to store more

    information .After the deleting same memory dynamically by dynamic memory

    allocation functions.

    ALGORITHM:

    1. Open the UNIX operating system.2. Edit the command vi filename in the home directory or in

    the directory created by user. VI stands for visual, a fullscreen editor, indicates most powerful editor. File nameindicates program name.

    3. Now enter required header files and open main ( )

    function.4. Inside main ( ) function declare required variables,

    pointers and allocate a block of memory dynamically byusing malloc ( ) function.

    5. Check whether dynamically a block of memory allocatedor not.

    6. If allocated, store the information and display theinformation.

    7. Reallocate the same memory to store more informationthan before by using realloc ( ) function.

    8. Check whether reallocation of same memory dynamically

    done or not.9. If allocated, store the new information and display it.10. If no longer needed the stored information, release by

    using free ( ) function.11.To save the program, press Escape button in the

    keyboard and enter :wq command.12.To compile the program edit the command

    cc filename.c

  • 7/30/2019 28795185 Fundamentals of Computer

    51/56

    13. If no compile time error, to run the program edit thecommand ./a. out.

    14. If no run time error, output of the program is displayed.

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 46 OF 51

    Program

    #include#include#includemain( ){

    char *buffer;buffer=(char *)malloc(10*sizeof(char));

    if(buffer==0){

    printf(" Dynamically memory not allocated . . . \n");exit(1);

    }elseprintf(" Dynamically memory allocated . . . \n");strcpy(buffer,"Chennai");printf(" Buffer contains : %s \n",buffer);buffer=realloc(buffer,50);if(buffer==0)

    {printf(" Reallocation failed . . . \n");exit(1);

    }printf(" Buffer size modified . . .\n");printf(" Buffer still contains: %s \n",buffer);strcpy(buffer,"Chennai is the capital of the Tamilnadu state ");printf(" Buffer now contains: %s \n",buffer);printf(" Releasing dynamically allocated memory . . . . ");free(buffer);}

  • 7/30/2019 28795185 Fundamentals of Computer

    52/56

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 47 OF 51

    OUTPUTDynamically Memory Allocated

    Buffer contains : chennaiBuffer size modified . . .Buffer still contains: chennai

    Buffer now contains: chennai is the capital of Tamilnadu stateReleasing dynamically allocated memory . . .

    RESULT:Thus the program for dynamically memory allocation, reallocation and

    releasing the allocated memory dynamically is developed and executedsuccessfully.

  • 7/30/2019 28795185 Fundamentals of Computer

    53/56

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 48 OF 51

    EX NO: 10 Program to create file, to store information in the file and to showthe information in the file by using file handling functions.

    AIM:To develop the program to create file, to store information in the

    file and to show the information in the file by using file handling functions.

    ALGORITHM :1. Open the UNIX operating system.2. Edit the command vi filename in the home directory or in

    the directory created by user. VI stands for visual, a fullscreen editor, indicates most powerful editor. File nameindicates program name.

    3. Now enter required header files and open main ( )function.

    4. Inside main ( ) function declare required variables,file pointer. Open the file with write mode and assign to

    the file pointer.

    5. Enter number of students information to store.6. Through for( ) loop, read the one by one student

    information by using stdin keyword, represents thekeyboard and write to the given file by file pointer.

    7. Close the file using fclose ( ) function with file pointer asargument.

    8. Again open the file with read mode and assign to the filepointer.

    9. Again through same for( ) loop, read one by one studentinformation from the file by file pointer and write to thescreen by using stdout keyword, represents screen.

    10.For reading use fscanf ( ) function and for writing fprintf ( )function.

    11.Close the file using fclose ( ) function with file pointer asargument.

    12.To save the program, press Escape button in thekeyboard and enter :wq command.

    13.To compile the program edit the commandcc filename.c

  • 7/30/2019 28795185 Fundamentals of Computer

    54/56

    14. If no compile time error, to run the program edit thecommand ./a. out.

    15. If no run time error, output of the program is displayed..

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 49 OF 51

    Program

    #includemain( ){

    FILE *fp;char studname[15];int n, i,em,tm,mm,sm.scm,total;float avg;

    fp=fopen("studentdetails","w");printf(" ENTER NUMBER OF STUDENTS : ");scanf("%d",&n);printf(" enter student name and fallowing subject marks \n \n");printf(" english tamil maths science socialscience \n \n");for(i=1;i

  • 7/30/2019 28795185 Fundamentals of Computer

    55/56

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 50 OF 51

    OUTPUT

    ENTER NUMBER OF STUDENTS: 2ENTER STUDENT NAMES AND FALLOWING SUBJECT MARKS . .

    ENGLISH TAMIL MATHS SCIENCE SOCIALSCIENCE

    1: STUDENT DETAILSGnanasekar.P

    48 78 90 76 56

    2: STUDENT DETAILSVisu.L70 89 76 65 54

    STUDENT DETAILS STORED IN THE FILE . . .

    Gnanasekar.P4878

    90765634869.6

    Visu.L708976655435470.8

    RESULT:

    Thus the program for file handling by using file handling functions isdeveloped and executed successfully.

  • 7/30/2019 28795185 Fundamentals of Computer

    56/56

    .

    ISO/CSE/MANUAL/CP LBII GE 2155

    ISSUE: B REV: 00 PAGE NO: 51 OF 51