Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help writing the following code for my C++ program! HELP!! (the parts whe

ID: 3531950 • Letter: I

Question

I need help writing the following code for my C++ program! HELP!! (the parts where there are "???")



CTOR: PointTest()

//

// DESCRIPTION

// Default constructor. Does nothing.

//

// REMARKS

// Every class must have at least one ctor, because when an object is instantiated, a ctor must be called. If

// there are no data members to initialize, then we just provide a default ctor that does nothing.

//--------------------------------------------------------------------------------------------------------------

???


//--------------------------------------------------------------------------------------------------------------

// FUNCTION: Run()

//

// DESCRIPTION

// Tests the implementation of the Point class.

//

// PSEUDOCODE

// Define x, y, r, g, and b as int variables.

// Configure cout so real numbers are displayed in fixed notation with 3 digits after the decimal pt.

//

// Comment: Test that the default ctor works correctly.

// Define and instantiate a Point object named p1 calling the default ctor.

//

// Comment: Test that the second ctor works correctly.

// x <- GetInt("Enter point p2 x? ").

// y <- GetInt("Enter point p2 y? ").

// Define and instantiate a Point object named p2 passing x, y as the params to the ctor.

//

// Comment: Test that the third ctor works correctly.

// x <- GetInt("Enter point p3 x? ").

// y <- GetInt("Enter point p3 y? ").

// r <- GetInt("Enter point p3 red? ").

// g <- GetInt("Enter point p3 green? ").

// b <- GetInt("Enter point p3 blue? ").

// Define and instantiate a Point object named p3 passing x, y, r, g, and b as the params to the ctor.

//

// Comment: Test that the fourth ctor works correctly.

// x <- GetInt("Enter point p4 x? ").

// y <- GetInt("Enter point p4 y? ").

// r <- GetInt("Enter point p4 red? ").

// g <- GetInt("Enter point p4 green? ").

// b <- GetInt("Enter point p4 blue? ").

// Define and instantiate a Color object named color passing r, g, and b as the params to the ctor.

// Define and instantiate a Point object named p4 passing x, y, and color as the params to the ctor.

//

// Send to cout "The point p1 is " followed by p1.ToString() followed by endl.

// Send to cout "The point p2 is " followed by p2.ToString() followed by endl.

// Send to cout "The point p3 is " followed by p3.ToString() followed by endl.

// Send to cout "The point p4 is " followed by p4.ToString() followed by endl.

//--------------------------------------------------------------------------------------------------------------

???

Explanation / Answer


#include<iostream>



using namespace std;


class PointTest

{

int x;

int y;

int r;

int g;

int b;


public:

PointTest()

{

x=0;

y=0;

r=0;

g=0;

b=0;

}


PointTest(int x,int y)

{

this->x=x;

this->y=y;

}


PointTest(int x,int y,int r,int g,int b)

{

this->x=x;

this->y=y;

this->r=r;

this->g=g;

this->b=b;

}

PointTest(int r,int g,int b)

{

this->r=r;

this->g=g;

this->b=b;

}


int getX()

{

return x ;

}

int getY()

{

return y ;

}

int getR()

{

return r;

}

int getG()

{

return g;

}

int getB()

{

return b;

}


void setX(int x )

{

this->x=x;

}

void setY(int y )

{

this-> y=y;

}

void setR(int r )

{

this->r=r;

}

void setG(int g)

{

this-> g=g;

}

void setB(int b)

{

this-> b=b;

}


};


void run()

{

PointTest p;

cout<<" constructor check with zero parameters ";

cout<<"x= "<<p.getX()<<endl;

cout<<"y= "<<p.getY()<<endl;

cout<<"b= "<<p.getB()<<endl;

cout<<"r= "<<p.getR()<<endl;

cout<<"g= "<<p.getG()<<endl;


cout<<" constructor check with zero parameters ";


PointTest p1(10,20);

cout<<"x= "<<p1.getX()<<endl;

cout<<"y= "<<p1.getY()<<endl;

cout<<" constructor check with five parameters ";

PointTest p2(10,20,30,40,50);

cout<<"x= "<<p2.getX()<<endl;

cout<<"y= "<<p2.getY()<<endl;

cout<<"b= "<<p2.getB()<<endl;

cout<<"r= "<<p2.getR()<<endl;

cout<<"g= "<<p2.getG()<<endl;

cout<<" constructor check with three parameters ";

PointTest p3(30,40,50);

cout<<"b= "<<p2.getB()<<endl;

cout<<"r= "<<p2.getR()<<endl;

cout<<"g= "<<p2.getG()<<endl;


}


int main()

{

run();

return 0;

}