slip 28


/* Slip no : 28_1 Create a class Point that has x & y as integer data members. Write a C++ program to perform following functions:
   void setpoint(int, int)    To set the specified values of x and y in object.
   void showpoint()            To display contents of point object.
   point addpoint(point) To add the corresponding values of x, and y in point argument to current point object return point.
 */

#include<conio.h>
#include<iostream.h>

class point
{
                int x,y;
                public :
                void setpoint(int x1,int y1)
                {
                                x=x1;
                                y=y1;
                                //            cout<<x<<y;
                }

                void showpoint()
                {
                                cout<<"\n x = "<<x<<"\t y = "<<y;
                }

                point addpoint(point ob)
                {
                                point temp;
                                temp.x = x+ob.x;
                                temp.y = y+ob.y;
                                return temp;
                }
};

void main()
{
                int n1,n2,n3,n4;
                point p1,p2,p3;
                clrscr();
                cout<<"\n Enter x,y co-ordinate: ";
                cin>>n1;
                cin>>n2;
                p1.setpoint(n1,n2);

                cout<<"\n Enter x,y co-ordinate: ";
                cin>>n3;
                cin>>n4;
                p2.setpoint(n3,n4);

                cout<<"\n 1st co-ordinate : ";
                p1.showpoint();
                cout<<"\n 2nd co-ordinate : ";
                p2.showpoint();

                cout<<"\n Addition is : ";
                p3=p1.addpoint(p2);
                p3.showpoint();
                getch();


}














/* Slip no : 28_2 Create a base class Media. Derive two different classes Book (Book_id, Book_name, Publication, Author, Book_price) and CD (CD_title, CD_price) from Media. Write a C++ program to accept and display information of both Book and CD. (Use pure virtual function) */

#include<iostream.h>
#include<conio.h>
class media
{
public:
virtual void accept()=0;
virtual void display()=0;
};

class book:public media
{
public:
int bid,price;
char name[20],publication[29];
void accept()
{
   cout<<"\n Enter book id : ";
   cin>>bid;
   cout<<"\n Enter name : ";
   cin>>name;
   cout<<"\n Enter publication : " ;
   cin>>publication;
   cout<<"\n Enter price : ";
   cin>>price;
}

void display()
{
cout<<"\n bid = "<<bid<<"\n name = "<<name<<"\n publication = "<<publication<<"\n price = "<<price;
}

};

class CD:public media
{
public:
int price;
char title[20];
void accept()
{
cout<<"\n Enter title : ";
cin>>title;
cout<<"\n Enter price : ";
cin>>price;
}

void display()
{
cout<<"\n Title = "<<title<<"\n price = "<<price;
}
};

void main()
{
book ob1;
media *ptr;
clrscr();
ptr=&ob1;
ptr->accept();
ptr->display();
CD ob2;
ptr=&ob2;
ptr->accept();
ptr->display();
getch();
}
slip 28 slip 28 Reviewed by Dinesh Varal on January 31, 2018 Rating: 5

No comments:

Powered by Blogger.