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

In plane analytic geometry we can represent a line by the equation y = m\"x + b

ID: 3721241 • Letter: I

Question

In plane analytic geometry we can represent a line by the equation y = m"x + b where m is called the slope and is a real number representing the inclination of the line in relation to the horizontal axis and b is called the y-intercept which is the location where the line crosses the vertical axis. This is to say that any line will be determined by it's two attributes m and b Create a class named line that represent lines in two dimensional planes that has the following properties 1. It contains two double variables m and b representing the slop and the y-intercept as instance variables 2. It includes a default constructor that initialize m and b to 0 3. It include a constructor that requires two arguments one for m and one for b with default value of 0 4 It include a method to translate (move) the line up or down the y-axis (vertical axis) with the new b becoming btranslation where translation is the amount by which the line is moved up or down but the slope remains the same.

Explanation / Answer

//the following code is tested in gcc 4.6.3 compiler
//c++ 11 is used
#include <iostream>
using namespace std;

class line
{
private:
double m,b,y;
  
public:
line() //using default constructor to intialize default values ie 0
{
m=0;
b=0;

}

line(double p1=0, double p2=0) //using parameterized constructor with default values
{
m=p1;
b=p2;
}

void translate( double t) //fucntion to translate the value of b
{  
b=b+t; //value of b increases with t
}

void getvalues() //fucntion to print values of m and b
{
cout<<"m = "<<m<<" b = "<<b<<endl;
}
};
int main() {
line y(3,6); //creating an object of line with parameter 3 and 6 passed.
y.getvalues();

y.translate(5);
y.getvalues();
}