Design and implement a class named CPoint for the managementterms of its width,
ID: 3610525 • Letter: D
Question
Design and implement a class named CPoint for the managementterms of its width, height and the point corresponding to theupper-left corner. Finally, write a testing program that createstwo rectangles with two different contructors, shows on the consolethe attributes associated to that rectangles, double the size ofthe rectangles calling to the doubleSize() method, and shows againthe attributes of both rectangles.of a point at the plane.Following, design a implement a class named CRectangle for themanagement of rectangle in Using the previous program, overload the standard input andoutput operators (>> and <<) for the class CRectangle.The input and the output take the format (x,y). In C++ Design and implement a class named CPoint for the managementterms of its width, height and the point corresponding to theupper-left corner. Finally, write a testing program that createstwo rectangles with two different contructors, shows on the consolethe attributes associated to that rectangles, double the size ofthe rectangles calling to the doubleSize() method, and shows againthe attributes of both rectangles.of a point at the plane.Following, design a implement a class named CRectangle for themanagement of rectangle in Using the previous program, overload the standard input andoutput operators (>> and <<) for the class CRectangle.The input and the output take the format (x,y). In C++Explanation / Answer
#include<iostream>
#include <string.h>
using namespace std;
struct point {
double x,y;
};
class CPoint
{
public:
double width, height ;
struct point p;
CPoint(double x,double y,double w,double h){
p.x = x;
p.y = y;
width=w;
height=h;
}
void doubleSize(){
width = 2 * width;
height = 2 * height;
}
void show(){
cout<<" Left cornor is:"<<p.x<<" , "<<p.y<<endl;
cout<<" width ="<<width<<endl;
cout<<" height ="<<height<<endl<<endl;
}
#include <iostream>
#include <string.h>
using namespace std;
struct point {
double x,y;
};
class CRectangle
{
public:
double width, height ;
struct point p;
CRectangle(){
width=height=p.x=p.y=-1;
}
CRectangle(double x,double y,double w,doubleh){
p.x = x;
p.y = y;
width=w;
height=h;
}
void doubleSize(){
width = 2 * width;
height = 2 * height;
}
void show(){
cout<<" Left cornor is:"<<p.x<<" , "<<p.y<<endl;
cout<<" width ="<<width<<endl;
cout<<" height ="<<height<<endl<<endl;
}
friend istream& operator>>(istream& theStream, CRectangle & p)
{
cout<<"Enter leftcornor:x and y =";
theStream>>p.p.x>>p.p.y;
cout<<"Enterwidth:";
theStream>>p.width;
cout<<"Enterheight:";
theStream>>p.height;
return theStream;
}
friend ostream& operator<< (ostream& theStream,CRectangle & p)
{
theStream<<" Left cornoris :"<<p.p.x<<" , "<<p.p.y<<endl;
theStream<<" width ="<<p.width<<endl;
theStream<<" height ="<<p.height<<endl<<endl;
return theStream;
}
};
int main()
{
CRectangle theCRectangle;
cin>> theCRectangle;
cout << theCRectangle;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.