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

Write a C++ program that calculates the roots of a system of two equations. The

ID: 3622016 • Letter: W

Question

Write a C++ program that calculates the roots of a system of two equations. The program must consist of two functions: main function and systLinEqu with the following prototype:

void systLinEqu(double a[], double b[], double c[], double r[], int& key);

where: a – array of coefficients a1, a2,
b – array of coefficients b1, b2,
c – array of coefficients c1, c2,
r – array of roots r1, r2 (if there are . . . )
key - kind of result (many cases)
The systLinEqu function is called be the main function. All input and outputs operations mus by accomplished by main function.

Execute the program many times to test all different cases.

Explanation / Answer

// frox example x+2y = 5 and 3x+y = 5

// a array = 1 2 and b array = 2 1 and c array = 5 5   roots are 1 and 2

#include<iostream.h>
#include<conio.h>
void systLineEqu(double a[], double b[],double c[],double r[], int &key);
int main()
{
int k=0;
int& key=k;
double a[2],b[2],c[2],r[2];
cout << "enter a array coefficients"<<endl;
cin >> a[0] >> a[1];
cout << "enter b array coefficients"<<endl;
cin >> b[0] >> b[1];
cout << "enter c array coefficients"<<endl;
cin >> c[0] >> c[1];
systLineEqu(a,b,c,r,key);
if(key)
cout << "roots are given by " << r[0] << " " << r[1] << endl;
getch();
return 0;
}
void systLineEqu(double a[], double b[],double c[],double r[], int &key)
{
if(a[0]*b[1]==a[1]*b[0])
cout<< "solution doesnot exist. System inconsistent"<<endl;
else
{
r[0] = (c[0]*b[1]-c[1]*b[0])/(a[0]*b[1]-a[1]*b[0]);
r[1] = (a[0]*c[1]-a[1]*c[0])/(a[0]*b[1]-a[1]*b[0]);
key =1;
// cout << "roots are given by " << r[0] << r[1] << key<< endl;
}



}

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