SYSTEM 2,3 OPERATION
Submitted on: 5/3/2001 11:28:24 AM
By: UGO DESCHAMPS
Level: Beginner
User Rating: By 1 Users
Compatibility:C, C++ (general), Microsoft Visual C++, Borland C++
Users have accessed this code 189 times.
(About the author)
CALCULATE 2, 3 AND 4 DETERMINANT EQUATION AND SYSTEM WITH 2 AND 3 EQUATION..
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
Terms of Agreement:
By using this code, you agree to the following terms...
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
//**************************************
//
// Name: SYSTEM 2,3 OPERATION
// Description:CALCULATE 2, 3 AND 4 DETE
// RMINANT EQUATION AND SYSTEM WITH 2 AND 3
// EQUATION..
// By: UGO DESCHAMPS
//
//This code is copyrighted and has// limited warranties.Please see http://
// www.1CPlusPlusStreet.com/xq/ASP/txtCodeI
// d.1696/lngWId.3/qx/vb/scripts/ShowCode.h
// tm//for details.//**************************************
//
#include
#include
#include
#include
void sys_3_equation(void);
void sys_2_equation(void);
void sys_2_det(void);
void sys_3_det(void);
float verification(float);
char verification(char);
float v;
char resp;
char choice;
main()
{
do
{
clrscr();
gotoxy(30,2); printf ("MENU");
gotoxy(20,4); printf ("1----> 2 equation's system's");
gotoxy(20,5); printf ("2----> 3 equation's system's");
gotoxy(20,6); printf ("3----> determinant ordre 2");
gotoxy(20,7); printf ("4----> determinant ordre 3");
gotoxy(20,9); printf ("Q----> Quit");
gotoxy(30,11); choice = getch();
switch (choice)
{
case '1': sys_2_equation();
break;
case '2': sys_3_equation();
break;
case '3': sys_2_det();
break;
case '4': sys_3_det();
break;
case 'q':
case 'Q': exit(666);
default : clrscr();
gotoxy(25,5); printf ("ERROR!! Not a valid choice.");
gotoxy(28,6); printf ("Re-enter your choice.");
sleep(3);
}
}while (choice != 'Q');
}
////////////////////////////////////////
///////////////////////////////////////
/////////////// verification for all
// the number's//////////////
////////////////////////////////////////
///////////////////////////////////////
float verification(float number)
{
float num;
do
{
gotoxy(35,7); printf ("");
gotoxy(22,5); printf ("");
gotoxy(35,7); scanf ("%f", &num);
if (num <= -100 || num >= 100)
{
gotoxy(22,5); printf ("Enter a number between -99.99 and 99.99");
sleep(2);
}
}while (num <= -100 || num >= 100);
return(num);
}
char verification(char responce)
{
do
{
gotoxy(35,3); printf (" ");
gotoxy(22,4); printf ("");
gotoxy(38,3); resp = getchar();
if (resp != 'y' && resp != 'n')
{
gotoxy(25,4); printf ("Enter (y)yes or (n)no!!!");
sleep(2);
}
}while (resp != 'y' && resp != 'n');
clrscr();
return(resp);
}
void sys_2_equation()
{
float X[2], Y[2], T[2], x;
float delta, delta_x, delta_y;
float ans_x, ans_y;
char answer;
int i;
do
{
do
{
clrscr();
for (i=0;i<2;i++)
{
gotoxy(15,1); printf ("Do not put the '+' symbol. It will be added by default.");
gotoxy(20,2); printf ("Enter the variable #%d value of the variable X.", i);
X[i] = verification(x);
gotoxy(20,2); printf ("Enter the variable #%d value of the variable Y.", i);
Y[i] = verification(x);
gotoxy(20,2); printf ("Enter the total of the equation #%d. ", i);
T[i] = verification(x);
}
clrscr();
if (Y[1] > 0)
{gotoxy(25,5); printf ("%.2fx + %.2fy = %.2f", X[0], Y[0], T[0]);}
else
{gotoxy(25,5); printf ("%.2fx %.2fy = %.2f", X[0], Y[0], T[0]);}
if (Y[2] > 0)
{gotoxy(25,7); printf ("%.2fx + %.2fy = %.2f", X[1], Y[1], T[1]);}
else
{gotoxy(25,7); printf ("%.2fx %.2fy = %.2f", X[1], Y[1], T[1]);}
gotoxy(25,1); printf ("Is the entry correct (y/n)?");
answer = verification(resp);
}while (answer != 'y');
delta = (X[1] * Y[2] - X[2] * Y[1]);
delta_x = (T[1] * Y[2] - T[2] * Y[1]);
delta_y = (X[1] * T[2] - X[2] * T[1]);
if (delta ==0 && delta_x == 0)
{
gotoxy(30,10); printf ("Infinity of possibility.");
}
else
if (delta == 0 && delta_x !=0)
{
gotoxy(30,10); printf ("Impossible system!!");
}
if (delta != 0)
{
ans_x = delta_x / delta;
ans_y = delta_y / delta;
gotoxy(30,10); printf ("x = %.2f, y = %.2f", ans_x, ans_y);
}
gotoxy(30,1); printf ("Do you want to quit?");
answer = verification(resp);
}while (answer != 'y');
}
void sys_3_equation()
{
float V[3][3], T[3];
float delta, delta_x, delta_y, delta_z;
float ans_x, ans_y, ans_z, a ,b, c;
char answer;
int i, sign1[3], sign2[3];
do
{
do
{
////////////////////////////////////////
////////////////////////////////
////////// ENTRY OF ALL THE VARIABLE
// //////////////////
////////////////////////////////////////
////////////////////////////////
clrscr();
for (i=0;i<3;i++)
{
gotoxy(15,1); printf ("Do not put the '+' symbol. It will be added by default.");
gotoxy(20,3); printf ("Enter the value %d of the variable X. ", i+1);
V[i][0] = verification(v);
gotoxy(20,3); printf ("Enter the value %d of the variable Y. ", i+1);
V[i][1] = verification(v);
if (V[i][1]<0)
sign1[i]=0;
else
sign1[i]=43;
gotoxy(20,3); printf ("Enter the value %d of the variable Z. ", i+1);
V[i][2] = verification(v);
if (V[i][1]<0)
sign2[i]=0;
else
sign2[i]=43;
gotoxy(20,3); printf ("Enter the total of the equation %d. ", i+1);
T[i] = verification(v);
}
clrscr();
for (i=0;i<3;i++)
{
gotoxy(25,(i+2)*2); printf ("%.2fx %c %.2fy %c %.2fz = %.2f", V[i][0], sign1[i], V[i][1], sign2[i], V[i][2], T[i]);
}
gotoxy(25,1); printf ("Is the entry correct (y)?");
answer = verification(resp);
}while (answer != 'y');
/////////////////////////////////////////////////////////////////////////
//////////// THE MAGIC OF MATHEMATIC'S
// FORMULA /////////////
////////////////////////////////////////
/////////////////////////////////
a = V[0][0]*(V[1][1]*V[2][2]-(V[2][1]*V[1][2]));
b = V[0][1]*(V[1][0]*V[2][2]-(V[2][0]*V[1][2]));
c = V[0][2]*(V[1][0]*V[2][1]-(V[2][0]*V[1][1]));
delta = a-b+c;
a = T[0]*(V[1][1]*V[2][2]-(V[2][1]*V[1][2]));
b = V[0][1]*(T[1]*V[2][2]-(T[2]*V[1][2]));
c = V[0][2]*(T[1]*V[2][1]-(T[2]*V[1][1]));
delta_x = a-b+c;
a = V[0][0]*(T[1]*V[2][2]-(T[2]*V[1][2]));
b = T[0]*(V[1][0]*V[2][2]-(V[2][0]*V[1][2]));
c = V[0][2]*(V[1][0]*T[2]-(V[2][0]*T[1]));
delta_y = a-b+c;
a = V[0][0]*(V[1][1]*T[2]-(V[2][1]*T[1]));
b = V[0][1]*(V[1][0]*T[2]-(V[2][0]*T[1]));
c = T[0]*(V[1][0]*V[2][1]-(V[2][0]*V[1][1]));
delta_z = a-b+c;
if (delta ==0 && delta_x == 0)
{
gotoxy(25,10); printf ("Infinity of possibility.");
}
else
if (delta == 0 && delta_x !=0)
{
gotoxy(25,10); printf ("Impossible system!!");
}
if (delta != 0)
{
ans_x = delta_x / delta;
ans_y = delta_y / delta;
ans_z = delta_z / delta;
gotoxy(33,10); printf ("x = %.2f, y = %.2f z = %.2f", ans_x, ans_y, ans_z);
}
gotoxy(25,1); printf ("Do you want to quit (y)?");
answer = verification(resp);
}while (answer != 'y');
}
void sys_2_det()
{
int i, j;
float V[3][3], delta;
float X[2], Y[2];
char answer;
do
{
do
{
clrscr();
for (i=0;i<3;i++)
for (j=0;j<3;j++)
{
gotoxy(25,1); printf ("Enter the variable #%d of the row #%d", j+1, i+1);
V[i][j] = verification(v);
}
clrscr();
for (i=0;i<3;i++)
{
gotoxy(30,(2+i)*2); printf ("%.2f \t %.2f \t %.2f", V[i][0], V[i][1], V[i][2]);
}
printf ("Is the entry ok (y)?");
answer = verification(resp);
}while (answer != 'y');
delta = (X[1] * Y[2] - X[2] * Y[1]);
printf ("%.2f", delta);
gotoxy(25,1); printf ("Do you want to quit (y)?");
answer = verification(resp);
}while (answer != 'y');
}
void sys_3_det()
{
float V[3][3], T[3];
float det;
float a ,b, c;
char answer;
int i, j;
do
{
do
{
////////////////////////////////////////
////////////////////////////////
////////// ENTRY OF ALL THE VARIABLE
// //////////////////
////////////////////////////////////////
////////////////////////////////
clrscr();
for (i=0;i<3;i++)
for (j=0;j<3;j++)
{
gotoxy(20,1); printf ("Enter the variable #%d of the row #%d", j+1, i+1);
V[i][j] = verification(v);
clrscr();
}
for (i=0;i<3;i++)
{
gotoxy(20,(i+2));
printf ("%.2f%.2f%.2f", V[i][0], V[i][1], V[i][2]);
}
gotoxy(25,1); printf ("Is the entry correct (y)?");
answer = verification(resp);
}while (answer != 'y');
/////////////////////////////////////////////////////////////////////////
//////////// THE MAGIC OF MATHEMATIC'S
// FORMULA /////////////
////////////////////////////////////////
/////////////////////////////////
a = V[0][0]*(V[1][1]*V[2][2]-(V[2][1]*V[1][2]));
b = V[0][1]*(V[1][0]*V[2][2]-(V[2][0]*V[1][2]));
c = V[0][2]*(V[1][0]*V[2][1]-(V[2][0]*V[1][1]));
det = a-b+c;
gotoxy(20,1); printf ("Do you want to quit (y)?");
answer = verification(resp);
}while (answer != 'y');
}