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

Hi I missed this on an exam - I dont know why we needed to call by reference (so

ID: 3690997 • Letter: H

Question

Hi I missed this on an exam - I dont know why we needed to call by reference (someone has already answersed that I didnt need to use call by reference but when do I use call by reference and why are the slopes subtracted to figured out if the lines interersect or not

This is C++

thanks

#include <iostream>

using namespace std;
void line_inter(double,double,bool &);

int main()
{
    double m1, m2;
    bool yes_no;

    cout << "Enter the slopes of line 1 and line2: ";
    cin >> m1 >> m2;

    line_inter(m1,m2,yes_no);
    if (yes_no)
        cout << "The lines do intersect. ";
    else
        cout << "The lines don't intersect. ";


    return 0;
}


void line_inter(double m1, double m2, bool &yes_no)
{
    if (m1 - m2 == 0)
        yes_no = false;
    else
        yes_no = true;
}

Explanation / Answer

M1-M2 CHECKS FOR EQALITY OFTHEIR SLOPES. IF THE SLOPE IS EQUAL.THEN THEY CANNOT INTRSECT BECAUSE OF THEY ARE PARALLEL. SUPPOSE IF SLOPE IS 4 FOR ONE LINE AND ALSO FOR 2ND LINE THEY ARE WITH EQUQL SLOPE I.E THEY ARE PARALLEL.