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

C++ : Design a class named LinearEquation for a 2 X 2 system of linear equations

ID: 3770107 • Letter: C

Question

C++: Design a class named LinearEquation for a 2 X 2 system of linear equations:

ax + by = e

cx + dy = f

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

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

The class contains:

- Separate header and implementation files

- Private data fields a, b, c, d, e, and f.

- A constructor with the arguments for a, 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 getX() and getY() that return the solution for the equation.

Write a test 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.

Explanation / Answer

#include<stdio.h>
#include<iostream>

using namespace std;

class linear{
      int a,b,c,d,e,f;
      public:
           
      linear(int m,int n,int o,int p,int q,int r){
                 a=m;
                 b=n;
                 c=o;
                 d=p;
                 e=q;
                 f=r;}
               
    
      int getA(){return a;}
      int getB(){return b;}
      int getC(){return c;}
      int getD(){return d;}
      int getE(){return e;}
      int getF(){return f;}
      double getX(){
             double x;
             x = (((e*d)-(b*f))/((a*d)-(b*c)));
             return x;
             }
    
    
      double getY(){
          double y;
          y = (((a*f)-(e*c))/((a*d)-(b*c)));
          return y;}
    
      int isSolvable(){
          int h=((a*d)-(b*c));
          return h;}
        
          };
        
          int main(){
            
              linear l(14,6,1,3,2,2);
            
              cout<<"a:"<<l.getA()<<endl;
              cout<<"b:"<<l.getB()<<endl;
              cout<<"c:"<<l.getC()<<endl;
              cout<<"d:"<<l.getD()<<endl;
              cout<<"e:"<<l.getE()<<endl;
              cout<<"f:"<<l.getF()<<endl;
            
              if(l.isSolvable()<0){
                                   cout<<"no solution";
                                   }
                                 
                                   else{
                                        double x;
                                        x=l.getX();
                                        double y;
                                        y=l.getY();
                                   cout<<"value of x:"<<x<<endl;
                                   cout<<"value of y:"<<y<<endl;}
                                 
                                 
                              
                                   return 0;
                                   }