Cramer's Rule variable locations

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 839 Views - Last Post: 08 February 2013 - 05:47 PM Rate Topic: -----

#16 codescout  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 02-October 12

Re: Cramer's Rule variable locations

Posted 08 February 2013 - 03:37 PM

Will post it soon, tied up for a minute.

This post has been edited by codescout: 08 February 2013 - 03:37 PM

Was This Post Helpful? 0
  • +
  • -

#17 codescout  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 02-October 12

Re: Cramer's Rule variable locations

Posted 08 February 2013 - 04:17 PM

Hope that I am at least close to the solution.

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;


class LinearEquation
{
private:
	double a, b, c, d, e, f, x, y, isSolvable;


public:
	LinearEquation(double a, double b, double c, double d, double e, double f, double x, double y, bool isSolvable);


	double getA(double);
	double getB(double);
	double getC(double);
	double getD(double);
	double getE(double);
	double getF(double);
	double getX(double, double, double, double);
	double getY(double, double, double, double);
	bool isSolvable(double, double, double, double);
};


double LinearEquation::getA(double){
	return a;
}
double LinearEquation::getB(double){
	return b;
}
double LinearEquation::getC(double){
	return c;
}
double LinearEquation::getD(double){
	return d;
}
double LinearEquation::getE(double){
	e =((a*x) + (b*y));
	return e;
}
double LinearEquation::getF(double){
	f = ((c*x) + (d*y));
	return f;
}
bool LinearEquation::isSolvable(double, double, double, double){


	bool isSolvable = true;
	if((a*d)-(b*c) != 0){


		return isSolvable;
	}
	else {
		return false;
	} 
}
double LinearEquation::getX(double, double, double, double){
	double x =((e*d)-(b*f)/(a*d)-(b*c));
	return x;
}
double LinearEquation::getY(double, double, double, double){
	double y = ((a*f)-(e*c)/(a*d)-(b-c));
	return y;
}


int main()
{	
	double a;
	double b;
	double c;
	double d;
	double e; 
	double f;
	double x;
	double y;
	bool isSolvable;


	LinearEquation(double, double, double, double, double, double, double, double, bool);


	double variableArray[6] = {a, b, c, d, e, f};


	cout<<"Enter a, b, c, d, e, f: ";
	for(int i = 0; i < 6; i++){
		cin >> a >> b >> c >> d >> e >> f;


		if (isSolvable(a, b, c, d)){
			cout <<"x is "<< (&LinearEquation::getX) <<" and y is " << (&LinearEquation::getY);
		}
		else{(&LinearEquation::isSolvable);{
			cout <<"The equation has no solution.";
		}
		}
		return 0;
	}
}

Was This Post Helpful? 0
  • +
  • -

#18 jimblumberg  Icon User is offline

  • member icon


Reputation: 3993
  • View blog
  • Posts: 12,323
  • Joined: 25-December 09

Re: Cramer's Rule variable locations

Posted 08 February 2013 - 04:50 PM

I think you have too many parameters in your constructor. You shouldn't need the x,y and issolvable variables. These variables will be calculated when required. Also your getx(), gety(), issolvable() functions probably don't need any parameters, they will use the class member variables.

Also when you define your functions you should name the parameters. This will help with documenting your class.
void yourFunction(int variableName);


You also don't need any arrays in this program, you are using separate variables not arrays.

When you try to call a function you need the variable names not the variable types.

When you implement your functions you must supply variable names to this function.
double LinearEquation::getX(double, double, double, double){

The above snippet is incorrect, you need to provide names for the variables to be used in the function along with the type of variable.
void someFunction(int value){


There are probably many other things wrong with your program, you should probably re-read the function tutorials contained in my signature along with the links about classes from previous posts.

Jim
Was This Post Helpful? 0
  • +
  • -

#19 codescout  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 02-October 12

Re: Cramer's Rule variable locations

Posted 08 February 2013 - 05:47 PM

This alone has cleared up alot. Many of the tutorials define differently and I was not sure which one would fit my problem. Thank you so much. Will keep reading.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2