3.ds&la_record

Upload: cpprani

Post on 02-Jun-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 3.ds&la_record

    1/152

    DATA STRUCTURES

    AND

    ALGORITHMS

    1

  • 8/10/2019 3.ds&la_record

    2/152

    PROGRAM NO: 1

    DATE: 14/05/2014

    Implement Array ADT for one and two dimensions

    CLASS DIAGRAM

    PROGRAM

    #include

    using namespace std;

    class array

    {

    int ind1,ind2,alue,!a,si"e1,i,si"e2,,si"e;

    pu$lic%

    array&int , int range'(,int initalue)

    {

    if&**1)

    {

    si"e1*range'+(;

    a* new int'si"e1(;

    for&i*+;i

  • 8/10/2019 3.ds&la_record

    3/152

    else if&**2)

    {

    si"e1*range'+(;

    si"e2*range'1(;

    a*new int'si"e1!si"e2(;

    for&i*+;isi"e1)

    cout

  • 8/10/2019 3.ds&la_record

    4/152

    coutsi"e1)33&ind2>si"e2))

    cout

  • 8/10/2019 3.ds&la_record

    5/152

    cin>>ind1;

    cin>>/;

    o$18store&ind1,/);

    -

    else

    {

    coutind1;

    cin>>ind2;

    cout/;

    o$28store&ind1,ind2,/);-

    $rea;

    case 2%if&**1)

    {

    coutind1;

    t*o$18retriee&ind1);

    cout

  • 8/10/2019 3.ds&la_record

    6/152

    else

    o$28disp&);

    $rea;

    case :% $rea;

    default% cout

  • 8/10/2019 3.ds&la_record

    7/152

  • 8/10/2019 3.ds&la_record

    8/152

    PROGRAM NO: 2

    DATE: 14/05/2014

    Implement 5parse ADT

    CLASS DIAGRAM

    PROGRAM

    #include

    #include

    #define Ba/Term 1+

    using namespace std;

    class 5parseBatri/;

    class Batri/Term

    {

    pu$lic%

    friend class 5parseBatri/;

    int row,col,alue;

    -;

    class 5parseBatri/

    {

    int rows,cols,t;

    C

  • 8/10/2019 3.ds&la_record

    9/152

    pu$lic%

    Batri/Term smArray'Ba/Term(;

    5parseBatri/&int r,int c)

    {

    int i,,,n;

    rows*r;

    cols*c;

    t*+;

    *1;

    cout

  • 8/10/2019 3.ds&la_record

    10/152

    for&i*+;i

  • 8/10/2019 3.ds&la_record

    11/152

    if&sum's(8alue*+)

    s;

    -

    else

    {

    if&smArray'i(8col

  • 8/10/2019 3.ds&la_record

    12/152

    {

    sum's(8row*sm28smArray'(8row;

    sum's(8col*sm28smArray'(8col;

    sum's(8alue*sm28smArray'(8alue;

    ;

    s;

    -

    -

    if&i

  • 8/10/2019 3.ds&la_record

    13/152

    {

    cout

  • 8/10/2019 3.ds&la_record

    14/152

    cin>>c7;

    -

    return +;

    -

    OUTPUT

    1:

  • 8/10/2019 3.ds&la_record

    15/152

    PROGRAM NO: 3

    DATE: 21/05/2014

    rite a program to add two polynomials using Array8

    CLASS DIAGRAM

    PROGRAM

    #include

    using namespace std;

    class polynomial

    {

    int n;

    struct term

    {

    int coeff,e/p;

    -t'2+(;

    pu$lic%

    polynomial&);

    oid polyappend&int c,int e);

    oid polyadd&polynomial p1,polynomial p2);

    oid polydisplay&);

    -;

    polynomial%%polynomial&)

    {

    for&int i*+;i

  • 8/10/2019 3.ds&la_record

    16/152

    t'i(8coeff*+;

    t'i(8e/p*+;

    -

    n*+;

    -

    oid polynomial%%polyappend&int c,int e)

    {

    t'n(8coeff*c;

    t'n(8e/p*e;

    n;

    -

    oid polynomial%%polyadd&polynomial p1,polynomial p2){

    int i*+,*+,*+;

    if&&&p18t'+(8coeff)**+)GG&&p28t'+(8coeff)**+))

    {

    return;

    -

    w7ile&&i

  • 8/10/2019 3.ds&la_record

    17/152

    i;

    -

    -

    else

    {

    t'(8coeff*p28t'(8coeff;

    t'(8e/p*p28t'(8e/p;

    ;

    -

    ;

    -

    w7ile&i

  • 8/10/2019 3.ds&la_record

    18/152

    cout

  • 8/10/2019 3.ds&la_record

    19/152

    cin>>c7;

    -

    w7ile&c7*+);

    p48polyadd&p1,p2);

    cout

  • 8/10/2019 3.ds&la_record

    20/152

    PROGRAM NO: 4

    DATE: 21/05/2014

    Konert a Infi/ e/pression to its postfi/ eLuialent using stac

    CLASS DIAGRAM

    PROGRAM

    #include

    #include

    using namespace std;

    class postfi/

    {c7ar infi/'2+(,stac'2+(;

    int top;

    pu$lic%

    postfi/&)

    {

    top*.1;

    -

    oid read&)

    {

    int len,i;

    c7ar c7;

    coutinfi/;

    cout

  • 8/10/2019 3.ds&la_record

    21/152

    len*strlen&infi/);

    for&i*+;infi/'i(*=+=;i)

    {

    c7*infi/'i(;

    test&c7);

    -

    w7ile&top*.1)

    {

    cout

  • 8/10/2019 3.ds&la_record

    22/152

    if&top**.1)

    {

    stac'top(*c7;

    -

    else

    {

    if&stac'top(**=&=)

    {

    stac'top(*c7;

    -

    else

    {s*stac'top(;

    w7ile&priority&c7)

  • 8/10/2019 3.ds&la_record

    23/152

    else if&c**=&=)

    {

    return 1;

    -

    -

    -;

    int main&)

    {

    postfi/ p;

    p8read&);

    return +;

    -

    OUTPUT

    24

  • 8/10/2019 3.ds&la_record

    24/152

    PROGRAM NO: 5

    DATE: 04/06/2014

    Konert a Infi/ e/pression to prefi/ eLuialent using stac

    CLASS DIAGRAM

    PROGRAM

    #include

    #include

    using namespace std;class ?refi/

    {

    c7ar infi/'2+(,stac'2+(,prefi/'2+(,p'2+(;

    int top,;

    pu$lic%

    ?refi/&)

    {

    top*.1;

    *+;

    -

    oid read&)

    {

    int *+;

    int len,i;

    2:

  • 8/10/2019 3.ds&la_record

    25/152

    c7ar c7;

    coutinfi/;

    cout

  • 8/10/2019 3.ds&la_record

    26/152

    prefi/'(*c7;

    -

    else if&c7**=)=)

    {

    stac'top(*c7;

    -

    else if&c7**=&=)

    {

    w7ile&stac'top(*=)=)

    {

    prefi/'(*stac'top..(;

    -top..;

    -

    else

    {

    if&top**.1)

    {

    stac'top(*c7;

    -

    else

    {

    if&stac'top(**=&=)

    {

    stac'top(*c7;

    -

    else

    {

    s*stac'top(;

    w7ile&priority&c7)

  • 8/10/2019 3.ds&la_record

    27/152

    -

    stac'top(*c7;

    -

    -

    -

    -

    int priority&c7ar c)

    {

    if&c**==33c**=.=)

    {

    return 2;

    -else if&c**=!=33c**=6=)

    {

    return 4;

    -

    else if&c**=)=)

    {

    return 1;

    -

    -

    -;

    int main&)

    {

    ?refi/ p;

    p8read&);

    return +;

    -

    2

  • 8/10/2019 3.ds&la_record

    28/152

    OUTPUT

    2C

  • 8/10/2019 3.ds&la_record

    29/152

    PROGRAM NO: 6

    DATE: 04/06/2014

    aluate a ?ostfi/ e/pression $y using stac

    CLASS DIAGRAM

    PROGRAM

    #include

    #include

    #include

    #include

    #include

    #define si"e 2+

    using namespace std;

    class postfi/

    {

    c7ar a'si"e(;

    int al'si"e(;

    int top;

    pu$lic%

    postfi/&c7ar $'si"e()

    {

    top*.1;

    strcpy&a,$);

    -

    oid pus7&int num)

    {

    2F

  • 8/10/2019 3.ds&la_record

    30/152

    if&top**si"e.1)

    {

    cout

  • 8/10/2019 3.ds&la_record

    31/152

    else

    {

    int /*pop&);

    int y*pop&);

    int ";

    switc7&a'i()

    {

    case ==%"*y/;

    pus7&");

    $rea;

    case =.=%"*y./;

    pus7&");$rea;

    case =!=%"*y!/;

    pus7&");

    $rea;

    case =6=%"*y6/;

    pus7&");

    $rea;

    case =J=%"*pow&y,/);

    pus7&");

    $rea;

    default%cout

  • 8/10/2019 3.ds&la_record

    32/152

    int len*+;

    c7ar a'si"e(;

    couta;

    postfi/ s&a);

    for&int i*+;i

  • 8/10/2019 3.ds&la_record

    33/152

    PROGRAM NO: 7

    DATE: 11/06/2014

    9ead a 2D array&matri/) from user and store it in column maor order and retrieet7e elements $ac $y using its indices

    CLASS DIAGRAM

    PROGRAM

    #include

    using namespace std;

    class array

    {

    int a'1+(,$'1+('1+(;

    int row,col;

    pu$lic%

    oid read&)

    {

    cout

  • 8/10/2019 3.ds&la_record

    34/152

    -

    -

    -

    oid retriee&int /)

    {

    cout

  • 8/10/2019 3.ds&la_record

    35/152

    PROGRAM NO:8

    DATE: 11/06/2014

    Implement a 5ingly Oined Oist to insert G delete nodes from $egin, middle and end

    of t7e list

    CLASS DIAGRAM

    PROGRAM

    #include

    #include

    using namespace std;

    class Oist;

    class Eode

    {

    int data;

    Eode !lin;

    pu$lic%

    friend class Oist;

    -;

    class Oist

    {

    4

  • 8/10/2019 3.ds&la_record

    36/152

    Eode !Peader;

    pu$lic%

    Oist&)

    {

    Peader*ENOO;

    -

    oid insertlast&);

    oid insertfront&);

    oid insertmiddle&);

    oid deletefront&);

    oid deleteend&);

    oid deletemiddle&);oid display&);

    -;

    oid Oist%%insertlast&)

    {

    Eode !temp* new Eode;

    couttemp.>data;

    temp.>lin * ENOO;

    if&Peader**ENOO)

    Peader*temp;

    else

    {

    Eode !node*Peader;

    w7ile&node.>lin*ENOO)

    {

    node*node .>lin;

    -

    node.>lin * temp;

    -

    -

    oid Oist%%insertfront&)

    4@

  • 8/10/2019 3.ds&la_record

    37/152

    {

    Eode !temp*new Eode;

    couttemp.>data;

    temp.>lin*ENOO;

    if&Peader**ENOO)

    Peader*temp;

    else

    {

    temp.>lin*Peader;

    Peader*temp;

    -

    -

    oid Oist%%insertmiddle&)

    {

    int num;

    Eode !temp*new Eode;

    couttemp.>data;

    temp.>lin*ENOO;

    if&Peader**ENOO)

    Peader*temp;

    else

    {

    coutnum;

    Eode !node*Peader;

    w7ile&node.>lin*ENOO)

    {

    if&node.>data**num)

    {

    temp.>lin*node.>lin;

    4

  • 8/10/2019 3.ds&la_record

    38/152

    node.>lin*temp;

    -

    node*node.>lin;

    -

    -

    -

    oid Oist%% deletefront&)

    {

    Eode !node*Peader;

    if&node.>lin **ENOO)

    Peader*ENOO;

    else{

    Peader*node.>lin;

    -

    delete&node);

    -

    oid Oist%% deletemiddle&)

    {

    int num;

    Eode !temp;

    if&Peader *ENOO)

    {

    coutnum;

    Eode !node*Peader;

    if&node.>lin**ENOO)

    coutdata**num)

    4C

  • 8/10/2019 3.ds&la_record

    39/152

    {

    temp.>lin*node.>lin;

    delete&node);

    $rea;

    -

    temp*node;

    node*node.>lin;

    -

    -

    -

    -

    oid Oist%% deleteend&){

    Eode !node*Peader;

    if&node .> lin **ENOO)

    Peader*ENOO;

    else

    {

    Eode !temp;

    w7ile&node .>lin * ENOO)

    {

    temp*node;

    node * node .>lin;

    -

    temp.>lin*ENOO;

    -

    delete&node);

    -

    oid Oist%%display&)

    {

    Eode !temp*Peader;

    if&Peader**ENOO)

    cout

  • 8/10/2019 3.ds&la_record

    40/152

    else

    {

    coutlin*ENOO)

    {

    temp*temp.>lin;

    cout

  • 8/10/2019 3.ds&la_record

    41/152

    $rea;

    case %

    l8deletemiddle&);

    $rea;

    case @%

    l8deleteend&);

    $rea;

    case %

    l8display&);

    $rea;

    case C% e/it&+);

    default%cout

  • 8/10/2019 3.ds&la_record

    42/152

    OUTPUT

    :2

  • 8/10/2019 3.ds&la_record

    43/152

    :4

  • 8/10/2019 3.ds&la_record

    44/152

    ::

  • 8/10/2019 3.ds&la_record

    45/152

    :

  • 8/10/2019 3.ds&la_record

    46/152

    PROGRAM NO: 9

    DATE: 11/06/2014

    rite a program to create a sorted one way lined list wit7 n nodes8 /tend t7eprogram to insert a new node at appropriate location so t7at order does not get distur$ed8

    CLASS DIAGRAM

    PROGRAM

    #include

    using namespace std;

    int a*+;

    struct node

    {

    node !ne/t;

    int data;

    -!7ead*ENOO,!p*ENOO,!L*ENOO,!r*ENOO;

    class Oist{

    pu$lic%

    oid create&int /)

    {

    r*new node;

    r.>data*/;

    r.>ne/t*ENOO;

    :@

  • 8/10/2019 3.ds&la_record

    47/152

    if&a**+)

    {

    7ead*r;

    p*7ead;

    p.>ne/t*ENOO;

    a;

    -

    else

    {

    p*7ead;

    L*p;

    if&p.>data>r.>data){

    r.>ne/t*p;

    7ead*r;

    -

    else if&p.>datadata)

    {

    w7ile&p*ENOOGGL.>datadata)

    {

    L*p;

    p*p.>ne/t;

    if&p**ENOO)

    {

    L.>ne/t*r;

    r.>ne/t*ENOO;

    -

    else if&r.>datadata)

    {

    L.>ne/t*r;

    r.>ne/t*p;

    $rea;

    -

    :

  • 8/10/2019 3.ds&la_record

    48/152

    -

    -

    -

    -

    oid traerse&)

    {

    node !t*7ead;

    cout

  • 8/10/2019 3.ds&la_record

    49/152

    OUTPUT

    :F

  • 8/10/2019 3.ds&la_record

    50/152

    PROGRAM NO:10

    DATE: 18/06/2014

    Implement a Kircular 5ingly lined list for inserting G deleting nodes8

    CLASS DIAGRAM

    PROGRAM

    #include

    using namespace std;

    class linlist

    {

    struct node{

    int data;

    node !lin;

    -!p;

    pu$lic%

    linlist&)

    {p*ENOO;

    -

    Slinlist&)

    {

    if&p**ENOO)

    {

    return;

    +

  • 8/10/2019 3.ds&la_record

    51/152

    -

    node !temp*p,!L;

    w7ile&temp.>lin*p)

    {

    L*temp;

    temp*temp.>lin;

    delete L;

    -

    delete temp;

    -

    oid add&int num)

    {node !temp;

    temp*new node;

    temp.>data*num;

    if&p**ENOO)

    {

    temp.>lin*temp;

    p*temp;

    -

    else

    {

    temp.>lin*p.>lin;

    p.>lin*temp;

    -

    -

    int del&)

    {

    node !temp*new node;

    int item;

    if&p**ENOO)

    {

    return ENOO;

    1

  • 8/10/2019 3.ds&la_record

    52/152

    -

    temp*p.>lin;

    item*temp.>data;

    if&p.>lin**p)

    p*ENOO;

    else

    p.>lin*temp.>lin;

    delete temp;

    return item;

    -

    oid display&)

    {if&p**ENOO)

    {

    cout

  • 8/10/2019 3.ds&la_record

    53/152

    cout>c7;

    switc7&c7)

    {

    case 1%

    {

    coutnum;

    l8add&num);

    $rea;

    -case 2%

    {

    num*l8del&);

    if&num**+)

    {

    cout

  • 8/10/2019 3.ds&la_record

    54/152

    -

    w7ile&c7*:);

    return +;

    -

    OUTPUT

    :

  • 8/10/2019 3.ds&la_record

    55/152

  • 8/10/2019 3.ds&la_record

    56/152

    PROGRAM NO: 11

    DATE: 18/05/2014

    Implement 5tac using Oined Oist

    CLASS DIAGRAM

    PROGRAM

    #include

    #include

    using namespace std;

    class node

    {

    pu$lic%

    int data;

    node! ne/t;

    -;

    class 5tac

    {

    pu$lic%

    5tac&int ma/)

    {

    top*ENOO;

    ma/num*ma/;

    count*+;

    -

    oid pus7&int element)

    @

  • 8/10/2019 3.ds&la_record

    57/152

    {

    if&count**ma/num)

    coutne/t*ENOO;

    top*newTop;

    count;-

    else

    {

    newTop.>data*element;

    newTop.>ne/t*top;

    top*newTop;

    count;

    -

    -

    -

    oid pop&)

    {

    if&top**ENOO)

    cout

  • 8/10/2019 3.ds&la_record

    58/152

    -

    oid print&)

    {

    node !temp;

    temp * top;

    w7ile&temp*ENOO)

    {

    coutpop&);

    C

  • 8/10/2019 3.ds&la_record

    59/152

    $rea;

    case 4%

    s.>print&);

    $rea;

    case :%e/it&+);

    $rea;

    -

    couta;

    -

    return +;

    -

    OUTPUT

    F

  • 8/10/2019 3.ds&la_record

    60/152

    @+

  • 8/10/2019 3.ds&la_record

    61/152

    PROGRAM NO: 12

    DATE: 02/07/2014

    Implement ueue using Oined Oist

    CLASS DIAGRAM

    PROGRAM

    #include

    #include

    using namespace std;

    struct node

    {

    int data;

    struct node !lin;

    -;

    class Lueue

    {

    struct node !front ,!rear,!ptr;

    int si"e;pu$lic%

    Lueue&int ma/)

    {

    si"e*ma/;

    rear*ENOO;

    front*ENOO;

    -

    @1

  • 8/10/2019 3.ds&la_record

    62/152

    oid enLueue&int);

    oid dLueue&);

    oid display&);

    -;

    oid Lueue%%enLueue&int data)

    {

    ptr*new node;

    if&rear**ENOO)

    { front*ptr;

    -

    else

    {rear.>lin*ptr;

    ptr.>lin*ENOO;

    -

    rear*ptr;

    rear.>data*data;

    cout

  • 8/10/2019 3.ds&la_record

    63/152

    {

    ptr*front;

    front*front.>lin;

    delete ptr;

    -

    cout

  • 8/10/2019 3.ds&la_record

    64/152

    {

    case 1%

    coutdata;

    L8enLueue&data);$rea;

    case 2%

    L8dLueue&);$rea;

    case 4%

    L8display&);$rea;

    case :%

    e/it&+);

    $rea;default%

    cout

  • 8/10/2019 3.ds&la_record

    65/152

    OUTPUT

    @

  • 8/10/2019 3.ds&la_record

    66/152

    PROGRAM NO: 13

    DATE: 02/07/2014

    Implement Dou$ly Oined Oist

    CLASS DIAGRAM

    PROGRAM

    #include

    #include

    using namespace std;

    class Eode

    {

    int data;

    Eode !llin, !rlin;

    friend class D$lOist;

    -;

    class D$lOist

    {

    Eode !Peader;

    pu$lic%

    D$lOist&)

    @@

  • 8/10/2019 3.ds&la_record

    67/152

    {

    Peader * new Eode;

    Peader.>llin * Peader .>rlin *Peader;

    -

    oid insert&Eode !,Eode !);

    oid Insert&);

    oid del&);

    oid DeleteEode&Eode !);

    oid display&);

    -;

    oid D$lOist%%Insert&)

    {Eode !temp*new Eode;

    couttemp.>data;

    if&&Peader.>llin **Peader)GG&Peader .>rlin **Peader))

    insert&temp,Peader);

    else

    {

    int num;

    coutnum;

    Eode !node;

    node*Peader;

    do

    {

    node*node.>rlin;

    if&node.>data**num)

    {

    insert&temp, node);

    $rea;

    -

    -

    @

  • 8/10/2019 3.ds&la_record

    68/152

    w7ile&node.>rlin*Peader);

    -

    -

    oid D$lOist%%insert&Eode !EewEode, Eode !KurrentEode)

    {

    EewEode.>llin*KurrentEode;

    EewEode.>rlin*KurrentEode.>rlin;

    KurrentEode.>rlin.>llin*EewEode;

    KurrentEode.>rlin*EewEode;

    -

    oid D$lOist %% del&)

    {if&Peader.>llin **Peader GG Peader .>rlin **Peader)

    coutdata**num)

    {

    DeleteEode&node);

    $rea;

    -

    -

    w7ile&node.>rlin*Peader);

    -

    -

    @C

  • 8/10/2019 3.ds&la_record

    69/152

    oid D$lOist%%DeleteEode&Eode !/)

    {

    /.>llin.>rlin* /.>rlin;

    /.>rlin.>llin*/.>llin;

    delete /;

    -

    oid D$lOist%%display&)

    {

    Eode !temp*Peader;

    if&Peader.>llin**Peader GG Peader.>rlin**Peader)

    cout

  • 8/10/2019 3.ds&la_record

    70/152

    $rea;

    case 2%

    d8del&);

    $rea;

    case 4%

    d8display&);

    $rea;

    case :%

    e/it&+);

    $rea;

    default%

    cout

  • 8/10/2019 3.ds&la_record

    71/152

    OUTPUT

    1

  • 8/10/2019 3.ds&la_record

    72/152

    2

  • 8/10/2019 3.ds&la_record

    73/152

    PROGRAM NO: 14

    DATE: 02/07/2014

    Implement different traersal on Rinary Tree

    CLASS DIAGRAM

    PROGRAM

    #include

    using namespace std;

    class RTree

    {

    pu$lic%

    c7ar a'1++(;

    oid create&int);

    oid preorder&int);

    oid inorder&int);

    oid postorder&int);

    -;

    oid RTree%%create&int i)

    {

    c7ar c7;

    couta'i(;

    cout

  • 8/10/2019 3.ds&la_record

    74/152

  • 8/10/2019 3.ds&la_record

    75/152

    int main&)

    {

    RTree t;

    t8create&1);

    cout

  • 8/10/2019 3.ds&la_record

    76/152

    PROGRAM NO: 15

    DATE: 09/07/2014

    Implement a menu drien program to perform t7e following operations on a $inary

    searc7 tree%

    18 Konstruct a R5T &Konstruction $egins from an empty tree)

    28 Insert element&s) into a non empty R5T

    48 5earc7 for an element in a R5T

    :8 9etriee elements of t7e R5T in t7e sorted order

    CLASS DIAGRAM

    PROGRAM

    #include

    #include

    using namespace std;

    struct node

    {

    node !rig7t;

    node !left;

    int data;

    -;

    class R5T

    {

    struct node !root,!p;

    @

  • 8/10/2019 3.ds&la_record

    77/152

    pu$lic%

    R5T&)

    {

    root*ENOO;

    p*ENOO;

    -

    oid create&);

    oid find&int item);

    oid insert&int item);

    oid display&node !ptr);

    oid display&);-;

    oid R5T%%find&int item)

    {

    if&root**ENOO)

    {

    coutdata)

    flag*1;

    else

    ptr*ptr.>rig7t;

    -

    if&flag**1)

  • 8/10/2019 3.ds&la_record

    78/152

    coutleft * new node;

    C

  • 8/10/2019 3.ds&la_record

    79/152

    p * p.>left;

    p.>data * alue;

    p.>left * ENOO;

    p.>rig7t * ENOO;

    coutleft;

    --

    else if &alue > p.>data)

    {

    if &p.>rig7t ** ENOO)

    {

    p.>rig7t * new node;

    p * p.>rig7t;

    p.>data * alue;

    p.>left * ENOO;

    p.>rig7t * ENOO;

    coutrig7t;

    -

    -

    -

    -

    F

  • 8/10/2019 3.ds&la_record

    80/152

    c;

    -

    -

    oid R5T%%insert&int item)

    {

    node !ptr1*root,!ptr2*ENOO,!start;

    int flag*+;

    w7ile&ptr1*ENOOGGflag**+)

    {

    if&itemdata)

    {ptr2*ptr1;

    ptr1*ptr1.>left;

    -

    else if&item**ptr1.>data)

    {

    flag*1;

    coutdata*item;

    temp.>left*ENOO;

    C+

  • 8/10/2019 3.ds&la_record

    81/152

    temp.>rig7t*ENOO;

    if&root**ENOO)

    {

    root*start*temp;

    -

    if&ptr2*ENOO)

    {

    if&ptr2.>datarig7t*temp;

    else

    ptr2.>left*temp;-

    -

    -

    oid R5T%%display&)

    {

    display&root);

    -

    oid R5T%%display&node !ptr)

    {

    if&root**ENOO)

    {

    cout

  • 8/10/2019 3.ds&la_record

    82/152

    -

    int main&)

    {

    R5T t;

    int c7,n;

    do

    {

    coutc7;

    switc7&c7){

    case 1% t8create&);

    $rea;

    case 2%coutn;

    t8insert&n);

    $rea;

    case 4%coutn;

    t8find&n);

    $rea;

    case :%t8display&);

    $rea;

    case %e/it&+);

    -

    -

    w7ile&c7*);

    -

    C2

  • 8/10/2019 3.ds&la_record

    83/152

    OUTPUT

    C4

  • 8/10/2019 3.ds&la_record

    84/152

    C:

  • 8/10/2019 3.ds&la_record

    85/152

    PROGRAM NO: 16

    DATE: 10/07/2014

    rite a program to implement Insertion sort, 5election 5ort, Ru$$le 5ort for anyar$itrary set of elements &menu drien)8

    CLASS DIAGRAM

    PROGRAM

    #include

    #include

    using namespace std;

    class sort

    {

    int a'2+(,n,m;

    pu$lic%

    oid read&)

    {

    coutn;

    cout

  • 8/10/2019 3.ds&la_record

    86/152

    {

    for&int i*+;iey))

    {

    a'pos(*a'pos.1(;

    pos*pos.1;

    a'pos(*ey;

    -

    -

    -

    int min&int i)

    {

    m*i;

    for&int *i1;

  • 8/10/2019 3.ds&la_record

    87/152

    if&a'(

  • 8/10/2019 3.ds&la_record

    88/152

    58read&);

    58$u$$le&);

    58display&);

    $rea;

    case 2%cout

  • 8/10/2019 3.ds&la_record

    89/152

    OUTPUT

    CF

  • 8/10/2019 3.ds&la_record

    90/152

    PROGRAM NO: 17

    DATE: 10/07/2014

    rite a program to implement uic 5ort algorit7m

    CLASS DIAGRAM

    PROGRAM

    #include

    using namespace std;

    class Luic

    {

    int a'1+(;

    int n;

    pu$lic %

    oid read&int l);

    oid sort&int /,int y);

    int partition&int !$,int /,int y);

    oid display&);

    Luic&);

    -;

    oid Luic%%read&int l)

    {

    n*l;

    cout

  • 8/10/2019 3.ds&la_record

    91/152

    -

    -

    Luic%%Luic&)

    {

    for&int i*+;i*l)

    {

    w7ile&$'l(

  • 8/10/2019 3.ds&la_record

    92/152

    t*$'/(;

    $'/(*$'ri(;

    $'ri(*t;

    return ri;

    -

    oid Luic%%sort&int /,int y)

    {

    if&/

  • 8/10/2019 3.ds&la_record

    93/152

    return +;

    -

    OUTPUT

    F4

  • 8/10/2019 3.ds&la_record

    94/152

    LINUX

    ADMINISTRATION

    F:

  • 8/10/2019 3.ds&la_record

    95/152

    SHELL PROGRAMMING

    F

  • 8/10/2019 3.ds&la_record

    96/152

    PROGRAM NO: 1

    DATE: 14/05/2014

    rite a s7ell script to find t7e greatest among n num$ers8

    PROGRAM

    #6$in6s7

    ec7o 0nter si"e of an array0

    read n

    ec7o 0nter t7e num$ers0

    for&&i*+;i

  • 8/10/2019 3.ds&la_record

    97/152

    PROGRAM NO: 2

    DATE: 14/05/2014

    rite a s7ell script to concatinate two strings and find t7e lengt7 of t7e resultant

    string8

    PROGRAM

    #6$in6s7

    ec7o nter first string%

    read s1

    ec7o nter second string%

    read s2

    s4*Ws1Ws2

    len*Uec7o Ws4 3 wc .cU

    len*Ue/pr Wlen . 1U

    ec7o Koncatinated string is Ws4 of lengt7 Wlen

    OUTPUT

    F

  • 8/10/2019 3.ds&la_record

    98/152

    PROGRAM NO: 3

    DATE: 14/05/2014

    rite a s7ell script to find t7e net salary of an employee, w7o DA*Y of $asic pay,

    P9A *1+Y of $asic pay and ot7er allowance* Y of $asic pay8

    PROGRAM

    #6$in6$as7

    ec7o 0nter t7e Rasic ?ay0

    read $p

    7ra*Uec7o W$p ! +81 3 $cU

    da*Uec7o W$p ! +8+ 3 $cU

    oa*Uec7o W$p ! +8+ 3 $cU

    ta*Uec7o W$p W7ra Wda Woa 3 $cU

    ec7o 0Total 5alary % Wta0

    OUTPUT

    FC

  • 8/10/2019 3.ds&la_record

    99/152

    PROGRAM NO: 4

    DATE: 21/05/2014

    K7ec w7et7er a file e/ist , if its reada$le display t7e contents on t7e console or if its

    writa$le append contents to t7e file t7en display t7e contents on t7e console8

    PROGRAM

    #6$in6$as7

    ec7o enter filename

    read file

    if ' .f Wfile (

    t7en

    ec7o Wfile is present in current directory

    if ' .r Wfile (

    t7en

    ec7o Wfile is reada$le

    cat Wfile

    else

    ec7o Wfile is not reada$le

    fi

    if ' .w Wfile (

    t7en

    ec7o Wfile is writa$le

    cat >> Wfile

    ec7o T7e contents of file after appending

    cat Wfile

    else

    ec7o Wfile is not writa$le

    fi

    else

    ec7o Wfile is not present in current directory

    fi

    FF

  • 8/10/2019 3.ds&la_record

    100/152

    OUTPUT

    1++

  • 8/10/2019 3.ds&la_record

    101/152

    PROGRAM NO: 5

    DATE: 21/05/2014

    ?rint all t7e prime no=s $etween 1 to n8 7ere n is t7e user input from ey$oard8

    PROGRAM

    #6$in6$as7

    ec7o nter t7e limit

    read n

    ec7o ?rime num$ers are

    for && i*2;i

  • 8/10/2019 3.ds&la_record

    102/152

    PROGRAM NO: 6

    DATE: 21/05/2014

    Hind t7e factorial of a gien num$er as command line argument8

    PROGRAM

    #6$in6$as7

    if ' W# .ne 1 (

    t7en

    ec7o no sufficient command line argument

    else

    i*1

    f*1

    w7ile ' Wi .le W1 (

    do

    f*Ue/pr Wf ! WiU

    i*Ue/pr Wi 1U

    done

    ec7o 0T7e factorial of W1 is % Wf0fi

    OUTPUT

    1+2

  • 8/10/2019 3.ds&la_record

    103/152

    PROGRAM NO: 7

    DATE: 04/06/2014

    ?rint Hi$onacci 5eries8

    PROGRAM

    #6$in6$as7

    ec7o 0nter t7e limit0

    read num

    num1*+

    num2*1

    ec7o 0Hi$onacci series%0

    ec7o Wnum1

    ec7o Wnum2

    count*2

    w7ile ' Wcount .lt Wnum (

    do

    num4*Ue/pr Wnum1 Wnum2U

    ec7o Wnum4

    num1*Wnum2

    num2*Wnum4

    count*Ue/pr Wcount 1U

    done

    OUTPUT

    1+4

  • 8/10/2019 3.ds&la_record

    104/152

    PROGRAM NO: 8

    DATE: 11/06/2014

    ?rint Armstrong num$er $etween 1 to ++

    PROGRAM

    #6$in6$as7

    i*1

    w7ile&&i+))

    do

    a*W&&cY1+))

    $*W&&$ a!a!a))

    c*W&&c61+))

    done

    if&&$**d))

    t7en

    ec7o 0Wi0

    fi

    i*W&&i1))

    doneOUTPUT

    1+:

  • 8/10/2019 3.ds&la_record

    105/152

    PROGRAM NO: 9

    DATE: 11/06/2014

    rite a s7ell script to create a file t7at contains t7e output of ls command and count

    7ow many no8 of c and c files are aaila$le in a directory8

    PROGRAM

    #6$in6s7

    ls>newfile

    ec7o 0Eum$er of c files 0

    find !8cpp < newfile 3 wc .l

    ec7o 0Eum$er of c files 0

    find !8c < newfile 3 wc .l

    OUTPUT

    1+

  • 8/10/2019 3.ds&la_record

    106/152

    PROGRAM NO: 10

    DATE: 11/06/2014

    utput of w7o s7ould $e displayed on t7e screen wit7 alue of total no8 of users w7o

    7ae logged in displayed at t7e $ottom of t7e list8

    PROGRAM

    #6$in6s7

    w7o

    w7o 3 wc .l

    OUTPUT

    1+@

  • 8/10/2019 3.ds&la_record

    107/152

    PROGRAM NO: 11

    DATE: 18/06/2014

    rite a menu drien s7ell script to

    a) Kreate an empty file

    $) add content to an empty file

    c) display file content on t7e screen

    d) append content to an e/isting writa$le file8

    PROGRAM

    #6$in6$as7select a in KreateZanZemptyZfile AddZcontentZtoZanZemptyZfile DisplayZfileZcontent

    AppendZcontentZtoZanZe/istingZwrita$leZfile

    do

    case Wa in

    KreateZanZemptyZfile) touc7 empty;;

    AddZcontentZtoZanZemptyZfile) cat >empty;;

    DisplayZfileZcontent) cat empty;;

    AppendZcontentZtoZanZe/istingZwrita$leZfile) cat >>empty;;

    esac

    done

    OUTPUT

    1+

  • 8/10/2019 3.ds&la_record

    108/152

    PROGRAM NO: 12

    DATE: 18/06/2014

    rite a 57ell program to sort num$ers stored in a file in ascending order8

    PROGRAM

    #6$in6s7

    ec7o .n 0nter Hilename % 0

    read file

    if ' .f Wfile (

    t7en

    ec7o 0Wfile not a file0

    e/it 1

    fi

    ec7o Kontents of file

    cat Wfile

    ec7o 5orted order

    sort .n Wfile

    OUTPUT

    1+C

  • 8/10/2019 3.ds&la_record

    109/152

    PROGRAM NO: 13

    DATE: 02/07/2014

    rite a s7ell script to sort in descending order8 T7e num$ers s7ould $e gien as s7ell

    arguments8

    PROGRAM

    #6$in6s7

    if ' W# .eL + (

    t7en

    ec7o 0nter t7e arguments0

    e/it

    fi

    > a

    for i in W!

    do

    ec7o 0Wi0 >> a

    done

    ec7o 05orted data0

    sort .nr a

    OUTPUT

    1+F

  • 8/10/2019 3.ds&la_record

    110/152

    PROGRAM NO: 14

    DATE: 02/07/2014

    rite a s7ell script to sort an array of num$ers8

    PROGRAM

    #6$in6$as7

    touc7 5orting

    ec7o nter t7e limit

    read n

    ec7o nter t7e elements

    for && i*+;i> 5orting

    done

    ec7o lements in sorted order

    sort .n 5orting

    rm 5orting

    OUTPUT

    11+

  • 8/10/2019 3.ds&la_record

    111/152

    PROGRAM NO: 15

    DATE: 02/07/2014

    9ead t7e Eame and mars o$tained $y a student and calculate t7e grade6diision

    o$tained8

    PROGRAM

    #6$in6$as7

    ec7o nter your name

    read name

    ec7o nter mars in su$ectsread a $ c d e

    tot*Ue/pr Wa W$ Wc Wd We U

    ec7o Eame% Wname

    ec7o Total Bar% Wtot

    ec7o Xrade%

    if ' Wtot .ge :+ (

    t7en

    ec7o A grade

    elif ' Wtot .ge 4+ .a Wtot .lt :+ (

    t7en

    ec7o R grade

    elif ' Wtot .ge 2+ .a Wtot .lt 4+ (

    t7en

    ec7o K grade

    else

    ec7o HAIOD

    fi

    111

  • 8/10/2019 3.ds&la_record

    112/152

    OUTPUT

    112

  • 8/10/2019 3.ds&la_record

    113/152

    PROGRAM NO: 16

    DATE: 09/07/2014

    rite a program to determine w7et7er a gien year is leap year or not8 & Nse logical

    operator .a and .o )

    PROGRAM

    #6$in6s7

    ec7o nter t7e year

    read year

    a*Ue/pr Wyear Y :U

    $*Ue/pr Wyear Y 1++U

    c*Ue/pr Wyear Y :++U

    if ' Wa .eL + .a W$ .ne + .o Wc .eL + (

    t7en

    ec7o Wyear is leap year

    else

    ec7o Wyear is not leap year

    fi

    OUTPUT

    114

  • 8/10/2019 3.ds&la_record

    114/152

    PROGRAM NO: 17

    DATE: 09/07/2014

    57ell 5cript to create a menu drien calculator

    PROGRAM

    #6$in6$as7

    ec7o KAOKNOAT9

    select ar in Add 5u$ Bul Di /it

    do

    case War in

    Add)ec7o nter two num$ers

    read a $

    c*Ue/pr Wa W$U

    ec7o 9esult*Wc;;

    5u$)ec7o nter two num$ers

    read a $

    c*Ue/pr Wa . W$U

    ec7o 9esult*Wc;;

    Bul)ec7o nter two num$ers

    read a $

    c*Ue/pr Wa ! W$U

    ec7o 9esult*Wc;;

    Di)ec7o nter two num$ers

    read a $

    c*Ue/pr Wa 6 W$U

    ec7o 9esult*Wc;;

    /it) e/it;;

    !)ec7o Inalid e/pression;;

    esac

    done

    11:

  • 8/10/2019 3.ds&la_record

    115/152

    OUTPUT

    11

  • 8/10/2019 3.ds&la_record

    116/152

    PROGRAM NO: 18

    DATE: 10/07/2014

    rite a s7ell script to sort t7e gien num$ers in descending order using Ru$$le sort8

    PROGRAM

    #6$in6$as7

    ec7o nter t7e limit

    read n

    ec7o nter t7e num$ers

    for && i * +; i

  • 8/10/2019 3.ds&la_record

    117/152

    OUTPUT

    11

  • 8/10/2019 3.ds&la_record

    118/152

    PROGRAM NO: 19

    DATE: 10/07/2014

    rite a s7ell script to add records to a file called prisoner8dat8 T7e fields contained

    are to $e separated $y . 8All t7e fields alidation are as follows %

    prisoner code % s7ould $e $etween 1+++ and +++

    name % s7ould not $e $lan

    duration of sentence% s7ould $e greater t7an +

    PROGRAM

    #6$in6$as7ec7o nter prisoner code

    read pc

    ec7o nter t7e name

    read name

    ec7o nter duration of sentence

    read d

    if ' Wpc .ge 1+++ .a Wpc .le +++ (

    t7en

    if ' Wname (

    t7en

    if ' Wd .gt + (

    t7en

    ec7o Wpc>>prisoner8dat

    ec7o 0.0>>prisoner8dat

    ec7o Wname>>prisoner8dat

    ec7o 0.0>>prisoner8dat

    ec7o Wd>>prisoner8dat

    ec7o 0.0>>prisoner8dat

    ec7o 9K9D ADDD 5NKK55HNOO[

    else

    ec7o 0Duration of sentence s7ould $e >+0

    11C

  • 8/10/2019 3.ds&la_record

    119/152

    fi

    else

    ec7o 0Eame cannot $e null0

    fi

    else

    ec7o ?risoner code must $e $etween 1+++ and 2+++

    fi

    OUTPUT

    11F

  • 8/10/2019 3.ds&la_record

    120/152

    PROGRAM NO: 20

    DATE: 11/07/2014

    rite a s7ell script to eep on accepting lines of te/t and write t7e te/t into a data

    file until t7e user inputs 0end08 T7e script s7ould count t7e num$er of lines input and

    display t7em8 'Don=t use wc(

    PROGRAM

    #6$in6$as7

    ec7o nter a string t7en Type end to e/it

    read a

    count*+

    w7ile ' Wa * 0end0 (

    do

    ec7o Wa>tempfile

    cat tempfile>>file

    count*Ue/pr Wcount 1U

    read a

    doneec7o Oinecount% Wcount

    ec7o Kontents of file is

    cat file

    OUTPUT

    12+

  • 8/10/2019 3.ds&la_record

    121/152

    PROGRAM NO: 21

    DATE: 11/07/2014

    rite a 57ell script to generate t7e following series %

    1,4,2,:,4,,:,@ 8888888881++

    PROGRAM

    #6$in6$as7

    /*1

    f*+

    ec7o .n 1

    w7ile ' W/ * 1++ (

    do

    if ' Wf ** + (

    t7en

    /*Ue/pr W/ 2U

    ec7o .n 0 W/ 0

    f*1

    else

    /*Ue/pr W/ . 1U

    f*+

    ec7o .n 0 W/ 0

    fi

    done

    ec7o 0 0

    121

  • 8/10/2019 3.ds&la_record

    122/152

    OUTPUT

    122

  • 8/10/2019 3.ds&la_record

    123/152

    PROGRAM NO: 22

    DATE: 11/07/2014

    rite a Nni/ s7ell script t7at accepts an ption num$er, and t7e names of two files

    as command line arguments8 Depending on t7e option t7e following option s7ould $e

    taen8

    ption no % Action to $e taen

    1 Kopy first file to second file

    2 Koncatenate t7e files

    4 9ename 1st file as 2nd file

    : Display t7e num$er of lines in $ot7 t7e files

    PROGRAM

    #6$in6$as7

    c7*+

    if ' W# .ne 2 (

    t7en

    ec7o Insufficient arguments

    else

    ec7o 5elect an option

    select ar in K?[ KEKATIEAT 9EAB DI5?OA[ZENBR9ZHZOIE5 \IT

    do

    case War in

    K?[)cp W1 W2

    ec7o KETET5 IE HI95T HIOcat W1

    ec7o 0 0

    ec7o KETET5 IE 5KED HIO

    cat W2 ;;

    KEKATIEAT)touc7 file4

    cat W1 W2 >file4

    ec7o KEKATIEATD HIO I5

    124

  • 8/10/2019 3.ds&la_record

    124/152

    cat file4

    rm file4 ;;

    9EAB)m W1 W2

    ec7o HIO 9EABD ;;

    DI5?OA[ZENBR9ZHZOIE5)len1*Ucat W1 3wc .lU

    len2*Ucat W2 3wc .lU

    ec7o Eum$er of lines in first file is Wlen1

    ec7o Eum$er of lines in second file is Wlen2 ;;

    \IT)e/it

    esac

    donefi

    OUTPUT

    12:

  • 8/10/2019 3.ds&la_record

    125/152

    PROGRAM NO: 23

    DATE: 11/07/2014

    rite a menu drien s7ell program w7ic7 prints t7e following %

    1) Kurrent date in BB6DD6[[ format8

    2) T7e message 0Eo8 of users logged in % 0 wit7 total num$er of currently

    logged in users

    4) T7e message 0?ersonal 5tatus %0 wit7 your own logname, port num$er,

    date and time of login8

    PROGRAM#6$in6$as7

    ec7o 5elect an option

    select ar in KurrentZdate NsersZloggedZin ?ersonalZstatus \IT

    do

    case War in

    KurrentZdate)ec7o Kurrent date %

    DAT*Udate Ym6Yd6YyUec7o WDAT ;;

    NsersZloggedZin)ec7o Eum$er of users logged in %

    w7o3wc .l ;;

    ?ersonalZstatus)ec7o ?ersonal status %

    w7o am i ;;

    \IT)e/it ;;

    esac

    done

    12

  • 8/10/2019 3.ds&la_record

    126/152

    OUTPUT

    12@

  • 8/10/2019 3.ds&la_record

    127/152

    USER MANAGEMENT

    12

  • 8/10/2019 3.ds&la_record

    128/152

    DATE : 04/06/2014

    1. INSTALLING LINUX OS

    I!"#$$%& '()* CD/D+D

    1. D),$)#- " U" ISO %$

    An I5 file is a KD image file t7at will need to $e $urned $efore you can use it8

    2. ( " ISO %$

    3. ))" ()* " -%!

    nce you 7ae finis7ed $urning t7e disc, restart your computer and c7oose to $oot from t7e

    disc8

    4. T( U" )( %!"#$$%&

    nce you $oot from t7e disc, you will $e gien t7e option to try N$untu wit7out installing

    it8 T7e operating system will run from t7e disc, and you will 7ae a c7ance to e/plore t7e layout of

    t7e operating system8

    12C

  • 8/10/2019 3.ds&la_record

    129/152

    5. I!"#$$ U"

    [our computer will need at least :8 XR of free space8

    6. S" " ,%($!! )"%)

    If your computer is not connected to t7e internet ia t7ernet, you can configure your

    wireless connection in t7e ne/t step8

    7. C))! ,#" ") -) ,%" )( %!"%& )(#"%& !!"*

    If you 7ae indows installed on your system, you will $e gien a couple options on 7ow

    you]d lie to install N$untu8 [ou can eit7er install it along side your preious indows

    installation, or you can replace your indows installation wit7 N$untu8

    8. S" )( #("%"%) !%

    If you are installing N$untu alongside indows, you can use t7e slider to adust 7ow muc7

    space you would lie to designate for N$untu8

    12F

  • 8/10/2019 3.ds&la_record

    130/152

    9. C))! )( $)#"%)

    If you are connected to t7e Internet, t7is s7ould $e done automatically8 ^erify t7at t7e

    time"one displayed is correct, and t7en clic t7e Kontinue $utton8

    10. S" )( )#(- $#)".

    [ou can c7oose from a list of options, or clic t7e Detect Vey$oard Oayout $utton to 7ae

    N$untu automatically pic t7e correct

    11. E"( )( $)&% %)(*#"%).

    nter your name, t7e name of t7e computer &w7ic7 will $e displayed on t7e networ),

    c7oose a user name, and come up wit7 a password8 [ou can c7oose to 7ae N$untu automatically

    log you in, or reLuire your user name and password w7en it starts8

    12. #%" )( " %!"#$$#"%) ()!! ") )*$".nce you c7oose your login info, t7e installation will $egin8 During setup, arious tips for

    using N$untu will $e displayed on t7e screen8 nce it is finis7ed, you will $e prompt to restart t7e

    computer and N$untu will $e reloaded8

    U!%& " %-),! I!"#$$(

    18 Download t7e installer from t7e N$untu we$site8

    28 K7oose your user name and password8

    48 Klic Install to start

    :8 9estart your computer8

    14+

  • 8/10/2019 3.ds&la_record

    131/152

    DATE : 04/06/2014

    2. CREATE A OOTALE CD 'OR UUNTU OS

    5tep 1% Download I5 image of N$untu 1:8+: from Internet &42 or @: $it ersion)

    5tep 2% Insert t7e KD and select Rrasero dis $urner from das7 7ome8

    5tep 4% Klic on $urn as image option8

    5tep :% 5elect t7e image to write and also select t7e dis

    5tep % Klic create image

    141

  • 8/10/2019 3.ds&la_record

    132/152

    DATE : 04/06/2014

    3. CREATE A INSTALLED LINUX OS USING A PENDRI+E

    5tep 1% Download I5 image of N$untu 1:8+: from Internet &42 or @: $it ersion)

    5tep 2% 9ig7t clic t7e pendrie and select format option

    5tep 4% Install _Xparted ?artion ditor _ from N$untu software center

    5tep :% pen Xparted ?artion ditor software and select N5R from t7e drop down menu at t7e

    top8

    5tep % Hrom partition menu select umount and umount current file system of N5R8

    5tep @% 5elect new option

    5tep % Hrom t7e new opened window enter new si"e&to $urn I5 image)8 5elect t7e file system

    e/t26e/t46e/t:8 T7en clic add option8

    5tep C% Eow mae second partition and select file system as fat42 and t7en clic add

    5tep F% Hrom edit menu select _apply all operation`

    5tep 1+% Ee/t download and install startup dis creator

    5tep 11% pen t7e startup dis creator and select t7e source image location on t7e dis to w7ic7

    t7e I5 is to $e written

    5tep 12% Klic _mae startup dis`

    5tep 14% 9estart t7e system and select $oot from N5R to $oot 5 from N5R

    142

  • 8/10/2019 3.ds&la_record

    133/152

    DATE: 04/06/2014

    4. INSTALL LILO OOT LOADER 'OR ;OUR S;STEM

    5tep 1% nter t7e command

    < !-) #"=&" %!"#$$ $%$)

    5tep 2% pen t7e configuration file 6etc6lilo8conf and edit t7e entry under perimage

    %*#& > /))"/?*$% 3.2.035&(%#

    $#$ > "

    ())" > /-?/!-#5

    5tep 4% 9un t7e command

    < /!%/$%$) ="

    5tep :% T7en run t7e command

    < /!%/$%$)

    144

  • 8/10/2019 3.ds&la_record

    134/152

    DATE: 11/06/2014

    5. PRO+IDE A AC@GROUND IMAGE 'OR GRU MENU 'OR ;OUR

    S;STEM

    5tep 1% Oogin as super user

    5tep 2% Kopy a picture to 6$oot6gru$

    5tep 4% 9un t7e command

    < !-) -#"&(

    14:

  • 8/10/2019 3.ds&la_record

    135/152

    DATE: 11/06/2014

    6. PRO+IDE A AC@GROUND IMAGE 'OR ;OUR LOGIN INDO

    5tep 1% Oogin as super user

    5tep 2% Kopy a picture to 6usr6s7are6$acgrounds

    < /D!")/,#("%#$".& ,#("%#$".&

    14

  • 8/10/2019 3.ds&la_record

    136/152

    DATE: 11/06/2014

    7. ;OUR 'A+ORITE UOTE HAS TO E DISPLA;ED IN THE TERMINAL

    HENE+ER ;OU TA@E A NE TERMINAL

    5tep 1% Tae 8$as7rc file

    < ?%* .#!(

    5tep 2% Xie an ec7o command in it t7at specifies t7e Luote8

    ) B H#(% O*

    14@

  • 8/10/2019 3.ds&la_record

    137/152

    DATE: 18/06/2014

    8. GI+E AN ALTERNATI+E LOCATION 'OR MOUNTING PEN DRI+E

    CD DRI+E AND D+D DRI+E

    All files accessi$le in a Nni/ system are arranged in one $ig tree, t7e file 7ierarc7y, rooted

    at/8 T7ese files can $e spread out oer seeral deices8 T7e *)"command seres to attac7 t7e

    file system found on some deice to t7e $ig file tree8 Konersely, t7e *)" command will

    detac7 it again8

    T7e standard form of t7e *)"command, is *)" ="type deice dir

    T7is tells t7e ernel to attac7 t7e file system found on deice &w7ic7 is of type type) at t7e

    directory dir8 T7e preious contents &if any) and owner and mode of dir $ecome inisi$le, and as

    long as t7is file system remains mounted, t7e pat7name dir refers to t7e root of t7e file system on

    deice

    Hor mounting t7e pendrie to an alternate location add t7e following line

    to 6etc6fsta$ file8

    Hor mounting t7e pendrie to an alternate location add t7e following line to 6etc6fsta$ file8

    /-?/!-1 /)*/(#%"#/-(%? ?#" (, 0 0

    After t7at run t7e mount command

    !-) *)" /)*/(#%"#/-(%?

    Hor mounting t7e cd to an alternate location add t7e following line to 6etc6fsta$ file8

    /-?/!(0 /)*/(#%"#/- %!)9660 ())!%-)-? 0 0

    After t7at run t7e mount command

    !-) *)" /)*/(#%"#/-

    Hor mounting t7e dd to an alternate location add t7e following line to 6etc6fsta$ file8/-?/!(0 /)*/(#%"#/-?- %!)9660 () 0 0

    After t7at run t7e mount command

    !-) *)" /)*/(#%"#/-?-

    14

  • 8/10/2019 3.ds&la_record

    138/152

  • 8/10/2019 3.ds&la_record

    139/152

    DATE: 18/06/2014

    10. START XCLOC@ HEN ;OU LOG IN

    '%(!" ) " /"/()%$ !(%".

    sudo im 6etc6profile

    T #-- " )$$),%& $% ") " !(%"

    ec7o U/clocU

    A"( #--%& " $% !#? " %$.

    14F

  • 8/10/2019 3.ds&la_record

    140/152

    DATE: 18/06/2014

    11. CHEC@ THE D;NAMIC LOADED 'ILE S;STEM DRI+ERS IN ;OUR

    S;STEM

    T7e Oinu/ ernel modules are defined as pieces of code, w7ic7 can $e dynamically lined

    to t7e ernel , een after t7e system $ootup 8 T7e command lsmod lists all modules t7at are

    currently loaded 8

    $!*)-command will list dynamically loaded file system driers

    1:+

  • 8/10/2019 3.ds&la_record

    141/152

    DATE: 18/06/2014

    12. USER MANAGEMENT

    1. L)&% #! ())" #- (#" &()! #! -# ,%" %- 501 F !"- ,%" %- 555

    # groupadd d$a .g +1

    # groupadd stud .g

    2. C(#" " )$$),%& $%!" ) !(!

    U!( #* UID GID )(%& S$$ S)-#( C)**"! G()

    M#1 501 501 )( !$$ 555 M#1 !(

    useradd u +1 g +1 .c _mac1 user` d 67ome6mac1.m s 6$in6s7 X mac1

    M#2 502 501 C !$$ NULL M#2 !(

    useradd u +2 .g +1 .c _mac2 user` .d67ome6mac2 m s 6$in6cs7 mac2

    M#3 503 501 ASH S$$ 555 M#3 !(

    useradd u +4 .g +1 c _mac4 user` d67ome6mac4 m s6$in6$as7 X mac4

    U!(1 504 555 )( !$$ NULL U!(1 !(

    useradd u +: g c _user1 user` d67ome6user1 m s6$in6s7 user1

    U!(2 505 555 #! S$$ NULL U!(2 !(

    useradd u + g c _user2 user` d67ome6user2 m s6$in6$as7 user2

    3. E#*% " )"" ) " /"/#!!,- %$.

    #" /"/#!!,-

    T7e contents of t7is file 7ae t7e following format

    #*:#!!,)(-:UID:GID:!(%)(*#"%):)*-%(")(: !$$

    mac1 6$in6s7

    mac2 6$in6cs7

    mac4 6$in6$as7

    user1 6$in6s7

    user2 6$in6$as7

    1:1

  • 8/10/2019 3.ds&la_record

    142/152

    4. E#*% " )"" ) " /"/!#-), %$. N#* " "" "#" %! )- % " !)- %$-

    )( " !(! (#"-.

    #" /"/!#-),

    mac1%%%

    mac2%%%

    mac4%%%

    user1%%%

    user2%%%

    T7is is $ecause we 7ae not set password for t7e users mac1,mac2 and mac4

    5. S" #!!,)(- )( " !(! *#1 *#2 *#3 F !".passwd Bac1

    nter new NEI\ password%

    9etype new NEI\ password%

    passwd% password updated successfully

    passwd Bac2

    nter new NEI\ password%

    9etype new NEI\ password%

    passwd% password updated successfully

    passwd Bac4

    nter new NEI\ password%

    9etype new NEI\ password%

    passwd% password updated successfully

    setting password for t7ese users

    1:2

  • 8/10/2019 3.ds&la_record

    143/152

    6. S$" !(2 ()* " $%!" ) !(!. C#& " #!!,- #&%& %)(*#"%) )( !(2 !) "#"

    %" *#"! " )$$),%& %)(*#"%).

    M# %#"%? 2 -#!

    E%( 4 -#!

    N), #& " !!"* -#" %(#! 5 -#!

    # usermod f 2 e +:61F6+1

    Bodifying t7e users e/pired $y ne/t

    7. L)&)" ) $)&% !!!%). A""*" ") $)& #! !(2. #" #!

    T7e user is not a$le to login $ecause 7is account is e/pired8 nly administrator can mae

    c7anges8

    8. C#& " !$$ )( " !(2 ") )( !$$.

    # usermod .s 6$in6s7 user2

    9. D$" !(2 %$-%& %! )* -%(")( #- %! )**"!.

    # userdel .r user2

    10. L) " !(1 ,%" " $ ) # !%&$ )**#-.

    # passwd .l user1

    1:4

  • 8/10/2019 3.ds&la_record

    144/152

    DATE: 02/07/2014

    13. GI+E EXAMPLE 'OR CREATING HARD LIN@S AND SO'TLIN@S

    H#(- $%! :

    W im a$c

    W ln a$c def

    T7en type t7e command

    W ls .l a$c

    =(,=(,(== 2 (#%"# (#%"# 10 A& 12 09:24 #

    W ls .l def=(,=(,(== 2 (#%"# (#%"# 10 A& 12 09:24 -

    T7us for file def t7e num$er of lin is 2

    S)" $%! :

    W ln .s a$c 7i

    W ls .l 7i

    $(,(,(, 1 (#%"# 2 A& 1 09:30 %J =K #

    1::

  • 8/10/2019 3.ds&la_record

    145/152

    DATE: 02/07/2014

    14. ALLOING AND DEN;ING ACCESS

    U! #* ") - # !( #$$- B!(1 $)&% #!! ) #$$ "(*%#$! " )(

    ""1

    6etc6security6access8conf%

    .%N591%AOO \K?T tty1

    6etc6pam8d6login%

    account reLuired 6li$6security6pamZaccess8so

    A$$), !( B!(1 ") $)&% -(%& ,-#! ", 7 #* #- 5 .*

    6etc6security6time8conf%

    login;!;N591;+++.1++

    6etc6pam8d6login

    account reLuired 6li$6security6pamZtime8so

    D%!#$ $)&% ) #$$ !(! " ())" !( #- -%!$# " *!!#& B!!"*-( *#%"# ,?( # )(*#$ !( "(%! ") $)&%

    5tep 1% Kreate a file in 6etc as nologin8 If 6etc6nologin e/ist no ot7er users is allowed to

    login e/cept root8

    5tep 2% nce 6etc6nologin is created, add content into t7e file as ec7o _5[5TB NED9

    BAIETEAEK`8

    T7en t7e message is printed w7en non root users tries to login8

    A$$), !(! B!(1 F B!(2 ") $)&% ) #$$ -#! ", 8 #* #- 5*

    " )( !-#

    6etc6security6time8conf%

    login;!;N5913N592;Al5u+C++.1++

    6etc6pam8d6login

    account reLuired 6li$6security6pamZtime8so

    1:

  • 8/10/2019 3.ds&la_record

    146/152

    D " !(! !(1 #- !(2 !(?% #$$ ) " "%* )( $)&% ) "" #

    "" -?%

    6etc6security6time8conf

    login;!;N5913N592;AlAl++++.2:++

    6etc6pam8d6login%

    account reLuired 6li$6security6pamZtime8so

    L%*%" " *( ) ()!!! ") 25 )( # #("%$#( !(

    6etc6security6limits8conf%

    user 7ard nproc 2

    6etc6pam8d6login%

    session reLuired 6li$6security6pamZlimits8so

    1:@

  • 8/10/2019 3.ds&la_record

    147/152

    DATE: 09/07/2014

    15. CHEC@ THE CURRENT RUNLE+EL O' ;OUR S;STEM AND

    CHANGE THE DE'AULT RUNLE+EL O' ;OUR S;STEM TO 3

    A run leel is a software configuration of t7e system t7at represents t7e mode in w7ic7 your

    computer is operating8 A runleel determines w7ic7 serices are aaila$le on t7e system at any

    gien time8

    T7e possi$le run leels are

    0 H#$"

    1 !%&$ !( *)-.

    2 *$"%!( *)- ,%")" X #- ",)(%& !(?%!

    3 *$"%!( *)- ,%" ",)(%& !(?%! ,%")" X

    5 *$"%!( *)- ,%" X #- ",)( !(?%!

    6 ())"

    6etc6initta$ is t7e file associated wit7 runleel8 It is 7aing t7e format%

    %-:($?$:#"%):()!!

    t7e default entry is%

    %-:3:%%"-#$":

    To c7ec your mac7ine=s current runleel, you can run t7e 6s$in6runleel command8

    < ($?$

    To c7ange t7e default runleel edit t7e 6etc6initta$ files default runleel entry

    9

    /!%/%%" 3

    /!%/"$%%" 3

    1:

  • 8/10/2019 3.ds&la_record

    148/152

    DATE: 09/07/2014

    16. CRON AND AT

    T7e cron utility allows you to sc7edule a repetitie tas to tae place at any regular interal

    desired, and t7e at command lets you specify a one.time action to tae place at some desired time8

    At utility e/ecutes a command or multiple commands ust once at some future time8 T7e atd

    daemon runs your command at t7e specified time and mails t7e output to you8

    # U!%& ()"# (%" QH$$) ?( 5 *%"! % "(*%#$.

    im mycron

    !6 ! ! ! ! 6$in6ec7o _7ello` > 6de6pts61

    cronta$ mycron

    E" # () J)

    1. ?( 5 M%"!

    !6 ! ! ! ! ec7o Pello

    1:C

  • 8/10/2019 3.ds&la_record

    149/152

    2. ?( 5 H)(!

    + !6 ! ! ! 6$in6ec7o _7ello` > 6de6pts61

    3. ?( 5 S)-!

    Kron o$ cannot $e used to sc7edule a o$ in seconds interal8 i8e [ou cannot

    sc7edule a cron o$ to run eery seconds8 T7e alternatie is to write a s7ell script t7at uses bsleep

    command in it8

    < #" ?(5!)-!.!

    #6$in6$as7

    w7ile true

    do

    67ome6pranit7a6$acup8s7

    sleep

    done

    4. ?( 5" ,-#

    + + ! ! 67ome6pranit7a6$acup8s7

    &or)

    + + ! ! Hri 67ome6pranit7a6$acup8s7

    1:F

  • 8/10/2019 3.ds&la_record

    150/152

    5. ?( 5 *)"!

    + + 1 ,1+ ! 67ome6pranit7a6$acup8s7

    &or)

    + + 1 Bay,ct ! 67ome6pranit7a6$acup8s7

    U!%& #" )( !""%& # R*%-( M!!#&

    W at 1+%

    at> ec7o today you 7ae a meeting at 11%++

    - S-$ # #&()- C() ) ')( E?( 10 M%"!.

    !61+ ! ! ! ! 6$in6ec7o 07ello0 > 6de6pts61

    1+

  • 8/10/2019 3.ds&la_record

    151/152

  • 8/10/2019 3.ds&la_record

    152/152

    DATE: 09/07/2014

    17. AC@UP AND RESTORE

    S-$ # '$$ # ) # )$-( ") #)"( )$-( ) ?( S#"(-# 8:30*?%* ()

    4+ 2+ ! ! @ cp 67ome6pranit7a6file16! 67ome6pranit7a6file2

    ()"# ()

    ()"# =$

    )( () J) &" "- )""! ) %$1 #- %$2