Connecting Tech Pros Worldwide Help | Site Map

Calculating delta of a polynomial

Newbie
 
Join Date: Nov 2006
Posts: 1
#1: Dec 6 '06
hi i am hveing problem with this can any body help me please

you will implement a function that will calculate the "delta" and solutions of second polynomia degree (aX ^ 2+bX+c=0) where
a, b, c are double
a = 1.0
delta = (b^2)-(4*a*c)
first argument will be for the function b and you will take a number and add 6 to it
the second argument will be c and that you will take number and multipiled by -1.
Member
 
Join Date: Nov 2006
Location: Antipolo, City
Posts: 55
#2: Dec 7 '06

re: Calculating delta of a polynomial


Quote:

Originally Posted by natbee23

hi i am hveing problem with this can any body help me please

you will implement a function that will calculate the "delta" and solutions of second polynomia degree (aX ^ 2+bX+c=0) where
a, b, c are double
a = 1.0
delta = (b^2)-(4*a*c)
first argument will be for the function b and you will take a number and add 6 to it
the second argument will be c and that you will take number and multipiled by -1.


#include<iostream>
#include<conio.h>
#include<math.h>

class Equation
{
public:
Equation() {};
~Equation() {};
void WelcomeMsg();
void Choice();
double equation(double a, double b);
double equation1(double a, double b, double c, double DELTA);
double equation2(double a, double b, double c, double DELTA);
};

double Equation::equation(double a, double b)
{
return(-b/a);
}

double Equation::equation1(double a, double b, double c, double DELTA)
{
return sqrt(DELTA)/(2*a);
}

double Equation::equation2(double a, double b, double c, double DELTA)
{
return sqrt(-DELTA)/(2*a);
}

void Equation::WelcomeMsg()
{

cout << "Welcome to the Unit Changer! "\n;
cout << " This program can solve any first or second degree polynomial equation \n";

}

void Equation::choice()
{
char car = (char)254;
char exp = (char)253;
cout << car << " For first degree equation \"ax + b = 0\" enter '1' or enter '2' \n";
cout << car << " For second degree equation \"ax" << exp << " + bx + c = 0\": ";
}

void main()
{
Equation *p = new Equation;
double a = 0, b = 0, c = 0;
int nChoice = 1;
double D = 0, A = 0, B = 0, C = 0;
char exp = ( char )253;
char answer[5] = "yes";
while( strcmp( answer, "no" ) != 0 )
{
p->WelcomeMsg();
p->choice();
nChoice = getch();

switch(nChoice)
{
case 1:
cout << "a = ";
cin >> a;
cout << "b = ";
cin >> b;

while( a == 0 )
{
cout << "\"a\" can't be 0, please choose another value: ";
cin >> a;
}

cout << "your equation is: " << a << "x + " << b << " = 0" << endl;
cout << "the solution is: x = "<< p->root( a, b ) << "\n";
break;
case 2:
cout << "a = ";
cin >> a;

while( a == 0 )
{
cout << "\"a\" can't be 0, please choose another value: ";
cin >> a;
}

cout << "b = ";
cin >> b;
cout << "c = ";
cin >> c;

D = b * b - ( 4 * a * c );
A = -b/( 2 * a );
.................................................. ... actually theres a lot of thing to do

and so on, i hope this can help you i really did'nt finish it co'z you have to push yourself to do it, ok, try it it would be a very helpful credit for you if you finish it by yourself ok




regards,
Reply