OOPS file

Embed Size (px)

Citation preview

  • 8/6/2019 OOPS file

    1/25

    Program to show addition of two objects

    #include

    #include

    #includeclass A

    { int a,b;public:

    void getdata(int a1,int b1)

    {

    a=a1;b=b1;

    }

    void add(A ob1,A ob2){ a=ob1.a+ob2.a;

    b=ob1.b+ob2.b;cout

  • 8/6/2019 OOPS file

    2/25

    //wap to construct a class named bank with details-name,type of account,accnt no.,balance amt.member functions are-read,withdraw,deposite,display//

    #include#include

    #includeclass bank{

    char d_name[30];

    char a_name[20];

    int acc_no;int a_bal,d_bal,w_bal;

    public:void read()

    {

    cout

  • 8/6/2019 OOPS file

    3/25

    }};

    void main()

    {bank b;

    int select;clrscr();b.read();

    coutselect;

    if (select == 1)b.deposit();

    else

    if (select == 2)b.withdraw();

    else

    cout

  • 8/6/2019 OOPS file

    4/25

    Wap to create a class book that has the following details:-name of the book

    -author's name

    -book price-no. of pages

    member functions are:read(),display().also create array of 3 books & display their details//

    #include

    #include#include

    class book

    {char b_title[20];

    char a_name[20];

    int price;int pages;

    public:

    void display();void read()

    {

    cout

  • 8/6/2019 OOPS file

    5/25

    {b1[i].read();

    }

    for (int j=0;j

  • 8/6/2019 OOPS file

    6/25

    The book price is : 350

    The number of pages in the book is : 350

    ----------------------------------------------

    The name of the book is : computer system archmorris mano

    The name of the author is : morris mano

    The book price is : 300

    The number of pages in the book is : 350

    ----------------------------------------------

    The name of the book is : c++ fundamentals

    The name of the author is : sumita arora

    The book price is : 200

    The number of pages in the book is : 250

  • 8/6/2019 OOPS file

    7/25

    #include#include

    #include

    class book{

    protected:int exno,cost;char name[10],title[20];

    public:

    void getdata()

    {coutexno;

    cout

  • 8/6/2019 OOPS file

    8/25

    cout

  • 8/6/2019 OOPS file

    9/25

    #include#include

    #include

    class item{

    int price,code;

    public:

    item()

    {

    price =0;code =0;

    }

    item(int a,int b){

    price =a;

    code= b;}

    item(item &obj3)

    {

    price = obj3.price;code= obj3.code;

    }

    void display(){

    cout

  • 8/6/2019 OOPS file

    10/25

    //wap to construct 2 classes named employee with details-(name,address,company) &second class

    named perk with details-da(25% of salary),hra(20% of salary).implement to find the net

    salary//

    #include#include#include

    class employee

    {

    char e_name[30];char address[40];

    char company[20];

    public:void read()

    {

    cout

  • 8/6/2019 OOPS file

    11/25

    {cout

  • 8/6/2019 OOPS file

    12/25

    The Net Salary is : 8700

  • 8/6/2019 OOPS file

    13/25

    //wap to declare a class called matrix which is represented by 2-d array.write functions toperform the

    addition of 2 matrices & store them into 3rd matrix//

    #include

    #include#includeclass matrix

    {

    int a[2][2];

    public:

    void read();

    void add(matrix,matrix);};

    void matrix::read()

    {cout

  • 8/6/2019 OOPS file

    14/25

    {clrscr();

    matrix a,b,c;

    a.read();b.read();

    c.add(a,b);getch();}

    output:

    Enter the value of matrix :-----------------

    42

    5

    7

    Enter the value of matrix :-----------------

    2

    46

    7

    The matrix after addition is :----------------

    66

    11

    14

  • 8/6/2019 OOPS file

    15/25

    //wap to implement a class named student with following details :-read()-to read i/p

    -avg()-to cal. the average marks

    -display()-to display the student details//

    #include#include

    #include

    class student{

    char st_name[20];

    int r_no;int m1,m2,m3,m4,m5;

    public :void read()

    {

    coutm2>>m3>>m4>>m5;

    }

    void display()

    {cout

  • 8/6/2019 OOPS file

    16/25

    a.display();a.avg();

    getch();

    }

    output:

    enter your name : ram

    enter roll number : 12

    enter marks of m1,m2,m3,m4,m570

    60

    78

    9088

    The name of student is : ram

    the roll number is : 12

    the marks are:70

    60

    7890

    88

    The average is : 77

  • 8/6/2019 OOPS file

    17/25

    //wap to input & show the details(marks in 2 subjects & total)of student using concept ofinheritance//

    #include

    #include#include

    class student{protected:

    int roll_no;

    public:void getroll_no()

    {

    coutroll_no;

    }

    void put(){

    coutsub2;}

    };

    void test::showsub()

    {cout

  • 8/6/2019 OOPS file

    18/25

    getroll_no();getsub();

    }

    };void result::showdetail()

    {total = sub1 + sub2;cout

  • 8/6/2019 OOPS file

    19/25

    //wap to input & show the details(marks in 2 subjects & total)of student using concept ofinheritance//

    #include

    #include#include

    class student{protected:

    int roll_no;

    public:void getroll_no()

    {

    coutroll_no;

    }

    void put(){

    coutsub2;}

    };

    void test::showsub()

    {cout

  • 8/6/2019 OOPS file

    20/25

    getroll_no();getsub();

    }

    };void result::showdetail()

    {total = sub1 + sub2;cout

  • 8/6/2019 OOPS file

    21/25

    //wap to illustrate the working of function-overloading

    //

    #include#include#include

    int compute(int,int);

    void compute(int,int,int);

    void compute(char);void main()

    {

    int l,b,h,a;clrscr();

    coutl;coutb;

    couth;a = compute(l,b);

    cout

  • 8/6/2019 OOPS file

    22/25

    output:Enter the length :2

    Enter the Breadth :3

    Enter the Height : 4

    The Area is : 6

    **********The volume is : 24

    **********

  • 8/6/2019 OOPS file

    23/25

  • 8/6/2019 OOPS file

    24/25

  • 8/6/2019 OOPS file

    25/25