C++ Program to perform: Matricies-add,subtract & more
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<iomanip.h>
void menu();
void determan();
void multi();
void add();
void subtract();
void exit();
void suberror1();
void suberror2();
void adderror1();
void adderror2();
void multierror2();
void multierror1();
void equation();
void equationerror1();
void equationerror2();
int main()
{ cout<<"\n\n\n\n\n";
cout<<setw(40)<<"*************\n";
cout<<setw(40)<<"| MATRACIES |\n";
cout<<setw(40)<<"*************\n";
cout<<setw(41)<<"*************\n\n";
cout<<setw(48)<<"Press any key to continue...";
getch();
clrscr();
menu();
return 0;
}
void menu() //This is the main menu.
{
int todo;
cout<<setw(20)<<"Main Menu\n\n";
cout<<"1-Find the dertermanants of a 3*3\n";
cout<<"2-Multiply two 3*3\n";
cout<<"3-Add two 3*3\n";
cout<<"4-Subtract two 3*3\n";
cout<<"5-Solve an equation with 3 variables\n";
cout<<"6-Exit Program\n\n";
cout<<"What do you want to do Today?-";
cin>>todo;
clrscr();
if (todo==1)
determan();
if (todo==2)
multi();
if (todo==3)
add();
if (todo==4)
subtract();
if (todo==5)
equation();
if (todo==7)
exit();
}
void determan() //This Figures out Determanants
{
int back,back2;
double a1,a2,a3,b1,b2,b3,c1,c2,c3,determ;
cout<<setw(20)<<"| a1 b1 c1 |\n";
cout<<setw(20)<<"| a2 b2 c2 |\n";
cout<<setw(21)<<"| a3 b3 c3 |\n\n";
cout<<"Enter a1-";
cin>>a1;
cout<<endl;
cout<<"Enter a2-";
cin>>a2;
cout<<endl;
cout<<"Enter a3-";
cin>>a3;
cout<<endl;
cout<<"Enter b1-";
cin>>b1;
cout<<endl;
cout<<"Enter b2-";
cin>>b2;
cout<<endl;
cout<<"Enter b3-";
cin>>b3;
cout<<endl;
cout<<"Enter c1-";
cin>>c1;
cout<<endl;
cout<<"Enter c2-";
cin>>c2;
cout<<endl;
cout<<"Enter c3-";
cin>>c3;
cout<<endl;
clrscr();
determ=(a1*b2*c3)+(a2*b3*c1)+(a3*b1*c2)-(c1*b2*a3)-(c2*b3*a1)-(c3*b1*a2);
if (determ==0)
cout<<"Impossible to solve, the Determanant of a matrix cannot equal 0"<<endl;
cout<<" | "<<a1<<" "<<b1<<" "<<c1<<" |\n";
cout<<"The Determanant of | "<<a2<<" "<<b2<<" "<<c2<<" |="<<determ<<endl;
cout<<" | "<<a3<<" "<<b3<<" "<<c3<<" |\n";
cout<<endl;
cout<<"Go Back to Main Menu Press 1 Go back to Determanants press 2-";
cin>>back;
clrscr();
if (back==1)
menu();
if (back==2)
determan();
if (back>2)
cout<<"Error Please only press 1 or 2."<<endl;
cout<<endl;
cout<<"Go Back to Main Menu Press 1 Go back to Determanants press 2-";
cin>>back;
clrscr();
if (back2==1)
menu();
if (back2==2)
determan();
if (back2>2)
cout<<"Error";
}
void multi() //This Multiplies two matriceis
{
int a,b;
double a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3,f1,f2,f3,w1,w2,w3,w4,w5,w6,w7,w8,w9;
cout<<setw(40)<<"| a1 b1 c1 | | d1 e1 f1 |"<<endl;
cout<<setw(40)<<"| a2 b2 c2 | * | d2 e2 f2 |"<<endl;
cout<<setw(40)<<"| a3 b3 c3 | | d3 e3 f3 |"<<endl;
cout<<endl;
cout<<"Enter Value for a1- ";
cin>>a1;
cout<<"Enter Value for a2- ";
cin>>a2;
cout<<"Enter Value for a3- ";
cin>>a3;
cout<<"Enter Value for b1- ";
cin>>b1;
cout<<"Enter Value for b2- ";
cin>>b2;
cout<<"Enter Value for b3- ";
cin>>b3;
cout<<"Enter Value for c1- ";
cin>>c1;
cout<<"Enter Value for c2- ";
cin>>c2;
cout<<"Enter Value for c3- ";
cin>>c3;
cout<<"Enter Value for d1- ";
cin>>d1;
cout<<"Enter Value for d2- ";
cin>>d2;
cout<<"Enter Value for d3- ";
cin>>d3;
cout<<"Enter Value for e1- ";
cin>>e1;
cout<<"Enter Value for e2- ";
cin>>e2;
cout<<"Enter Value for e3- ";
cin>>e3;
cout<<"Enter Value for f1- ";
cin>>f1;
cout<<"Enter Value for f2- ";
cin>>f2;
cout<<"Enter Value for f3- ";
cin>>f3;
w1=(a1*d1)+(b1*d2)+(c1*d3);
w2=(a2*d1)+(b2*d2)+(c2*d3);
w3=(a3*d1)+(b3*d2)+(c3*d3);
w4=(a1*e1)+(b1*e2)+(c1*e3);
w5=(a2*e1)+(b2*e2)+(c2*e3);
w6=(a3*e1)+(b3*e2)+(c3*e3);
w7=(a1*f1)+(b1*f2)+(c1*f3);
w8=(a2*f1)+(b2*f2)+(c2*f3);
w9=(a3*f1)+(b3*f2)+(c3*f3);
clrscr();
cout<<"| "<<a1<<" "<<b1<<" "<<c1<<" | | "<<d1<<" "<<e1<<" "<<f1<<" | | "<<w1<<" "<<w4<<" "<<w7<<" |"<<endl;
cout<<"| "<<a2<<" "<<b2<<" "<<c2<<" | * | "<<d2<<" "<<e2<<" "<<f2<<" |= | "<<w2<<" "<<w5<<" "<<w8<<" |"<<endl;
cout<<"| "<<a3<<" "<<b3<<" "<<c3<<" | | "<<d3<<" "<<e3<<" "<<f3<<" | | "<<w3<<" "<<w6<<" "<<w9<<" |"<<endl;
cout<<endl;
cout<<"Go back to Multiplication press 1 go back to Main Menu press 2- ";
cin>>a;
clrscr();
if (a==1)
multi();
if (a==2)
menu();
if (a>2)
multierror1();
}
void add() //This adds two matriceis
{
int a,b;
double a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3,f1,f2,f3,w1,w2,w3,w4,w5,w6,w7,w8,w9;
cout<<setw(40)<<"| a1 b1 c1 | | d1 e1 f1 |"<<endl;
cout<<setw(40)<<"| a2 b2 c2 | + | d2 e2 f2 |"<<endl;
cout<<setw(40)<<"| a3 b3 c3 | | d3 e3 f3 |"<<endl;
cout<<endl;
cout<<"Enter Value for a1- ";
cin>>a1;
cout<<"Enter Value for a2- ";
cin>>a2;
cout<<"Enter Value for a3- ";
cin>>a3;
cout<<"Enter Value for b1- ";
cin>>b1;
cout<<"Enter Value for b2- ";
cin>>b2;
cout<<"Enter Value for b3- ";
cin>>b3;
cout<<"Enter Value for c1- ";
cin>>c1;
cout<<"Enter Value for c2- ";
cin>>c2;
cout<<"Enter Value for c3- ";
cin>>c3;
cout<<"Enter Value for d1- ";
cin>>d1;
cout<<"Enter Value for d2- ";
cin>>d2;
cout<<"Enter Value for d3- ";
cin>>d3;
cout<<"Enter Value for e1- ";
cin>>e1;
cout<<"Enter Value for e2- ";
cin>>e2;
cout<<"Enter Value for e3- ";
cin>>e3;
cout<<"Enter Value for f1- ";
cin>>f1;
cout<<"Enter Value for f2- ";
cin>>f2;
cout<<"Enter Value for f3- ";
cin>>f3;
clrscr();
w1=a1+d1;
w2=a2+d2;
w3=a3+d3;
w4=b1+e1;
w5=b2+e2;
w6=b3+e3;
w7=c1+f1;
w8=c2+f2;
w9=c3+f3;
clrscr();
cout<<"| "<<a1<<" "<<b1<<" "<<c1<<" | | "<<d1<<" "<<e1<<" "<<f1<<" | | "<<w1<<" "<<w4<<" "<<w7<<" |"<<endl;
cout<<"| "<<a2<<" "<<b2<<" "<<c2<<" | + | "<<d2<<" "<<e2<<" "<<f2<<" |= | "<<w2<<" "<<w5<<" "<<w8<<" |"<<endl;
cout<<"| "<<a3<<" "<<b3<<" "<<c3<<" | | "<<d3<<" "<<e3<<" "<<f3<<" | | "<<w3<<" "<<w6<<" "<<w9<<" |"<<endl;
cout<<endl;
cout<<"Go back to Addition press 1 go back to Main Menu press 2- ";
cin>>a;
clrscr();
if (a==1)
add();
if (a==2)
menu();
if (a>2)
adderror1();
}
void subtract() //This Subtracts two matriceis
{ int a;
double a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,e1,e2,e3,f1,f2,f3,w1,w2,w3,w4,w5,w6,w7,w8,w9;
cout<<setw(40)<<"| a1 b1 c1 | | d1 e1 f1 |"<<endl;
cout<<setw(40)<<"| a2 b2 c2 | - | d2 e2 f2 |"<<endl;
cout<<setw(40)<<"| a3 b3 c3 | | d3 e3 f3 |"<<endl;
cout<<endl;
cout<<"Enter Value for a1- ";
cin>>a1;
cout<<"Enter Value for a2- ";
cin>>a2;
cout<<"Enter Value for a3- ";
cin>>a3;
cout<<"Enter Value for b1- ";
cin>>b1;
cout<<"Enter Value for b2- ";
cin>>b2;
cout<<"Enter Value for b3- ";
cin>>b3;
cout<<"Enter Value for c1- ";
cin>>c1;
cout<<"Enter Value for c2- ";
cin>>c2;
cout<<"Enter Value for c3- ";
cin>>c3;
cout<<"Enter Value for d1- ";
cin>>d1;
cout<<"Enter Value for d2- ";
cin>>d2;
cout<<"Enter Value for d3- ";
cin>>d3;
cout<<"Enter Value for e1- ";
cin>>e1;
cout<<"Enter Value for e2- ";
cin>>e2;
cout<<"Enter Value for e3- ";
cin>>e3;
cout<<"Enter Value for f1- ";
cin>>f1;
cout<<"Enter Value for f2- ";
cin>>f2;
cout<<"Enter Value for f3- ";
cin>>f3;
clrscr();
w1=a1-d1;
w2=a2-d2;
w3=a3-d3;
w4=b1-e1;
w5=b2-e2;
w6=b3-e3;
w7=c1-f1;
w8=c2-f2;
w9=c3-f3;
clrscr();
cout<<"| "<<a1<<" "<<b1<<" "<<c1<<" | | "<<d1<<" "<<e1<<" "<<f1<<" | | "<<w1<<" "<<w4<<" "<<w7<<" |"<<endl;
cout<<"| "<<a2<<" "<<b2<<" "<<c2<<" | - | "<<d2<<" "<<e2<<" "<<f2<<" |= | "<<w2<<" "<<w5<<" "<<w8<<" |"<<endl;
cout<<"| "<<a3<<" "<<b3<<" "<<c3<<" | | "<<d3<<" "<<e3<<" "<<f3<<" | | "<<w3<<" "<<w6<<" "<<w9<<" |"<<endl;
cout<<endl;
cout<<"Go back to Subtraction press 1 go back to Main Menu press 2- ";
cin>>a;
clrscr();
if (a==1)
subtract();
if (a==2)
menu();
if (a<2)
suberror1();
if (a=='a')
suberror1();
}
void exit() //This exits the program
{
char *yes;
cout<<"Thank you for usin my Matrix program. "<<endl;
cout<<endl;
cout<<"Are you sure you want to quit?(y/n)- ";
cin>>yes;
clrscr();
if (yes=="n")
menu();
}
void suberror1()
{
int c;
cout<<"Error Please only press 1 or 2."<<endl;
cout<<endl;
cout<<"Go back to Subtraction press 1 go back to Main Menu press 2- ";
cin>>c;
clrscr();
if (c==1)
subtract();
if(c==2)
menu();
if (c>2)
suberror2();
}
void suberror2()
{
int d;
cout<<"Error Please only press 1 or 2."<<endl;
cout<<endl;
cout<<"Go back to Subtraction press 1 go back to Main Menu press 2- ";
cin>>d;
clrscr();
if (d==1)
subtract();
if(d==2)
menu();
if (d>2)
suberror1();
}
void adderror1()
{
int c;
cout<<"Error Please only press 1 or 2."<<endl;
cout<<endl;
cout<<"Go back to Addition press 1 go back to Main Menu press 2- ";
cin>>c;
clrscr();
if (c==1)
add();
if(c==2)
menu();
if (c>2)
adderror2();
}
void adderror2()
{
int d;
cout<<"Error Please only press 1 or 2.\n";
cout<<endl;
cout<<"Go back to Addition press 1 go back to Main Menu press 2- ";
cin>>d;
clrscr();
if (d==1)
add();
if(d==2)
menu();
if (d>2)
adderror1();
}
void multierror1()
{
int c;
cout<<"Error Please only press 1 or 2.\n";
cout<<endl;
cout<<"Go back to Multiplication press 1 go back to Main Menu press 2- ";
cin>>c;
clrscr();
if (c==1)
multi();
if(c==2)
menu();
if (c>2)
multierror2();
}
void multierror2()
{
int d;
cout<<"Error Please only press 1 or 2.\n";
cout<<endl;
cout<<"Go back to Multiplication press 1 go back to Main Menu press 2- ";
cin>>d;
clrscr();
if (d==1)
multi();
if(d==2)
menu();
if (d>2)
multierror1();
}
void equation()
{
double a1,a2,a3,b1,b2,b3,c1,c2,c3,d1,d2,d3,x,y,z,m;
cout<<setw(30)<<"A1x+B1y+C1z=D1"<<endl;
cout<<setw(30)<<"A2x+B2y+C2z=D2"<<endl;
cout<<setw(30)<<"A3x+B3y+C3z=D3"<<endl;
cout<<endl;
cout<<"Enter the value for A1-";
cin>>a1;
cout<<"Enter the value for A2-";
cin>>a2;
cout<<"Enter the value for A3-";
cin>>a3;
cout<<"Enter the value for B1-";
cin>>b1;
cout<<"Enter the value for B2-";
cin>>b2;
cout<<"Enter the value for B3-";
cin>>b3;
cout<<"Enter the value for C1-";
cin>>c1;
cout<<"Enter the value for C2-";
cin>>c2;
cout<<"Enter the value for C3-";
cin>>c3;
cout<<"Enter the value for D1-";
cin>>d1;
cout<<"Enter the value for D2-";
cin>>d2;
cout<<"Enter the value for D3-";
cin>>d3;
clrscr();
x=((d1*b2*c3)+(d2*b3*c1)+(d3*b1*c2)-(c1*b2*d3)-(c2*b3*d1)-(c3*b1*d2))/((a1*b2*c3)+(a2*b3*c1)+(a3*b1*c2)-(c1*b2*a3)-(c2*b3*a1)-(c3*b1*a2));
y=((a1*d2*c3)+(a2*d3*c1)+(a3*d1*c2)-(c1*d2*a3)-(c2*d3*a1)-(c3*d1*a2))/((a1*b2*c3)+(a2*b3*c1)+(a3*b1*c2)-(c1*b2*a3)-(c2*b3*a1)-(c3*b1*a2));
z=((a1*b2*d3)+(a2*b3*d1)+(a3*b1*d2)-(d1*b2*a3)-(d2*b3*a1)-(d3*b1*a2))/((a1*b2*c3)+(a2*b3*c1)+(a3*b1*c2)-(c1*b2*a3)-(c2*b3*a1)-(c3*b1*a2));
cout<<"In the Equations:\n";
cout<<a1<<"x+"<<b1<<"y+"<<c1<<"z="<<d1<<endl;
cout<<a2<<"x+"<<b2<<"y+"<<c2<<"z="<<d2<<endl;
cout<<a3<<"x+"<<b3<<"y+"<<c3<<"z="<<d3;
cout<<"\n\n";
cout<<"X="<<x<<", Y="<<y<<", Z="<<z;
cout<<"\n\n";
cout<<"If you want to solve more equations press 1, if you want to go back\n";
cout<<" to the Main Menu press 2-";
cin>>m;
clrscr();
if (m==1)
equation();
if (m==2)
menu();
if (m>2)
equationerror1();
}
void equationerror1()
{
int c;
cout<<"Error Please only press 1 or 2.\n";
cout<<endl;
cout<<"If you want to solve more equations press 1, if you want to go back\n";
cout<<" to the Main Menu press 2-";
cin>>c;
clrscr();
if (c==1)
equation();
if(c==2)
menu();
if (c>2)
equationerror2();
}
void equationerror2()
{
int d;
cout<<"Error Please only press 1 or 2.\n";
cout<<endl;
cout<<"If you want to solve more equations press 1, if you want to go back\n";
cout<<" to the Main Menu press 2-";
cin>>d;
clrscr();
if (d==1)
equation();
if(d==2)
menu();
if (d>2)
equationerror1();
}
0 comments:
Post a Comment