Computer Practical Report Class12

Embed Size (px)

Citation preview

  • 8/15/2019 Computer Practical Report Class12

    1/77

    PROGRAM NO-1

    AIM: To demonstrate classes and objects

    INPUT REQUIRED: Bank account details

    OUTPUT EXPECTED: Balance and/or details

    #include

    #include

    #include

    int n, am;

    class bank { char name[8!;

      int acc"no;

      enum acctpe{$,%&;

      'oid account"tpe(int n);

      *loat balance;

      public+

      *loat add"bal(*loat n);

    *loat ithdral (*loat k);

      'oid initial();  'oid displa();

      &acc;

    *loat bank++ add"bal(*loat n)

      {

      cout

  • 8/15/2019 Computer Practical Report Class12

    2/77

    {cout

  • 8/15/2019 Computer Practical Report Class12

    3/77

      sitch(n)

      {

    case $03 + cout

  • 8/15/2019 Computer Practical Report Class12

    4/77

      break;

      case ?+ cout

  • 8/15/2019 Computer Practical Report Class12

    5/77

    PROGRAM NO-2

    AIM: = pro7ram to print student details usin7 constructor and

    destructor.

    INPUT REQUIRED: $tudent @etails

    OUTPUT REQUIRED: $tudent @etails

    Computer Science Department/PSBE 5 2015-16

  • 8/15/2019 Computer Practical Report Class12

    6/77

    #include

    #include

    class stu

    {

     pri'ate+ char name[:!,add[:!;

      int roll,Eip;

     public+ stu ( );//%onstructor 

    Fstu( );//@estructor 

    'oid read( );

    'oid disp( );

    &;

    stu ++ stu( )

    {

    cout

  • 8/15/2019 Computer Practical Report Class12

    7/77

    coutEip;

    &

    'oid stu ++ disp( )

    {

    cout

  • 8/15/2019 Computer Practical Report Class12

    8/77

    PROGRAM NO-3

    AIM: Dro7ram to de*ine the classes D65$J, K=L6 and

    $T4@6T M to access the essential data usin7 multiple inheritance

    INPUT REQUIRED: $tudent details

    OUTPUT REQUIRED: $tudent details ith 7rade

    #include

    #include

    #include

    class person{ char name[:3!;

    Computer Science Department/PSBE 8 2015-16

  • 8/15/2019 Computer Practical Report Class12

    9/77

      int a7e;

      public+

      'oid indata()

      {cout

  • 8/15/2019 Computer Practical Report Class12

    10/77

      cout

  • 8/15/2019 Computer Practical Report Class12

    11/77

      {

      outdata();

      cout

  • 8/15/2019 Computer Practical Report Class12

    12/77

  • 8/15/2019 Computer Practical Report Class12

    13/77

  • 8/15/2019 Computer Practical Report Class12

    14/77

    'oid putdata()

    {cout

  • 8/15/2019 Computer Practical Report Class12

    15/77

    i*(strcmp(nm,-.-)R1)

    strcp(name,nm);

    i*(strcmp(cl,-.-)R1)

    strcp(%lass,cl);

    i*(mks R123)

    { marks1mks;

    i*(marks>1NC) 7rade19=9;

    else i*(marks>1P) 7rade19B9;

    else i*(marks>1C) 7rade19%9;

    else i*(marks>1A) 7rade19@9;

    else 7rade19@9; &&

    'oid main()

    { *stream *io(-stu.dat-,ios++inios++outios++binar);

    int rno;lon7 pos;char *ound19*9;

    coutrno;

    hile(R*io.eo*())

    { pos1*io.tell7();*io.read((charS)Ms3,siEeo*(s3) );

    i*(s3.7etrno()11rno)

    { s3.modi*();

    Computer Science Department/PSBE 15 2015-16

  • 8/15/2019 Computer Practical Report Class12

    16/77

    *io.seek7(pos);

    *io.rite((charS)Ms3,siEeo*(s3));

    *ound19t9;

     break; &&

    i* (*ound119*9)

    cout

  • 8/15/2019 Computer Practical Report Class12

    17/77

    PROGRAM NO-5

    AIM: Dro7ram *or deletin7 a record in a *ile.

    INPUT REQUIRED: 5ollno o* the student hose record has to be

    deleted.

    OUTPUT REQUIRED: @etails o* the record.

    #include

    #include

    #include

    #include

    Computer Science Department/PSBE 17 2015-16

  • 8/15/2019 Computer Practical Report Class12

    18/77

  • 8/15/2019 Computer Practical Report Class12

    19/77

      cin>>marks;

      i*(marks>1NC)

      7rade19=9;

      else i*(marks>1P)

      7rade19B9;

      else i*(marks>1C)

      7rade19%9;

      else i*(marks>1A)

      7rade19@9;

      else

      7rade19Q9; &

     'oid putdata()

    { cout

  • 8/15/2019 Computer Practical Report Class12

    20/77

    &s3,stud;

    int main()

    { i*stream *io(-stu.tt-,ios++in);

      o*stream *ile(-temp.tt-,ios++out);

     int rno;

     char *ound1 9*9,con*irm19n9;

     coutrno;

    hile(R*io.eo*())

    { *io.read((charS)Ms3,siEeo*(s3));

     i*(s3.7etrno()11rno)

      { s3.putdata();

      *ound19t9;

      cout

  • 8/15/2019 Computer Practical Report Class12

    21/77

    cin>>con*irm;

      i*(con*irm119n9)

      *ile.rite((charS)Ms3,siEeo*(s3)); &

    else

      *ile.rite((charS)Ms3,siEeo*(s3));

    &

    i*(*ound119*9)

    cout

  • 8/15/2019 Computer Practical Report Class12

    22/77

  • 8/15/2019 Computer Practical Report Class12

    23/77

    PROGRAM NO-6

    AIM: To count the number o* uppercase alphabets in a *ile. 

    INPUT REQUIRED: = sentence/para7raph /ord.

    OUTPUT REQUIRED: The number o* uppercase alphabets.

    #include

    #include

    #include

    'oid main( )

    { clrscr( );

    i*stream *in;

    o*stream *out;

    Computer Science Department/PSBE 23 2015-16

  • 8/15/2019 Computer Practical Report Class12

    24/77

    *in.open(-=5T%U6.TVT-,ios++in);

    *out.open(-=5T%U6.TVT-,ios++out);

    char ch,mline[3!;int uppercount1;

    cout

  • 8/15/2019 Computer Practical Report Class12

    25/77

    PROGRAM NO-7

    AIM: To *ind the output o* the 7i'en pro7ram, hich utiliEes pointers

    INPUT REQUIRED: one

    OUTPUT REQUIRED: To be *ound b eecutin7 the pro7ram

    #include

    #include

    int main( )

    {

    Computer Science Department/PSBE 25 2015-16

  • 8/15/2019 Computer Practical Report Class12

    26/77

      int ;

      int =rra[!1{A,P,3,3:&;

      int Spointer1=rra;

      *or(13;

  • 8/15/2019 Computer Practical Report Class12

    27/77

      cout

  • 8/15/2019 Computer Practical Report Class12

    28/77

    c%ar Ptr+e,t

    int en(t%tren*+e,t

    or*Counter"en(t%- 2Counter2Ptr

    *PtrCountertoupper**PtrCounter

    int main*

    int Poition0

    c%ar :ea(e.;Pointer

  • 8/15/2019 Computer Practical Report Class12

    29/77

    PROGRAM NO-9

    AIM: Dro7ram to insert a element in a arra.

    INPUT REQUIRED: =rra element and a 'alue.

    OUTPUT REQUIRED: =rra ith the inserted element.

    #include

    #include

    int Qindpos(int [ !, int, int);

    int main()

    { int ar[C!,T6L,,inde;

    Computer Science Department/PSBE 29 2015-16

  • 8/15/2019 Computer Practical Report Class12

    30/77

  • 8/15/2019 Computer Practical Report Class12

    31/77

     013;

    coutch;

    &

    cout

  • 8/15/2019 Computer Practical Report Class12

    32/77

  • 8/15/2019 Computer Practical Report Class12

    33/77

  • 8/15/2019 Computer Practical Report Class12

    34/77

    cin>>n;

    cout

  • 8/15/2019 Computer Practical Report Class12

    35/77

    PROGRAM NO-11

    AIM: To sort the 7i'en arra usin7 insertion sort.

    INPUT REQUIRED: =rra elements.

    OUTPUT REQUIRED: $orted arra.

    #include

    #include

    'oid inssort(int[!,int);

    int main()

    Computer Science Department/PSBE 35 2015-16

  • 8/15/2019 Computer Practical Report Class12

    36/77

    { int ar[C!,item,n,inde;

    coutn;

    cout

  • 8/15/2019 Computer Practical Report Class12

    37/77

  • 8/15/2019 Computer Practical Report Class12

    38/77

    PROGRAM NO-12

    AIM: To sort an arra o* inte7ers on the basis o* di7its at oneYs place.

    INPUT REQUIRED: =rra 6lements.

    OUTPUT REQUIRED: =ltered =rra.

    #include

    #include

    const int arra"siEe13;

    int main()

    Computer Science Department/PSBE 38 2015-16

  • 8/15/2019 Computer Practical Report Class12

    39/77

    { int numbers[3!;

    inti,j,temp;

    cout

  • 8/15/2019 Computer Practical Report Class12

    40/77

    cout

  • 8/15/2019 Computer Practical Report Class12

    41/77

    { clrscr();

      int a[?![?!,b[?![?!,i,j;

      cout

  • 8/15/2019 Computer Practical Report Class12

    42/77

      &

    &

    PROGRAM-14

    AIM: rite a *unction in %00 hich accepts a :@ arra o* inte7ers and

    its siEe as ar7uments and displas the elements o* middle ro and the

    elements o* middle column.

    INPUT REQUIRED: =rra 6lements

    OUTPUT REQUIRED: 6lements o* middle ro and middle column

    #include

    #include

    Computer Science Department/PSBE 42 2015-16

  • 8/15/2019 Computer Practical Report Class12

    43/77

  • 8/15/2019 Computer Practical Report Class12

    44/77

      *or(int j1;j

  • 8/15/2019 Computer Practical Report Class12

    45/77

    PROGRAM NO-15

    AIM: 

    rite *unction in %00 hich accepts an inte7er arra and siEe asar7uments and assi7n 'alues into a :@ arra o* inte7ers in the *olloin7

    *ormat +

    * the arra is 3, :, ?.The resultant :@ arra is 7i'en +

    3 : ?

    3 :

    3

    INPUT REQUIRED: nte7er arra

    Computer Science Department/PSBE 45 2015-16

  • 8/15/2019 Computer Practical Report Class12

    46/77

    OUTPUT REQUIRED: :2@ arra

    #include

    #include

    int main()

    {

    int a[3C!;

      int n;

      coutn;

      cout

  • 8/15/2019 Computer Practical Report Class12

    47/77

      int b[n![n!;

      *or (int i1;i

  • 8/15/2019 Computer Practical Report Class12

    48/77

  • 8/15/2019 Computer Practical Report Class12

    49/77

    { int stack[C!,item,top123,res;

    char ch199;

    hile(ch1199ch1199)

    { coutitem;

    res1push(stack,top,item);

     i*(res1123)

    { cout

  • 8/15/2019 Computer Practical Report Class12

    50/77

    cin>>ch; &

    return ;

    &

     int push(int stack[!, intMtop, int ele)

     { i*(top11C23)

      return 23;

    else

      { top00;

      stack[top!1ele; &

     return ;

      &

     int pop(int stack[!,intMtop)

     { int ret;

      i*(top1123)

      return 23;

      else

    { ret1stack[top!;&

    top22; &

     return ret;

    & 'oid displa(int stack[!, int top)

     { i*(top1123)

      cout

  • 8/15/2019 Computer Practical Report Class12

    51/77

  • 8/15/2019 Computer Practical Report Class12

    52/77

    &Stop,Sneptr,Ssa'e,Sptr;

    nodeScreatenenode(int);

    'oid push(nodeS);

    'oid displa(nodeS);

    'oid pop();

    int main()

    { top14UU;

    int in*;

    char ch199;

    hile(ch1199ch1199)

    { coutin*;

    neptr1createnenode(in*);

    i*(neptr114UU)

    { cout

  • 8/15/2019 Computer Practical Report Class12

    53/77

    do

    { coutnet14UU;

    return ptr;

    &

    'oid push(nodeSnp)

    { i*(top114UU)

    top1np;else

    { sa'e1top;

    top1np;

    Computer Science Department/PSBE 53 2015-16

  • 8/15/2019 Computer Practical Report Class12

    54/77

    np2>net1sa'e;

    &

    &

    'oid pop()

    { i*(top114UU)

    cout

  • 8/15/2019 Computer Practical Report Class12

    55/77

    PROGRAM NO-18

    AIM: Dro7ram *or static2ueue operation.

    INPUT REQUIRED: \ueue elements.

    OUTPUT REQUIRED: @etails o* the ueue.

    #include

    Computer Science Department/PSBE 55 2015-16

  • 8/15/2019 Computer Practical Report Class12

    56/77

    #include

    int 5emo'e(int [!);

    int nsert(int [!,int);

    'oid @ispla(int[!, int, int);

    const siEe1C;

    int \ueue[siEe!, *ront123, rear123;

    'oid main()

    {

    clrscr();

    int tem, res,choice;

    char ch199;

    hile(ch1199ch1199)

    { couttem;

    res1nsert(\ueue,tem);

    i*(res1123)

    {

    Computer Science Department/PSBE 56 2015-16

  • 8/15/2019 Computer Practical Report Class12

    57/77

    cout

  • 8/15/2019 Computer Practical Report Class12

    58/77

    else

    cout

  • 8/15/2019 Computer Practical Report Class12

    59/77

    else

    { rear00;

    \ueue[rear!1ele; &

    return ;

    &

    //@eletion

    int 5emo'e (int \ueue[!)

    { int ret;

    i* (*ront1123)

    return 23;

    else

    {

    ret 1\ueue[*ront!;

    i* (*ront11rear)

    *ront1rear123;

    else

    *ront00; &

    Computer Science Department/PSBE 59 2015-16

  • 8/15/2019 Computer Practical Report Class12

    60/77

    return ret; &

    //@ispla

    'oid @ispla(int \ueue[!,int *ront, int rear)

    {

    i* (*ront1123)

    { cout

  • 8/15/2019 Computer Practical Report Class12

    61/77

    PROGRAM NO-19

    AIM: To insert and delete in the 7i'en dnamic ueue.

    INPUT REQUIRED: Uinked ueue, element.

    OUTPUT REQUIRED: @ispla o* linked ueue a*ter insertion and

    deletion.

    #include

    #include

    Computer Science Department/PSBE 61 2015-16

  • 8/15/2019 Computer Practical Report Class12

    62/77

    struct ode { int in*o;

      ode S net;

      & S*ront, Sneptr, Ssa'e, Sptr, Srear;

     odeScreate(int n)

    { ptr1ne ode;

      ptr2>in*o1n; ptr2>net14UU;

      return ptr;

    &

    'oid displa(odeSnp)

    { hile(npR14UU)

    { cout

  • 8/15/2019 Computer Practical Report Class12

    63/77

     &

    'oid delnode()

    { i*(*ront114UU)

    cout

  • 8/15/2019 Computer Practical Report Class12

    64/77

    eit(3); &

      nsert(neptr);

      coutch;

      &

    sstem(-cls-);

    do

    {cout

  • 8/15/2019 Computer Practical Report Class12

    65/77

  • 8/15/2019 Computer Practical Report Class12

    66/77

     S QL 1

    Ta!" S"#$"% a#$ %"&'('"#)

    %reate database table;

    use table;

    create table sender;

    ( $ender@ inte7er,

      $endername char(?),

      $ender=ddress char(A),

      $ender%it char(:)

    );

    nsert into sender

    ]alues ( 3,Y5^ain;,Y=B% aptsY,Ye @elhiY);//Jther 'alues ha'e been

    inserted usin7 the same commandsselectS*rom sender;

    create table recipient

      ( 5ecd int,

      $enderd int,

      5e%ame char(3C),

    Computer Science Department/PSBE 66 2015-16

  • 8/15/2019 Computer Practical Report Class12

    67/77

  • 8/15/2019 Computer Practical Report Class12

    68/77

    A#+: $elect rec@, $enderame, $ender=ddress, 5ecame, 5ec=ddress

    *rom $ender, 5ecipient here $ender.$enderid15ecipient.5enderd;

    ,'''* To displa the sender details in ascendin7 order o* $enderame.

    A#+: $elect S *rom $ender order b $enderame;

    ,'* To displa number o* 5ecipients *rom each cit.

    A#+: $elect 5ec%it,%ount(S) *rom 5ecipient 7roup b 5ec%it;

    SQL2

    Ta!" ../+ a#$ I++"$

    TJ %56=T6 T=BU6 BJJ_$+

    %reate database book;

    Computer Science Department/PSBE 68 2015-16

  • 8/15/2019 Computer Practical Report Class12

    69/77

  • 8/15/2019 Computer Practical Report Class12

    70/77

  • 8/15/2019 Computer Practical Report Class12

    71/77

  • 8/15/2019 Computer Practical Report Class12

    72/77

    %56=T6 T=BU6 %J$KJ5 

    ( %nor %X=5(?),

      %norame %X=5(?),  %nor =ddress %X=5(?),

      %it %X=5(?));

    $65T TJ %J$KJ5(%nor@,%norame,%nor=ddress,%it)

    ]=U46$(`@3Y,Y5 sin7halY,Y:A,=B% 6ncla'e `,Y6 @6UXY);

    =UU JTX65 ]=U46$ =56 $65T6@ $LU=5U

    %J$KJ5

    %56=T6 T=BU6 %J$K66

    ( %nee@ %X=5(?),

      %nor@ %X=5(?),

      %neeame %X=5(?),

      %nee=ddress %X=5(?),

      %nee%it %X=5(?))

    Computer Science Department/PSBE 72 2015-16

  • 8/15/2019 Computer Practical Report Class12

    73/77

    $65T TJ

    %J$K66(%nee@,%nor@,%neeame,%nee=ddress,%nee%it)

    ]=U46$ (`L4CY,Y@3Y,Y5ahul_ishore`,YC,Dark

    a'enueY,L4LB=Y);

    =UU JTX65 ]=U46$ =56 $65T6@ $LU=5U

    QUERIES:

     ,'* To displa the names o* all consi7nors *rom Lumbai.

    A#++ $elect %norame *rom %onsi7nor here cit1GLumbaiG;

    ,''* To displa the cnee@, cnorame, cnor=ddress, %neeame,

    %nee=ddress *or e'er %onsi7nee.

    A#+: $elect %need, %norame, %nor=ddress, %neeame,

    %nee=ddress *rom %onsi7nor,%onsi7nee here

    %onsi7nor.%nord1%onsi7nee.%nord;

    Computer Science Department/PSBE 73 2015-16

  • 8/15/2019 Computer Practical Report Class12

    74/77

    ,'''* To displa the consi7nee details in ascendin7 order o* %neeame.

    A#+: $elect S *rom %onsi7nee

    Jrder b %neeame =sc;

    ,'* To displa number o* consi7nors *rom each cit.

    A#+ $elect cit, count(S) *rom %onsi7nor 7roup b cit;

    Computer Science Department/PSBE 74 2015-16

  • 8/15/2019 Computer Practical Report Class12

    75/77

    SQL 4

    Ta!" I)" a#$ C+)."%

    %onsider the *olloin7 tables tem and %ustomer. rite $\U commands

    *or the statement (i) to (i') and 7i'e outputs *or $\U ueries (') to ('iii)

      T6L

     

    CUSTOMER 

     

    (i) To displa the details o* those %ustomers hose cit is @elhi.

    =ns+ $elect all *rom %ustomer here %it1G@elhiG

    Computer Science Department/PSBE 75 2015-16

  • 8/15/2019 Computer Practical Report Class12

    76/77

  • 8/15/2019 Computer Practical Report Class12

    77/77