computer practical (c++ programs) for cbse xii practical exams

Upload: shiladitya

Post on 26-Feb-2018

230 views

Category:

Documents


1 download

TRANSCRIPT

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    1/74

    COMPUTER PRACTICAL

    2015-16AISSCE EXAMINATION

    SUBMITTED BY:

    Name:

    Boards Roll No:

    Class: XII

    School:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    2/74

    Acknowledgement

    I am extremely thankful to the Principal for herencouragement and for all the facilities that she provided

    for this project work and Computer teachers XYZ, of ABC

    for giving me the opportunity for this project work.

    I am very thankful to them for their advice and guidance

    during the course of my project work.

    Signature of Candidate

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    3/74

    Certificate

    This is to certify that X, student of class XII of ABC School

    has completed the Computer Practical during the

    academic year 2015-2016 towards partial fulfillment of

    credit for the Computer Project of AISSCE 2016 and

    submitted the satisfactory report as completed in the

    following pages under my supervision and does notinvolve in plagiarism of any kind. The reference taken in

    making this project has been declared at the end of this

    report.

    ___________________

    Teachers Signature

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    4/74

    Index

    Sl.

    no

    Date Programs Page

    no.

    Signature Remarks

    1 21/8/15

    Write constructor and destructor definition

    (for a class) that should display the object

    number being created/destroyed of this

    type

    1

    2 28/8/15Program to illustrate access control of

    inherited members in the privately derived

    class

    3

    3 5/9/15Calculating Sum and Product of two

    numbers using Inheritance6

    4 12/9/15Function Overloading to calculate the area

    of a circle, rectangle and triangle9

    5 19/9/15

    Program to create a text file and then create

    another text file by converting each line of

    the newly created text file into an uppercase

    string

    12

    6 26/9/15 Program to append data in a file 15

    7 29/9/15 Bubble Sort 18

    8 1/10/15 Program to demonstrate Queue using Array 20

    9 4/10/15 Pushing and Popping in Stack-Array 25

    10 7/10/15 Insertion in Queue 29

    11 15/10/15 Deletion in Array-Queue 32

    12 17/10/15Addition and deletion of new books using

    linked list36

    13 19/10/15 Program to demonstrate the sum of twomatrices

    40

    14 25/10/15 Program to find the length of the string 43

    15 27/10/15Program to find the occurrence of character

    in the string46

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    5/74

    16 31/10/15A program to illustrate Multiple Inheritance

    49

    17 2/11/15

    Program to create two arrays to store roll

    numbers and marks of desired students,

    whose number would be known at run time

    53

    18 5/11/15Function to display the elements which lie

    on middle of row and column55

    19 10/11/15Program to check whether the string is

    palindrome or not58

    20 21/11/15Program to check whether the two strings

    are equal or not61

    21 25/11/15

    Program to illustrate working of default

    arguments. Calculate interest amount

    making use of default arguments

    64

    22 1/12/15 SQL Program for TABLE: STUDENT 66

    23 7/12/15K-Map (SOP)

    70

    24 7/12/15K-Map (POS)

    71

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    6/74

    Write constructor and destructor definition for a class) that should

    display the object number being created/destroyed of this type:

    #include

    #include

    class A

    {

    static int count;

    public:

    A()

    {

    count++;

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    7/74

    Output of the program for writing constructor and destructor

    definition for a class) that should display the object number being

    created/destroyed of this type:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    8/74

    Program to illustrate access control of inherited members in the

    privately derived class:

    #include

    #include

    #include

    const int LEN=25;

    class Employee

    {

    private:

    char name[LEN];

    unsigned long enumb;

    public:void getdata()

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    9/74

    class Manager:public Employee

    {

    private:

    char title[LEN];

    public:void getdata()

    {

    Employee::getdata();

    getbasic();

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    10/74

    Output of the program to illustrate access control of inherited

    members in the privately derived class:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    11/74

    Calculating Sum and Product of two numbers using Inheritance:

    #include

    #include

    class Sum[

    public:

    int a,b,c;

    void getdata();

    void calc();

    void show();

    };

    void Sum::getdata(){

    couta>>b;

    }

    void Sum::calc()

    {

    c=a+b;

    }void Sum::show()

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    12/74

    p=a*b;

    }

    void SumProduct::showp()

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    13/74

    Output of the program for calculating Sum and Product of two

    numbers using Inheritance

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    14/74

    Function Overloading to calculate the area of a circle, rectangle

    and triangle:

    #include#include

    #include

    #include

    void area(float r)

    {

    float area;

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    15/74

    switch(opt)

    {

    case 1:coutr;

    area(r);break;

    case 2:coutl>>b;

    area(l,b);

    break;

    case 3:coutx;

    couty;

    coutz;

    area(x,y,z);

    break;

    default:cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    16/74

    Output of the program for Function Overloading to calculate the

    area of a circle, rectangle and triangle:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    17/74

    Program to create a text file and then create another text file by

    converting each line of the newly created text file into an

    uppercase string:

    # include

    # include

    # include

    # include

    void main()

    {

    char fname[20];

    char str[80], ch = 'y';

    int count;

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    18/74

    }

    newfile.close();

    temp.close();

    clrscr();

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    19/74

    Output of the program to create a text file and then create another text file

    by converting each line of the newly created text file into an uppercase

    string:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    20/74

    Program to append data in a file:

    #include

    #include#include

    class stu

    {

    int rollno;

    char name[25];

    char Class[4];

    float marks;

    char grade;

    public:

    void getdata()

    {

    coutrollno;

    coutname;

    coutClass;coutmarks;

    if(marks>=75)

    grade=A;

    else if(marks>=60)

    grade=B;

    else if(marks>=50)

    grade=C;else if(marks>=40)

    grade=D;

    else

    grade=E;

    }

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    21/74

    void putdata()

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    22/74

    Output of the program to append data in a file:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    23/74

    Bubble Sort:

    #include

    #includevoid main()

    {

    int i,a[10],t,j;

    clrscr();

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    24/74

    Output of Bubble Sort:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    25/74

    Program to demonstrate Queue using Array:

    #include

    #include

    #include

    #define SIZE 5

    int rear=-1, front=-1;

    void main()

    {

    void insert(int q[], int s, int num);

    void delete_Q(int q[]);

    void show(int q[]);

    int que[SIZE],ch,x;

    while(1)

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    26/74

    if(rear==-1)

    {

    front=rear=0;

    q[rear]=num;

    }else if(rear==s-1)

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    27/74

    void show(int q[])

    {

    int i;

    if(front==-1)

    {cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    28/74

    Output of the program to demonstrate Queue using Array:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    29/74

    Output of the program to demonstrate Queue using Array:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    30/74

    Pushing and Popping in Stack-Array:

    #include

    #include

    #include

    #include

    struct Node

    {

    int info;

    Node*next;

    }

    *top,*newptr,*save,*ptr;

    Node*Create_New_Node(int);

    void Push(Node*);

    void Display(Node*);

    void Pop();

    void main()

    {

    top=NULL;

    int inf;

    char ch=y;while(ch==y || ch==Y)

    {

    coutinf;

    newptr=Create_New_Node(inf);

    if(newptr==NULL)

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    31/74

    cin>>ch;

    }

    system(cls);

    do

    {cout next=NULL;return ptr;

    }

    void Push(node*np)

    {

    If(top=NULL)

    top=np;

    else

    {save=top;

    top=np;

    np -> next=save;

    }

    }

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    32/74

    void Pop()

    {

    If(top==NULL)

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    33/74

    Output of the program for Pushing and Popping in Stack-Array:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    34/74

    Insertion in Queue:

    #include

    #include

    #include

    int Insert_in_Q(int [],int);

    void Display(int [], int, int);

    const int size=50;

    int Queue[size], front=-1, rear=-1;

    void main()

    {

    int Item,res;

    char ch='y';

    clrscr();

    while(ch=='y' || ch=='Y')

    {

    coutItem;

    res=Insert_in_Q(Queue,Item);

    if(res==-1){

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    35/74

    if(rear==size-1)

    return-1;

    else if(rear==-1)

    {

    front=rear=0;Queue[rear]=ele;

    }

    else

    {

    rear++;

    Queue[rear]=ele;

    }

    getch();}

    void Display(int Queue[], int front, int rear)

    {

    if(front==-1)

    return;

    for(int i=front;i

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    36/74

    Output of the program for Insertion in Queue:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    37/74

    Deletion in Array-Queue:

    #include

    #include

    #include

    #include

    int Remove(int []);

    int Insert(int [],int);

    void Display(int [],int,int);

    const int size=50;

    int Queue[size],front=-1,rear=-1;

    void main()

    {

    int Item,res;

    char ch='y';

    clrscr();

    while(ch=='y' || ch=='Y')

    {

    coutItem;

    res=Insert(Queue,Item);if(res==-1)

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    38/74

    {

    res=Remove(Queue);

    if(res==-1)

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    39/74

    int Remove(int Queue[])

    {

    int ret;

    if(front==-1)

    return-1;else

    {

    ret=Queue[front];

    if(front==rear)

    front=rear=-1;

    else

    front++;

    }return ret;

    }

    void Display(int Queue[],int front,int rear)

    {

    if(front==-1)

    return;

    for(int i=front;i

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    40/74

    Output of the program for Deletion in Array-Queue:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    41/74

    Addition and deletion of new books using linked list:

    # include

    # include class NODE

    {

    public:

    int bookno;

    NODE *link;

    };

    class LINKLIST

    { private:

    NODE *first,*last,*temp;

    public:

    void NCREATE(int); // Create a linked list with n nodes

    void insertatk(int); // Inserting at kth position

    void display(); // Display the linked list

    };

    void LINKLIST::NCREATE( int n)

    {

    first = new NODE;

    cout > first->bookno;

    first->link = NULL;

    temp = first;

    for(int i =1;i last->bookno;

    last->link = NULL;

    temp->link = last;

    temp = last;

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    42/74

    }

    }

    void LINKLIST::insertatk(int j) // Function to insert the node at kth position

    {

    int i = 0;NODE *newnode,*back;

    newnode = new NODE;

    cout>newnode->bookno;

    newnode->link = NULL;

    temp = first;

    while (i < (j-1))

    {back = temp;

    temp = temp->link;

    i++;

    }

    back->link = newnode;

    newnode->link = temp;

    }

    void LINKLIST::display() //Function to display the link list{

    temp = first;

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    43/74

    char ch1 = 'y';

    LINKLIST list;

    clrscr();

    cout > n;list.NCREATE(n);

    do

    {

    clrscr();

    cout> k;

    list.insertatk(k);break;

    case 2 :

    list.display();

    break;

    }

    } while (ch != 3);

    }

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    44/74

    Output of the program for Addition and deletion of new books using linked

    list

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    45/74

    Program to demonstrate the sum of two matrices:

    #include

    #include

    main()

    {

    int a[3][3], b[3][3], c[3][3];

    int i, j;

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    46/74

    }

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    47/74

    Output of program to demonstrate the sum of two matrices:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    48/74

    Program to find the length of the string:

    #include

    #include

    #include

    #include

    //CLASS DECLARATION

    class strn

    {

    char *a;

    int i;

    public:

    void read(); //MEMBER FUNCTIONSvoid calculate();

    }; //END OF CLASS

    void strn::read()

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    49/74

    x.read(); //CALLING MEMBER FUNCTIONS

    x.calculate();

    getch();

    } //E N D O F M A I N

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    50/74

    Output of the program to find the length of the string:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    51/74

    Program to find the occurrence of character in the string:

    #include

    #include

    #include

    # include

    //CLASS DECLARATION

    class strn

    {

    char *a;

    char ch;

    int i;

    public:void read(); //MEMBER FUNCTIONS

    void find();

    }; //END OF CLASS

    void strn::read()

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    52/74

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    53/74

    Output of the program to find the occurrence of character in the

    string:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    54/74

    A program to illustrate Multiple Inheritance:

    #include

    #include

    #include

    class admin

    {

    int admno;

    char name[30];

    public:

    void getadmin();

    void putadmin();

    };void admin::getadmin()

    {

    coutadmno;

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    55/74

    };

    void acadm::getacadm()

    {

    coutrno;coutmarks;

    }

    void acadm::putacadm()

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    56/74

    putacadm();

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    57/74

    Output of the program to illustrate Multiple Inheritance:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    58/74

    Program to create two arrays to store roll numbers and marks of

    desired students, whose number would be known at run time:

    #include#include

    int*rollno;

    float*marks;

    void main()

    {

    clrscr();

    int size;

    coutsize;

    rollno=new int[size];

    marks=new float[size];

    if((!rollno) || (!marks))

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    59/74

    Output of the program to create two arrays to store roll numbers

    and marks of desired students, whose number would be known at

    run time:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    60/74

    Function to display the elements which lie on middle of row and

    column:

    #include

    #include

    #include

    const M = 10;

    const N = 10;

    void display_RowCol(int Array[M][N], int r, int c)

    {

    clrscr();

    int row = r / 2;

    int col = c / 2;

    // Finding the middle row

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    61/74

    // Array to be a square matrix with odd dimension

    if ((r == c) && ((r%2==1) && (c%2==1)))

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    62/74

    Output of the function to display the elements which lie on

    middle of row and column:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    63/74

    Program to check whether the string is palindrome or not:

    #include

    #include

    #include

    //CLASS DECLARATION

    class strn

    {

    char *a, flag;

    int i, j, k;

    public:

    void read(); //MEMBER FUNCTIONS

    void ch_pal();strn() //USE OF CONSTRUCTOR

    {

    flag = 'y';

    }

    };

    //END OF CLASS

    void strn::read()

    {cout a; //TO READ THE STRING

    }

    void strn::ch_pal()

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    64/74

    flag = 'n';

    break;

    }

    }

    if(flag == 'n')cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    65/74

    Output of the program to check whether the string is palindrome

    or not:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    66/74

    Program to check whether the two strings are equal or not:

    #include

    #include

    #include

    #include

    //CLASS DECLARATION

    class strn

    {

    char *a, *b, flag;

    int i, j, k;

    public:

    void read(); //MEMBER FUNCTIONSvoid compare();

    strn() //USE OF CONSTRUCTOR

    {

    flag = 'y';

    }

    }; //END OF CLASS

    void strn::read()

    {cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    67/74

    j++;

    if (i != j)

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    68/74

    Output of the program to check whether the two strings are equal

    or not:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    69/74

    Program to illustrate working of default arguments. Calculate

    interest amount making use of default arguments:

    #include#include

    #include

    void amount(float princ, int time=2, float rate=0.08);

    void amount(float princ, int time, float rate)

    {

    cout

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    70/74

    Output of the program to illustrate working of default arguments.

    Calculate interest amount making use of default arguments:

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    71/74

    TABLE: STUDENT

    No: Name Stipend Stream Avgmark Grade Class

    1 Karan 400.00 Medical 78.5 B 12B

    2 Divakar 450.00 Commerce 89.2 A 11C

    3 Divya 300.00 Commerce 68.6 C 12C

    4 Arun 350.00 Humanities 73.1 B 12C

    5 Sabina 500.00 Nonmedical 90.6 A 11A

    6 John 400.00 Medical 75.4 B 12B

    7 Robert 250.00 Humanities 64.4 C 11A

    8 Rubina 450.00 Nonmedical 88.5 A 12A

    9 Vikas 500.00 Nonmedical 92.0 A 12A

    10 Mohan 300.00 Commerce 67.5 C 12C

    WRITE SQL COMMANDS FOR QUESTIONS 1 TO 7 ON THE BASIS OF TABLE STUDENT

    1) Select all the Nonmedical stream students from STUDENT.

    SELECT NAME

    FROM STUDENT

    WHERE STREAM=NONMEDICAL;

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    72/74

    OUTPUT:

    NAME:

    SABINA

    RUBINA

    VIKAS

    2) List the names of those students who are in class 12 sorted by stipend

    SELECT NAME, STIPEND FROM STUDENT

    WHERE CLASS=12

    ORDER BY STIPEND;

    OUTPUT:

    NAME STIPEND

    DIVYA 300.00

    MOHAN 300.00

    ARUN 350.00

    KARAN 400.00

    JOHN 400.00

    RUBINA 450.00

    VIKAS 500.00

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    73/74

    3) List all students sorted by avgmark in descending order:

    SELECT NAME FROM STUDENT

    ORDER BY AVGMARK DESC;

    OUTPUT:

    ROBERT

    MOHAN

    DIVYA

    ARUN

    JOHN

    KARAN

    RUBINA

    DIVAKAR

    SABINA

    VIKAS

    4) To count the number of students with grade A

    SELECT COUNT(GRADE)

    FROM STUDENT

    WHERE GRADE=A;

    OUTPUT:

    4

  • 7/25/2019 Computer Practical (C++ Programs) for CBSE XII Practical Exams

    74/74

    5) To insert a new student in the table anf fill the columns with some values

    INSERT INTO STUDENT VALUES

    (11,MANISHA,300.00,NONMEDICAL,72.5,B,12C);

    OUTPUT:

    ONE ROW ADDED

    6) Give the output of the following SQL statement:

    A) SELECT MIN(AVGMARK)

    FROM STUDENT

    WHERE AVGMARK