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

C++ programming question 1. In function main declare coordinates for two points

ID: 3763755 • Letter: C

Question

C++ programming question

1. In function main declare coordinates for two points (x1, y1, x2, y2) and slope m and y-intercept b. Call a function get2points to read in the two sets of coordinates. Return the values to function main, pass by address. Call a second function slopeIntercept to calculate the values of slope m and intercept b for the form y = mx+b. Function slopeIntercept has six parameters, the four coordinate values and pointers to the slope and y-intercept. Call a function displayEquation to print the final form of the equation.

Enclose the call statements in a while or do…while loop so that additional coordinates can be converted to the slope intercept format if desired.

Test with coordinate pairs:

(4,3) and (-2,1)

(1,1) and (5,17.8)

Explanation / Answer

#include<iostream>

using namespace std;

void get2points(double &x1, double &y1, double &x2, double &y2) {

cout<<"Enter x1,y1: ";

cin>>x1>>y1;

cout<<"Enter x2,y2: ";

cin>>x2>>y2;

cout<<" ";

}

void slopeIntercept(double &x1, double &y1, double &x2, double &y2, double &m, double &b) {

m=(y2-y1)/(x2-x1);

b=y1-m*x1;

}

void displayEquation(double &m, double &b) {

cout<<"y = "<<m<<"x + "<<b<<" ";

}

int main() {

double x1,y1,x2,y2,m,b;

  

get2points(x1,y1,x2,y2);

slopeIntercept(x1,y1,x2,y2,m,b);

cout<<"Equation: ";

displayEquation(m,b);

  

  

cout<<" ";

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote