Write the definition for a class called ‘point’ that has x & y as integer data members. Overload the assignment operator (=) to copy one object to another. (Use Default and parameterized constructor to initialize the appropriate objects) Write a C++ program to illustrate the use of above class.
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<conio.h>
#include<iostream.h>
class point
{
float x,y;
public:
point()
{
}
point(float a,float b=10) //constructor
{
x=a;
y=b;
}
point operator =(point p1) //function overloading
{
x=p1.x;
y=p1.y;
return(p1);
}
void disp()
{
cout<<"\n X = "<<x;
cout<<"\n Y = "<<y;
}
};
int main()
{
int n;
cout<<"\nEnter X coordinate: ";
cin>>n;
cout<<"\nY coordinate is fixed.";
point p(n),p1; //object created
cout<<"\n========Original Points=======";
p.disp();
p1=p;
cout<<"\n========Copy Of points========";
p1.disp();
getch();
return(0);
}
-
Next Imagine a ticket Selling booth at a fair. People passing by are requested to purchase a ticket. A ticket is priced as Rs. 5/- . The ticketbooth keeps the track of the number of peoples that have visited the booth and of the total amount of cash collected. Create a class ticketbooth that contains No_of_people_visited, Total_Amount_collected. Write C++ program to perform following functions: i. To assign initial values. ii. To increment the No_of_people_visited if visitors have just visited the booth. iii. To increment the No_of_people_visited and Total_amount_collected if tickets have been purchased. iv. To display both totals
-
Previous Write a C++ program to create a class Integer. Write necessary member functions to overload the operator unary pre and post decrement ‘--’ for an integer number.
0 Comments