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

Please help! Practicing functions with reference parameters in visual studios C+

ID: 3679213 • Letter: P

Question

Please help!

Practicing functions with reference parameters in visual studios C++

Cramer’s rule allows the resolution of 2 equations with 2 unknowns as long as the equations are unique (one is not a multiple of the other). Suppose x and y are the unknowns. Given the two equations

          ax + by = e      and    cx + dy = f

where a, b, c, d, e, and f are coefficients, the values for x and y may be determined from

x= (ed-bf)/(ad-bc) and y= (af-ec)/(ad-bc)   

Create a single function that will accept the coefficients plus two parameters for x and y, calculate the values for x and y and send back to the function call the values for x and y. Your function should not use input statements (cin) or output statements (cout).

Create a main function that will prompt the user to enter the coefficients, call the function to determine x and y, then output the values of x and y.

Do not use the same identifiers in main and in your function. Also put your function definition after main.

Explanation / Answer

#include <iostream>

#include <tuple>

using namespace std;

int main()

{

int x,y,a,b,c,d,e,f;

cout << " Enter the coefficients a,b,c,d,e, and f : ";

cin >> a1 >> b1 >> c1 >> d1 >> e1 >> f1;

tie ( x, y ) = equations(a,b,c,d,e,f);

cout<< " x value: "<< x << " " << "y value: " << y;

return;

}

tuple<int,int> equations( int a, int b, int c, int d, int e, int f)

{

int x, y;

x = (ed-bf) / (ad-bc);

y = (af-ec) / (ad-bc);

return make_tuple(x,y);

}