(Algebra: 2 x 2 linear equations) Design a class named LinearEquation for a 2 x
ID: 3577885 • Letter: #
Question
(Algebra: 2 x 2 linear equations) Design a class named LinearEquation for a 2 x 2 system of linear equations: by ar ad bc The class contains: Private data fields a b, c, d, e, and f A constructor with the arguments fora, b, c, d, e, and f Six get functions for a b,c, d, e, and f A function named issolvable() that returns true if ad bc is not 0 Functions getX0 and getY0 that return the solution for the equation. Draw the UML diagram for the class and then implement the class. Write a test program that prompts the user to enter a, b,c, d, e, and fand displays the result. If ad-bc is 0, report that "The equation has no solution. See Programming Exercise for sample runs. (Algebra: solve 2 x 2 linear equations) You can use Cramer's rule to solve the following 2 x 2 system of linear equation: Write a program that prompts the user to enter a, b,c, d,e and f and displays the result. If ad-bc is 0, report that "The equation has no solution." Enter f 1. 9.0 4.0 3.0 21.0 x is 2.0 and y is 3.0 Enter a, b, c, d, e, f: 1.0 2.0 2.0 4.0 4.0 5.0 Ptin The equation has no solutionExplanation / Answer
******************LInearEquation.cpp*****************
#include<iostream>
using namespace std;
class LinearEquation{
private:
float a,b,c,d,e,f;
public:
LinearEquation(float p,float q,float r,float s,float t,float u){
a=p;
b=q;
c=r,
d=s;
e=t;
f=u;
}
void geta(float p){
a=p;
}
void getb(float p){
b=p;
}
void getc(float p){
c=p;
}
void getd(float p){
d=p;
}
void gete(float p){
e=p;
}
void getf(float p){
f=p;
}
bool solvable(){
if((a*d)-(b*c)!=0)
return true;
else
false;
}
float getX(){
float x;
x=((e*d)-(b*f))/((a*d)-(b*c));
return x;
}
float getY(){
float y;
y=((a*f)-(e*c))/((a*d)-(b*c));
return y;
}
};
int main(){
float p,q,r,s,t,u;
cout<<" Enter a,b,c,d,f,e:";
cin>>p>>q>>r>>s>>t>>u;
LinearEquation l(p,q,r,s,t,u);
if(l.solvable()==true){
cout<<" x is:"<<l.getX();
cout<<" and y is "<<l.getY();
}
else{
cout<<" The equation has no solution.";
}
}
**********************OUTPUT************************
Enter a,b,c,d,f,e:9.0
4.0
3.0
-5.0
-6.0
-21.0
x is:-2 and y is 3
--------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.