CS File 12th

download CS File 12th

of 78

Transcript of CS File 12th

  • 8/12/2019 CS File 12th

    1/78

    Q1.Write a C++ program that uses an area( ) function for the calculation of area of

    triangle or a rectangle or a square. Number of sides (3 for triangle, 2 for

    rectangle and 1 for square) suggest about the shape for which area is to be

    calculated.

    Ans.

    #include#include#include#includevoid area(float);void area(float,float);void area(float,float,float);void main()

    {clrscr();

    int a;float b,c,d,e;cout

  • 8/12/2019 CS File 12th

    2/78

    area(b,c);break;

    case (3): coutc;cin>>d;area(b,c,d);break;

    default : cout

  • 8/12/2019 CS File 12th

    3/78

    Output:

    Enter the desired option:1. Square2. Rectangle

    3. Triangle2

    You selected Rectangle!Enter the sides: 23

    The area is: 6

  • 8/12/2019 CS File 12th

    4/78

    Q2. Write a C++ program that uses a function to check whether a given number isdivisible by another number or not. However, if the second number is missing,the function checks whether the given number is prime or not ?

    Ans.

    #include#include#includevoid num(int, int);void num(int);void main()

    {clrscr();int a,b,c;cout

  • 8/12/2019 CS File 12th

    5/78

    void num(int b, int c){int r;r = (b%c);cout

  • 8/12/2019 CS File 12th

    6/78

    Q3.Write a C++ program using function overloading, the function volume( ) returnsthe relevant volume and has three versions:-

    1.For cubes volume that takes one float side of the cube.2.For cylinders volume that takes float radius and float height of the

    cylinder.

    3.

    For rectangular boxs volume that takes float length, float breadth and

    float height of the box.

    Ans.

    #include#include#include

    void volume(float);void volume(float,float);void volume(float,float,float);void main()

    {clrscr();int a;float l,b,h,r;cout

  • 8/12/2019 CS File 12th

    7/78

    case (3): coutl;cin>>b;cin>>h;volume(l,b,h);break;

    default : cout

  • 8/12/2019 CS File 12th

    8/78

    Output:

    Enter the desired option:1. Cube's volume2. Cylinder's volume3. Rectangular Box's volume3

    You selected Rectangular Box's Volume!Enter the length, breadth and height: 345

    The result is: 60

  • 8/12/2019 CS File 12th

    9/78

    Q1. Define a class RESORT in C++ with the following descriptions:

    Private Members:

    Rno Room Number

    Name Customer Name

    Charges Per Day Charges

    Days Days Of Stay

    COMPUTE() A function to calculate amount

    Public Members:

    Getinfo() A function to enter content

    Displayinfo() A function to display contents andevoke COMPUTE()

    Ans.

    #include#include#includeclass Resort{

    private: int rno;char name[20];int charges;int days;float compute()

    { int amount;amount = (days*charges);if (amount>11000)

    amount = (1.02*amount);return (amount);

    Classes and Objects

  • 8/12/2019 CS File 12th

    10/78

    }public: void getinfo()

    {coutrno;coutname;coutcharges;coutdays;}

    void dispinfo(){cout

  • 8/12/2019 CS File 12th

    11/78

    Output:

    Enter the Room number: 121Enter the Customer name: Archit goelEnter the Per day charges: 10000Enter the Days of stay: 3

    The Room number is: 121The Customer's name is: Archit goelThe Charges per day are: 10000The Days of stay are: 3The Amount is: 30600

  • 8/12/2019 CS File 12th

    12/78

    Q2. Define a class in C++ with the following descriptions:

    A data member TrainNumber of type integer

    A data member Destination of type string

    A data member Distance of type float

    A data member Fuel of type float

    A member function CALFUEL( ) to calculate the value of Fuel as per the following

    criteria

    Distance Fuel

  • 8/12/2019 CS File 12th

    13/78

    if (dis>3000)fuel = 2500;return(fuel);}

    public: void feedinfo(){couttno;coutdest;coutdis;cout

  • 8/12/2019 CS File 12th

    14/78

    Output:

    Enter the Train number: 1023Enter the Destination name: MumbaiEnter the Distance: 1233The fuel required is: 250

    The Train number is: 1023The Destinations name is: Mumbai

    The Distance is: 1233

  • 8/12/2019 CS File 12th

    15/78

    Q3. Define a class TESTMATCH in C++ with the following descriptions:

    Private Members:

    TestCode of type integer

    Description of type string

    NoOfCandidates of type integer

    CenterReqd (number of centers required) of type integer

    A member function CALCULATECNTR ( ) to calculate and return the number of

    centers as (NoOfCandidates/100 + 1)

    Public Members:

    A function GETDATA ( ) to allow user to enter values for the contents andcall function CALCULATECNTR ( ) to calculate the number of centers.

    A function PUTDATA ( ) to display contents.

    Ans.

    #include#include#include

    class testmatch{

    private: int tcode;char des[20];int noc;int cr;float calculatecntr()

    {

    float a;a = (noc/100) + 1 ;return(a);}

    public: void getdata(){ couttcode;coutdes;cout

  • 8/12/2019 CS File 12th

    16/78

    cin>>noc;coutcr;cout

  • 8/12/2019 CS File 12th

    17/78

    Q4. Define a class Flight in C++ with the following descriptions:

    Private Members:

    A data member FlightNumberof type integer

    A data member Destinationof type stringA data member Distanceof float type

    A data member Fuelof type float

    A member function CalFuel ( ) to calculate the value of fuel as per the following criteria

    Distance Fuel

  • 8/12/2019 CS File 12th

    18/78

    if (dis>2000)fuel = 2200;return(fuel);}

    public: void feedinfo(){coutfno;coutdest;coutdis;cout

  • 8/12/2019 CS File 12th

    19/78

    Output:

    Enter the Flight number: 1124Enter the Destination name: BangaloreEnter the Distance: 1400The fuel required is: 1100

    The Flight number is: 1124The Destinations name is: Bangalore

    The Distance is: 1400

  • 8/12/2019 CS File 12th

    20/78

    Q5. Define a class employee in C++ which stores names of employees, hisdepartment, and his salary in public area. In the class two member functionsgetdata( ) and displaydata ( ) accept and display the data entries respectively.

    Ans.

    #include#include#includeclass employee{

    private: char name[20];char dep[10];

    int salary;public: void getdata()

    {coutname;coutdep;coutsalary;}

    void displaydata(){ cout

  • 8/12/2019 CS File 12th

    21/78

    Output:

    Enter the Name of the Employee : Archit goelEnter the Department : AdminEnter the salary: 20000

    The Name of the Employee is: Archit goelThe Department's name is: AdminThe Salary is: 20000

  • 8/12/2019 CS File 12th

    22/78

    Q6. Define a class STOCK in C++ with the following descriptions:

    Private Members:

    ICode of type integer

    Item of type string

    Price of type float

    Qtn of type integer

    Discount of type float

    A member function FindDisc ( ) to calculate the discount as per the following rule:

    If Qtn

  • 8/12/2019 CS File 12th

    23/78

    dis=10;return (dis);}

    public: void Buy(){couticode;coutitem;coutprice;coutqtn;cout

  • 8/12/2019 CS File 12th

    24/78

    Output:

    Enter the Item Code: 112Enter the Item Name: PasteEnter the Price: 10Enter the Quantity of item: 25The Discount being offered is: 0

    The Item Code is: 112The Item Name is: PasteThe Price is: 10The Quantity in stock is: 25

  • 8/12/2019 CS File 12th

    25/78

    Q1. Define a class Garments in C++ with the following descriptions:

    Private Members:

    GCode of type string

    Gtype of type string GSize of type integer

    GFabric of type string

    GPrice of type float

    A function Assign ( ) which calculates and assignsd the value of GPrice as follows:

    For the value of GFabric COTTON,

    GType Gprice(Rs.)

    TROUSERS 1300

    SHIRT 1100

    For GFabric other than COTTON the above mentioned GPrice gets reduced by 10%

    Public Members:

    A constructor to assign initial values of GCode, Gtype and Gfabric with the

    word NOT ALLOWED and GSize and Gprize with 0.

    A function Input( ) to input the values of the Data Members GCode,

    GType , GSize and GFabric and invoke the Assign( ) function.

    A function Display( ) which displays the content of all the data members

    for a Garment.

    Constructors and

    Destructors

  • 8/12/2019 CS File 12th

    26/78

    Ans.

    #include#include#include

    #includeclass garment{ private: char gcode[25];

    char gtype[25];int gsize;char gfabric[10];float gprice;void assign()

    {if (strcmp(gfabric,"Cotton")==0){ if (strcmp(gtype,"Trousers")==0)

    {gprice=1300;else if (strcmp(gtype,"Shirt")==0)

    gprice=1100;}

    else{ if(strcmp(gtype,"Trousers")==0)

    gprice=1170;else if(strcmp(gtype,"Shirt")==0)

    gprice==990;}

    cout

  • 8/12/2019 CS File 12th

    27/78

    cin>>gsize;coutgfabric;assign();}

    void display(){cout

  • 8/12/2019 CS File 12th

    28/78

    Q2. Define a class Play in C++ with the following descriptions:

    Private members of play: Playcode integer Playtitle 25 character

    Duration float Noofscenes integer

    Public members of class Play:A constructor function to initialize Duration as 45 and

    number of scenes as 5. Newplay( ) function to accept values for Playcode and

    Playtitle.

    Moreinfo( ) function to assign the values of Duration andNoofscenes with the help of corresponding values passed asparameters to this function.

    Shoplay( ) function to display all the data members on thescreen.

    Ans.#include#includeclass play{

    private: int playcode;char playtitle[25];float duration;int noofscenes;

    public: play()

    { duration=45;noofscenes=5; }

    void newplay(){coutplaycode;coutplaytitle;}

    void moreinfo(int,int)

  • 8/12/2019 CS File 12th

    29/78

    {int d,no;cout

  • 8/12/2019 CS File 12th

    30/78

    Q1. C

    Q1.Create tableFURNITURE and ARRIVALS and write SQL commands for

    the same.

    mysql> create table furniture(no int, inm char(20),typ char(20), dost date, pr int, disc int);

    Query OK, 0 rows affected (0.06 sec)

    mysql> insert into furniture values(1, 'White Lotus', 'Double Bed', '23-02-02',30000, 25);

    Query OK, 1 row affected (0.03 sec)

    mysql> insert into furniture values(2, 'Pink Feather', 'Baby Cot', '21-01-02', 7000, 20);

    Query OK, 1 row affected (0.02 sec)

    mysql> insert into furniture values(3, 'Dolphin', 'Baby Cot', '19-02-02', 9500,20);

    Query OK, 1 row affected (0.02 sec)

    mysql> insert into furniture values(4, 'Decent', 'Office Table', '01-01-02', 25000, 30);

    Query OK, 1 row affected (0.03 sec)

    mysql> insert into furniture values(5, 'Comfort Zone', 'Double Bed', '12-01-02', 25000, 25);

    Query OK, 1 row affected (0.03 sec)

    mysql> insert into furniture values(6, 'Donald', 'Baby Cot', '24-02-02', 6500, 15);

    Query OK, 1 row affected (0.03 sec)

    mysql> insert into furniture values(7, 'Royal Finish', 'Office Table', '20-02-02', 18000, 30);

    Query OK, 1 row affected (0.01 sec)

    mysql> insert into furniture values(8, 'Royal Tiger', 'Sofa', '22-02-02', 31000, 30);

    Query OK, 1 row affected (0.00 sec)

    mysql> insert into furniture values(9, 'Econo Sitting', 'Sofa', '13-12-01', 9500, 25);

    Query OK, 1 row affected (0.02 sec)

    mysql> insert into furniture values(10, 'Eating Paradise', 'Dining Table', '19-02-02', 11500, 25);

    Query OK, 1 row affected (0.03 sec)

    mysql> select * from furniture;

    Structured

    Query Language

  • 8/12/2019 CS File 12th

    31/78

    +-----+--------------------+----------------+---------------+-------+------+| no | inm | typ | dost | pr | disc |+ ----+--------------------+----------------+--------------- +--------+------+| 1 | White Lotus | Double Bed | 2023-02-02 | 30000 | 25 || 2 | Pink Feather | Baby Cot | 2021-01-02 | 7000 | 20 || 3 | Dolphin | Baby Cot | 2019-02-02 | 9500 | 20 |

    | 4 | Decent | Office Table | 2001-01-02 | 25000 | 30 || 5 | Comfort Zone | Double Bed | 2012-01-02 | 25000 | 25 || 6 | Donald | Baby Cot | 2024-02-02 | 6500 | 15 || 7 | Royal Finish | Office Table | 2020-02-02 | 18000 | 30 || 8 | Royal Tiger | Sofa | 2022-02-02 | 31000 | 30 || 9 | Econo Sitting | Sofa | 2013-12-01 | 9500 | 25 || 10 | Eating Paradise | Dining Table | 2019-02-02 | 11500 | 25 |+-----+-------------------+-----------------+---------------+-------+-------+mysql> create table arrivals(no int,inm char(20), typ char(20), dost date, pr int, disc int);

    Query OK, 0 rows affected (0.05 sec)

    mysql> insert into arrivals values(11, 'Wood Comfort', 'Double Bed', '23-03-03', 25000, 25);

    Query OK, 1 row affected (0.03 sec)

    mysql> insert into arrivals values(12, 'Old Fox', 'Sofa', '20-02-03', 17000, 20);

    Query OK, 1 row affected (0.02 sec)

    mysql> insert into arrivals values(13, 'Micky', 'Baby Cot', '21-02-03', 7500, 15);

    Query OK, 1 row affected (0.02 sec)

    mysql> select * from arrivals;

    +------+------------------+---------------+--------------+--------+-----+

    | no | inm | typ | dost | pr | disc |+------+------------------+---------------+--------------+--------+-----+| 11 | Wood Comfort | Double Bed | 2023-03-03 | 25000 | 25 || 12 | Old Fox | Sofa | 2020-02-03 | 17000 | 20 || 13 | Micky | Baby Cot | 2021-02-03 | 7500 | 15 |+------+------------------+---------------+--------------+---------+-----+

    mysql> select * from furniture where typ='Baby Cot';

    +----+----------------+------------+--------------+------+------+| no | inm | typ | dost | pr | disc |-----+-----------------+-----------+---------------+------+------+

    | 2 | Pink Feather | Baby Cot | 2021-01-02 | 7000 | 20 || 3 | Dolphin | Baby Cot | 2019-02-02 | 9500 | 20 || 6 | Donald | Baby Cot | 2024-02-02 | 6500 | 15 |+----+----------------+------------+--------------+-------+-----+

    mysql> select inm from furniture where pr>15000;

  • 8/12/2019 CS File 12th

    32/78

    +----------------+| inm |+----------------+| White Lotus || Decent || Comfort Zone |

    | Royal Finish || Royal Tiger |+----------------+mysql> select inm , typ from furniture where dot select inm, dost from furniture where disc > 25;

    +---------------+---------------+| inm | dost |+---------------+---------------+| Decent | 2001-01-02 |

    | Royal Finish | 2020-02-02 || Royal Tiger | 2022-02-02 |+----------- ----+--------------+mysql> select count(*) from furniture where typ='Sofa';

    +----------+| count(*) |+----------+| 2 |+----------+mysql> insert into arrivals values(14, 'Velvet Touch', 'Double Bed', '25-03-03', 25000, 30);

    Query OK, 1 row affected (0.01 sec)

    mysql> select * from arrivals;

    +------+-----------------+---------------- +--------------+--------+------+| no | inm | typ | dost | pr | disc |+------+-----------------+---------------- +--------------+--------+------+| 11 | Wood Comfort | Double Bed | 2023-03-03 | 25000 | 25 || 12 | Old Fox | Sofa | 2020-02-03 | 17000 | 20 || 13 | Micky | Baby Cot | 2021-02-03 | 7500 | 15 || 14 | Velvet Touch | Double Bed | 2025-03-03 | 25000 | 30 |

    mysql> select count(distinct typ) from furniture;

    +---------------------+| count(distinct typ) |+---------------------+| 5 |+---------------------+mysql> select avg(disc) from furniture where typ='Baby Cot';

    +-----------+| avg(disc) |+-----------+| 18.3333 |+-----------+

  • 8/12/2019 CS File 12th

    33/78

    mysql> select sum(pr) from furniture where dost < 12-02-02;

    +---------+| sum(pr) |+---------+| NULL |+---------+

    Q2. Create tablesCustomer & Item and write SQL commands for the same.

    Ans.

    mysql> create table item(i_id char(8) primary key, inm char(20), mfr char(3), pr int);

    Query OK, 0 rows affected (0.13 sec)

    mysql> insert into item values('PC01', 'Personal Computer', 'ABC',30000);

    Query OK, 1 row affected (0.03 sec)

    mysql> insert into item values('LC05', 'Laptop', 'ABC',55000);

    Query OK, 1 row affected (0.08 sec)

    mysql> insert into item values('PC03', 'Personal Computer', 'XYZ',32000);

    Query OK, 1 row affected (0.02 sec)

    mysql> insert into item values('PC06', 'Personal Computer', 'COM',37000);

    Query OK, 1 row affected (0.01 sec)

    mysql> insert into item values('LC03', 'Laptop', 'PQR',57000);

    Query OK, 1 row affected (0.02 sec)

    mysql> select * from item;

    +-------+-----------------------+-------+-------+

    | i_id | inm | mfr | pr |

    +-------+-----------------------+-------+-------+

    | LC03 | Laptop | PQR | 57000 || LC05 | Laptop | ABC | 55000 |

    | PC01 | Personal Computer | ABC | 30000 |

    | PC03 | Personal Computer | XYZ | 32000 |

    | PC06 | Personal Computer | COM | 37000 |

    +-------+-----------------------+-------+-------+

    mysql> create table customer (c_id int primary key, cnm char(15), city char(10), i_id char(5) references

    item(i_id));

    Query OK, 0 rows affected (0.05 sec)

    mysql> insert into customer values(01, 'N Roy', 'Delhi', 'LC03');

    Query OK, 1 row affected (0.02 sec)

  • 8/12/2019 CS File 12th

    34/78

    mysql> insert into customer values(06, 'H Singh', 'Mumbai', 'PC03');

    Query OK, 1 row affected (0.01 sec)

    mysql> insert into customer values(12, 'R Pandey', 'Delhi', 'PC06');

    Query OK, 1 row affected (0.03 sec)

    mysql> insert into customer values(15, 'C Sharma', 'Delhi', 'LC03');

    Query OK, 1 row affected (0.05 sec)

    mysql> insert into customer values(16, 'K Agarwal', 'Bangalore', 'PC01');

    Query OK, 1 row affected (0.02 sec)

    mysql> select * from customer;

    +-----+-------------+------------ +------+

    | c_id | cnm | city | i_id |+-----+-------------+------------ +------+

    | 1 | N Roy | Delhi | LC03 |

    | 6 | H Singh | Mumbai | PC03 |

    | 12 | R Pandey | Delhi | PC06 |

    | 15 | C Sharma | Delhi | LC03 |

    | 16 | K Agarwal |Bangalore | PC01 |

    +----+--------------+-----------+--------+

    mysql> select * from customer where city='Delhi';

    +------+----------+-------+------+| c_id | cnm | city | i_id |

    +------+----------+-------+------+

    | 1 | N Roy | Delhi | LC03 |

    | 12 | R Pandey | Delhi | PC06 |

    | 15 | C Sharma | Delhi | LC03 |

    mysql> select * from item where pr >= 35000 and pr

  • 8/12/2019 CS File 12th

    35/78

    mysql> select cnm,city,inm,pr from customer c,item i where c.i_id=i.i_id;

    +--------------- +---------------- +------------------------- +-------+

    | cnm | city | inm | pr |

    +--------------- +---------------- +------------------------- +-------+

    | N Roy | Delhi | Laptop | 57000 |

    | C Sharma | Delhi | Laptop | 57000 || K Agarwal | Bangalore | Personal Computer | 30000 |

    | H Singh | Mumbai | Personal Computer | 32000 |

    | R Pandey | Delhi | Personal Computer | 37000 |

    +--------------- +---------------- +------------------------- +-------+

    mysql> update item set pr= pr+1000;

    Rows matched: 5 Changed: 5 Warnings: 0

    mysql> select * from item;

    +------+-------------------------- +-------+-------+

    | i_id | inm | mfr | pr |

    +------+-------------------------- +------- +-------+

    | LC03 | Laptop | PQR | 58000 |

    | LC05 | Laptop | ABC | 56000 |

    | PC01 | Personal Computer | ABC | 31000 |

    | PC03 | Personal Computer | XYZ | 33000 |

    | PC06 | Personal Computer | COM | 38000 |

    +------+-------------------------- +-------+-------+mysql> select distinct city from customer;

    +--------------- +

    | city |

    +--------------- +

    | Delhi |

    | Mumbai |

    | Bangalore |

    +--------------- +

    mysql> select inm,max(pr),count(*) from item group by inm;

    +------------------------ +---------+----------+

    | inm | max(pr) | count(*)|

    +------------------------ +---------+----------+

    | Laptop | 58000 | 2 |

    | Personal Computer | 38000 | 3 |

    +------------------------ +---------+----------+

  • 8/12/2019 CS File 12th

    36/78

    mysql> select cnm,mfr from item,customer where item.i_id=customer.i_id;

    +--------------- +------+

    | cnm | mfr |

    +--------------- +------+

    | N Roy | PQR |

    | C Sharma | PQR || K Agarwal | ABC |

    | H Singh | XYZ |

    | R Pandey | COM |

    +--------------- +-------+

    mysql> select inm, pr*100 from item where mfr='ABC';

    +------------------------ +---------+

    | inm | pr*100 |

    +------------------------ +---------+

    | Laptop | 5600000 |

    | Personal Computer | 3100000 |+------------------------ +---------+

    Q3. Create a table GAMES and PLAYERS and also write the SQL commands.

    Ans.

    mysql> create table games (gcode int primary key, gname char(20), type char(15),no int, pm int, sd date);

    mysql> insert into games values(101, Carom Board, indoor, 2, 5000, 2004-01-23);

    mysql> insert into games values(102, Badminton, outdoor, 2, 12000, 2003-12-12);

    mysql> insert into games values(103, Table Tennis, indoor, 4, 8000, 2004-02-14);

    mysql> insert into games values(105, Chess, indoor, 2, 9000, 2004-01-01);

    mysql> insert into games values(108, Lawn Tennis, outdoor,4, 25000, 2004-03-19);

    mysql> select * from games;

    +------+--------------------- +---------------- +----+------+----------------+

    | gcode| gname | type | no | pm | sd |

    +------+--------------------- +---------------- +----+-------+---------------+

    | 101 | carom board | indoor | 2 | 5000 | 2004-01-23 |

    | 102 | badminton | outdoor | 2 | 12000 | 2003-12-12 |

    | 103 | table tennis | indoor | 4 | 8000 | 2004-02-14 |

    | 105 | chess | indoor | 5 | 9000 | 2004-01-01 |

    | 108 | lawn tennis | outdoor | 4 | 25000 | 2004-03-19 |

    +------+-------------------- +---------------- +----+-------+---------------+

    5 rows in set (0.08 sec)

    mysql> create table player (pcode int primary key, name char(20), gcode int references games (gcode));

    mysql> insert into player values(1, Nabi Ahmed, 101);

  • 8/12/2019 CS File 12th

    37/78

    mysql> insert into player values(2, Ravi Sahai, 108);

    mysql> insert into player values(3, Jatin, 101);

    mysql> insert into player values(4 ,Nazneen, 103);

    mysql> select * from player;

    +--------+--------------+-------+

    | pcode | name | gcode |+--------+--------------+-------+

    | 1 | Nabi Anand | 101 |

    | 2 | Ravi Sahai | 108 |

    | 3 | Jatin | 101 |

    | 4 | Nazneen | 103 |

    +-------+--------------+-------+

    4 rows in set (0.03 sec)

    mysql> select gname, name, pm,g.gcode from games g, player p where p.gcode=g.gco

    de and type='indoor';

    +------------------- +---------------- +------+-------+

    | gname | name | pm | gcode |

    +------------------- +---------------- +------+-------+

    | carom board | Nabi Anand | 5000 | 101 |

    | carom board | Jatin | 5000 | 101 |

    | table tennis | Nazneen | 8000 | 103 |

    +------------------- +---------------- +------+-------+mysql> select * from games where pm>7000;

    +-------+--------------+----------+------+-------+------------+

    | gcode | gname | type | no | pm | sd |

    +-------+--------------+----------+------+-------+------------+

    | 102 | badminton | outdoor | 2 | 12000 | 2003-12-12 |

    | 103 | table tennis | indoor | 4 | 8000 | 2004-02-14 |

    | 105 | chess | indoor | 5 | 9000 | 2004-01-01 |

    | 108 | lawn tennis | outdoor | 4 | 25000 | 2004-03-19 |

    +-------+--------------+----------+------+-------+------------+

    mysql> select * from games order by sd asc;

    +-------+--------------+----------+----+-------+------------+

    | gcode | gname | type | no | pm | sd |

    +-------+--------------+----------+----+-------+------------+

    | 102 | badminton | outdoor | 2 |12000 | 2003-12-12 |

    | 105 | chess | indoor | 5 | 9000 | 2004-01-01 |

    | 101 | carom board | indoor | 2 | 5000 | 2004-01-23 |

    | 103 | table tennis | indoor | 4 | 8000 | 2004-02-14 |

    | 108 | lawn tennis | outdoor | 4 | 25000 | 2004-03-19 |

    +-------+---------------+----------+----+-------+------------+5 rows in set (0.00 sec)

  • 8/12/2019 CS File 12th

    38/78

    mysql> select count(distinct no) from games;

    +--------------------+

    | count(distinct no) |

    +--------------------+

    | 3 |

    +--------------------+mysql> select max(sd), min(sd) from games;

    +------------+------------+

    | max(sd) | min(sd) |

    +------------+------------+

    | 2004-03-19 | 2003-12-12 |

    +------------+------------+

    mysql> select name, gname from games g, player p where g.gcode=p.gcode and g.pm>10000;

    +------------+-------------+

    | name | gname |

    +------------+-------------+| Ravi Sahai | lawn tennis |

    +------------+-------------+

    Q4. Create a table HOSPITAL and also write the SQL commands.

    Ans.

    mysql>create database BD;

    Database Created

    mysql> use BD;Database changed

    mysql>create table Hospital(No int, Name char(11), Age int, Department char(30), Datofdm date,

    Chargess int, Sex char(1));

    Query OK (0.36 sec)

    mysql> describe Hospital;

    +------------------- +---------------- +------+-------- +---------+-------+

    | Field | Type | Null | Key | Default | Extra |

    +------------------- +---------------- +------+-------- +---------+-------+

    | No | int(11) | YES | | NULL | |

    | Name | char(18) | YES | | NULL | || Age | int(11) | YES | | NULL | |

    | Department | char(30) | YES | | NULL | |

    | Datofadm | date | YES | | NULL | |

    | Charges | int(11) | YES | | NULL | |

    | Sex | char(1) | YES | | NULL | |

    +------------------- +---------------- +------+-------- +---------+-------+

    mysql> insert into Hospital values(1, Subash ,65, Surgery ,20100310, 300, M );

    Query OK, 1 row affected, 1 warning (0.36 sec)

    mysql> insert into Hospital values(2, Rubina ,24, Nuclear Medicine ,20100120, 250, F );

    Query OK, 1 row affected, 1 warning (0.11 sec)

  • 8/12/2019 CS File 12th

    39/78

    mysql> insert into Hospital values(3, Amit Nair ,45, Orthopedic ,20090219, 200, M );

    Query OK, 1 row affected, 1 warning (0.13 sec)

    mysql> insert into Hospital values(2, Rishi Narula ,16, Surgery ,19980101, 300, M );

    Query OK, 1 row affected, 1 warning (0.13 sec)

    mysql> insert into Hospital values(5, Shiba ,35, ENT ,19980912, 280, F );

    Query OK, 1 row affected, 1 warning (0.14 sec)

    mysql> insert into Hospital values(6, Zeba ,15, ENT ,19980224, 300, F );

    Query OK, 1 row affected, 1 warning (0.11 sec)

    mysql> insert into Hospital values(7, Karan Singh ,34, Cardiology ,19980120, 350, M );

    Query OK, 1 row affected, 1 warning (0.05 sec)

    mysql> insert into Hospital values(8, Shiela ,45, ENT ,19980223, 320, F );

    Query OK, 1 row affected, 1 warning (0.03 sec)

    mysql> insert into Hospital values(9, Ankit ,19, Cardiology ,19980912, 350, M );

    Query OK, 1 row affected, 1 warning (0.17 sec)

    mysql> insert into Hospital values(10, Kavita ,31, Nuclear Medicine ,19980119, 450, F );

    Query OK, 1 row affected, 1 warning (0.14 sec)

    mysql> update Hospital set no='4' where Name= Rishi Narula ;

    Query OK, 1 row affected (0.45 sec) Rows matched: 1 Changed: 1 Warnings: 0

    mysql> select * from Hospital;

    +----+----------------------- +------+-------------------------- +--------------+--------- +-----+

    | No | Name | Age | Department | Datofadm | Charges | Sex |

    +----+----------------------- +------+-------------------------- +--------------+--------- +-----+

    | 1 | Subash | 65 | Surgery | 2010-03-10 | 300 | M |

    | 2 | Rubina | 24 | Nuclear Medicine | 2010-01-20 | 250 | F |

    | 3 | Amit Nair | 45 | Orthopedic | 2009-02-19 | 200 | M |

    | 4 | Rishi Narula | 16 | Surgery | 1998-01-01 | 300 | M |

    | 5 | Shiba | 35 | ENT | 1998-09-12 | 280 | F |

    | 6 | Zeba | 15 | ENT | 1998-02-24 | 300 | F |

    | 7 | Karan Singh | 34 | Cardiology | 1990-01-20 | 350 | M |

    | 8 | Shiela | 45 | ENT | 1998-02-23 | 320 | F |

    | 9 | Ankit | 19 | Cardiology | 1998-09-12 | 350 | M |

    | 10 | Kavita | 31 | Nuclear Medicine | 1998-01-19 | 450 | F |

    +----+----------------------- +------+-------------------------- +--------------+---------+------+

    mysql> select * from Hospital where Department= ENT or Department= Cardiology ;

  • 8/12/2019 CS File 12th

    40/78

    +----+----------------------- +------- +--------------- +--------------+--------- +-----+

    | No | Name | Age | Department | Datofadm | Charges| Sex |

    +- --+----------------------- +------- +--------------- +--------------+----------+-----+

    | 5 | Shiba | 35 | ENT | 1998-09-12 | 280 | F |

    | 6 | Zeba | 15 | ENT | 1998-02-24 | 300 | F |

    | 7 | Karan Singh | 34 | Cardiology | 1990-01-20 | 350 | M || 8 | Shiela | 45 | ENT | 1998-02-23 | 320 | F |

    | 9 | Ankit | 19 | Cardiology | 1998-09-12 | 350 | M |

    +----+----------------------- +------- +--------------- +--------------+----------+-----+

    mysql> select name from Hospital where Department= Orthopedic and Sex= F ;

    Empty set (0.00 sec)

    mysql> select Name,Charges, Age from Hospital where Sex= F ;

    +----------+-----------+------+| Name | Charges | Age |

    +----------+-----------+------+

    | Rubina | 250 | 24 |

    | Shiba | 280 | 35 |

    | Zeba | 300 | 15 |

    | Shiela | 320 | 45 |

    | Kavita | 450 | 31 |

    +----------+-----------+------+

    mysql> select count(*) from Hospital where age>40;

    +----------+

    | count(*) |

    +----------+

    | 3 |

    +----------+

    mysql> select * from Hospital order by datofadm;

    +----+----------------------- +-----+---------------------------+----------------+---------+-----+

    | No | Name | Age| Department | Datofadm | Charges| Sex |

    +----+----------------------- +-----+---------------------------+----------------+---------+-----+

    | 7 | Karan Singh | 34 | Cardiology | 1990-01-20 | 350 | M |

    | 4 | Rishi Narula | 16 | Surgery | 1998-01-01 | 300 | M |

    | 10| Kavita | 31 | Nuclear Medicine | 1998-01-19 | 450 | F |

    | 8 | Shiela | 45 | ENT | 1998-02-23 | 320 | F |

    | 6 | Zeba | 15 | ENT | 1998-02-24 | 300 | F |

    | 5 | Shiba | 35 | ENT | 1998-09-12 | 280 | F |

    | 9 | Ankit | 19 | Cardiology | 1998-09-12 | 350 | M |

    | 3 | Amit Nair | 45 | Orthopedic | 2009-02-19 | 200 | M |

    | 2 | Rubina | 24 | Nuclear Medicine | 2010-01-20 | 250 | F |

    | 1 | Subash | 65 | Surgery | 2010-03-10 | 300 | M |+----+-------------- -------- +-----+---------------------------+----------------+---------+-----+

  • 8/12/2019 CS File 12th

    41/78

    mysql> insert into Hospital values(11, Mukul ,37, ENT ,'19980225', 300, M );

    mysql> select * from Hospital;

    +-----+---------------------- +-----+---------------------------+----------------+----------+----+

    | No | Name | Age| Department | Datofadm | Charges | Sex|

    +-----+---------------------- +-----+---------------------------+----------------+----------+----+

    | 1 | Subash | 65 | Surgery | 2010-03-10 | 300 | M || 2 | Rubina | 24 | Nuclear Medicine | 2010-01-20 | 250 | F |

    | 3 | Amit Nair | 45 | Orthopedic | 2009-02-19 | 200 | M |

    | 4 | Rishi Narula | 16 | Surgery | 1998-01-01 | 300 | M |

    | 5 | Shiba | 35 | ENT | 1998-09-12 | 280 | F |

    | 6 | Zeba | 15 | ENT | 1998-02-24 | 300 | F |

    | 7 | Karan Singh | 34 | Cardiology | 1990-01-20 | 350 | M |

    | 8 | Shiela | 45 | ENT | 1998-02-23 | 320 | F |

    | 9 | Ankit | 19 | Cardiology | 1998-09-12 | 350 | M |

    | 10| Kavita | 31 | Nuclear Medicine | 1998-01-19 | 450 | F |

    | 11| Mukul | 37 | ENT | 1998-02-25 | 300 | M |+-----+---------------------- +-----+---------------------------+-----------------+----------+----+

    mysql> select count(distinct department) from Hospital;

    +--------------------------------+

    | count(distinct department) |

    +--------------------------------+

    | 5 |

    +--------------------------------+

    mysql> select count(*) from Hospital;

    +----------+

    | count(*) |

    +----------+

    | 11 |

    +----------+

    mysql> select max(age) from Hospital where sex='F';

    +----------+

    | max(age)|

    +----------+

    | 45 |

    +----------+

    mysql> select avg(Charges) from Hospital;

    +----------------+

    | avg(Charges) |

    +----------------+

    | 309.0909 |

    +----------------+

  • 8/12/2019 CS File 12th

    42/78

    mysql> select sum(Charges) from Hospital;

    +-----------------+

    | sum(Charges) |

    +-----------------+

    | 3400 |

    +-----------------+1 row in set (0.00 sec)

  • 8/12/2019 CS File 12th

    43/78

    Q1:Write a program using pointers that accepts an array of integers and prints

    the highest

    Ans:

    #include#includevoid main(){ clrscr();

    int a[16], max;int *p;p=a;cout

  • 8/12/2019 CS File 12th

    44/78

  • 8/12/2019 CS File 12th

    45/78

    Q3: Write a program using pointers that accepts a string and converts it toupper case.

    ANS:

    #include#include#include#includevoid main(){ clrscr();

    char *str;str= new char[25];cout

  • 8/12/2019 CS File 12th

    46/78

    Q4: Write a program using pointers that accepts two values and returns thesmaller one of them.

    ANS:

    #include#includeint *small(int &, int &);void main(){ clrscr();

    int a, b, *res;couta;coutb;res=small(a,b);cout

  • 8/12/2019 CS File 12th

    47/78

    Q5: Write a program using pointers(link list) which has a self referentialstructure. The program accepts the size of the link list and thus acceptsname and age of people according to it.

    ANS:

    #include#include#includeint main(){struct stud

    {char name[20];int age;stud *next; // Self Referential Structure.};

    clrscr();stud *first, *last, *x;int i, n;

    coutn;if(n

  • 8/12/2019 CS File 12th

    48/78

    {x=new stud;coutx->name;coutx->age;x->next=NULL;last->next=x;last=x;}

    last = first;cout

  • 8/12/2019 CS File 12th

    49/78

    Q1: Write a program which has 2 classes, person and a derived class student.Both of these classes accept the concerned data from the user and displayit.

    ANS:

    #include#include#include#includeclass person{ private:

    char name[20];int age;public:

    void readdata();void dispdata();

    };class student: public person{ private:

    int roll;int marks;char cl;

    public:void getdata();void showdata();char compute();

    };

    Inheritance

  • 8/12/2019 CS File 12th

    50/78

    void person::readdata(){ cout

  • 8/12/2019 CS File 12th

    51/78

    void main(){ clrscr();

    student ob;ob.getdata();ob.showdata();getch();

    }

    Output:

    Enter name:XYZEnter age:17Enter roll number:6Enter marks:96

    Name:XYZAge:17Roll Number:6Pass/Fail: P

  • 8/12/2019 CS File 12th

    52/78

    Q1. To search for an element from an array or elements or valuesentered by user using binary search.

    ANS:

    #include

    #includevoid main{

    clrscr();int series[100];int i,n,pos,x;int first,last, middle;coutn;cout

  • 8/12/2019 CS File 12th

    53/78

    if (pos>(-1))cout

  • 8/12/2019 CS File 12th

    54/78

    Q2. To sort names entered by user in ascending order using bubblesort.

    Ans.

    #include#include#include#include

    char main(){clrscr();char a[10][10];char temp[50];cout

  • 8/12/2019 CS File 12th

    55/78

    Output:

    Enter the names:AvfTerdGhgfNjnhdbBhjklVhjdHjkWerZuhfjQwertyAvf Bhjkl Ghgf Hjk Njnhdb Qwerty Terd Wer Zuhfj

  • 8/12/2019 CS File 12th

    56/78

    Q3. To sort integer values entered by user in ascending order usinginsertion sort.

    Ans.

    #include#includemain()

    {int a[10];

    clrscr();cout

  • 8/12/2019 CS File 12th

    57/78

    Q4. To search for a value from the values entered by user using linearsearch

    Ans.

    #include#include

    void main(){int a [10];int pos, i, value;cout

  • 8/12/2019 CS File 12th

    58/78

    Q5. To sort a given array using selection sort

    Ans.

    #include#include#include#includevoid selection(int arr[], int l);void main(){

    clrscr();int num[10],i;cout

  • 8/12/2019 CS File 12th

    59/78

    Output:Please enter the values:1 8 4 12 17 5 10 2 6 7The Sorted array:1 2 4 5 6 7 8 10 12 17

  • 8/12/2019 CS File 12th

    60/78

    Q1. To add lines, display lines, count the number of words and reverse aline of a text file using a menu driven program.

    Ans.

    #include#include#include#include#include#includevoid create(){char ch;

    fstream fil;char lin[80],Q;fil.open("Stud.TXT", ios:: out);do

    { cout

  • 8/12/2019 CS File 12th

    61/78

    do{ cout

  • 8/12/2019 CS File 12th

    62/78

    cword++;}

    cout

  • 8/12/2019 CS File 12th

    63/78

  • 8/12/2019 CS File 12th

    64/78

    Ans.

    # include# include# include# include# includeclass stud{

    int rl;char nm[40];float m;public: void gtdt();

    void showdt();void moddata();int getrollno();

    };

    void stud::gtdt(void){ char ch;

    cin.get(ch);clrscr();

    cout

  • 8/12/2019 CS File 12th

    65/78

    cin>>m;}

    int stud::getrollno(){ return rl;}

    void search(int rno){ stud st1;

    int flag;fstream fin;fin.open("student.dat",ios::binary|ios::in);if(fin==NULL)

    { cout

  • 8/12/2019 CS File 12th

    66/78

    }

    void append(){ stud st1;

    fstream fin("student.dat",ios::binary|ios::app);char choice;do{ st1.gtdt();

    fin.write((char*)&st1,sizeof(stud));coutchoice;

    }while(choice=='y');fin.close();

    }

    void delet(int rno){ stud st1;

    int flag=0;fstream fin;fin.open("student.dat",ios::binary|ios::in);

    if(fin==NULL){ cout

  • 8/12/2019 CS File 12th

    67/78

    rename("temp.dat","student.dat");}

    void display(){ stud st1;

    fstream fin("student.dat",ios::in|ios::binary);if(fin==NULL){ cout

  • 8/12/2019 CS File 12th

    68/78

    }if(flag==0)

    cout

  • 8/12/2019 CS File 12th

    69/78

  • 8/12/2019 CS File 12th

    70/78

    Ans.

    #include#includeconst int max = 10;

    void push (int s[], int &t){ if(t

  • 8/12/2019 CS File 12th

    71/78

    break;case 'O' : pop(stack, top);

    break;case 'D' : stackdisp(stack, top);

    break;}

    }while (ch!= 'Q');}

    Output :P : PushO : PopD : DisplayQ : QuitEnter your choice: PData:3

    Q2.To enter a value in a stack using dynamic stack.

    Ans.

    #include#includestruct node{ int data;

    node*next;};

  • 8/12/2019 CS File 12th

    72/78

    class stack{ node*top;

    public: stack() { top=NULL; }void push();void pop();void disp();~ stack();

    };

    void stack::push(){ node*temp;

    couttemp->data;top=temp->next;top=temp;

    }

    void stack::pop(){ if(top!=NULL)

    { node*temp=top;cout

  • 8/12/2019 CS File 12th

    73/78

    delete temp;}

    }void main()

    { clrscr();stack st;char ch;do{ coutch;switch(ch){ case 'P' : st.push();

    break;case 'O' : st.pop();

    break;case 'D' : st.disp();

    break;}

    }while (ch!='Q');}

    Output:

    Enter P/O/D/Q: PData: 10Enter P/O/D/Q: PData: 11Enter P/O/D/Q: ODeleted 11Q3.Write a program using Queues

    Ans.

    #include#includeconst int max = 10;void qinsert (int q[], int &r, int f)

    { if((r+1)% max!= f){ r= (r+1)% max;

    coutq[r];}

  • 8/12/2019 CS File 12th

    74/78

  • 8/12/2019 CS File 12th

    75/78

    }while(ch!= 'Q');}Output:I : InsertD : DeleteO : DisplayQ : QuitEnter choice : IData : 451I : InsertD : DeleteO : DisplayQ : QuitEnter choice: O451I : InsertD : Delete

    O : DisplayQ : QuitEnter choice: D1 DeletedQ4.Write a program using Dynamic Queues

    Ans.

    #include#include

    struct node{ int data;

    node*next;};class queue{ node*rear,*front;

    public: queue() {rear=NULL; front=NULL; }void qinsert();

  • 8/12/2019 CS File 12th

    76/78

    void qdelete();void qdisp();~ queue();

    };

    void queue::qinsert(){ node*temp;

    temp=new node;couttemp->data;temp->next=NULL;if(rear==NULL){ rear=temp;

    front=temp;}else{ rear->next=temp;

    rear=temp;}

    }void queue::qdelete()

    { if(front!=NULL){ node*temp=front;

    cout

  • 8/12/2019 CS File 12th

    77/78

    }

    void queue::~queue(){ while(front!=NULL)

    { node*temp=front;front=front->next;delete temp;

    }}

    void main(){ clrscr();

    queue q;char ch;do{ coutch;switch(ch){ case 'I' :q. qinsert();

    break;case 'D' :q.qdelete();

    break;case 'O' :q.qdisp();

    break;}

    }while(ch!='Q');}

    Output:

    Enter I/D/O/Q: IData: 5Enter I/D/O/Q: IData: 4Enter I/D/O/Q: DDeleted 4Enter I/D/O/Q: O5

  • 8/12/2019 CS File 12th

    78/78