C++
is
statically
typed,
compiled,
language
that
supports
as
a middle-
level language.
C++ was developed by Bjarne Stroustrup
as an enhancement to the C language and
originally named C with Classes but later it
was renamed C++ in 1983.
C++ is a superset of C, and that virtually
any legal C program is a legal C++
program.
ADVANTAGES OF C++:
Re use of code
Ease of comprehension
Easy redesign and extension
1 | Page
object
oriented
programming
has
been
essential
features
without
2 | Page
such
subtraction,
as
matrix
addition,
multiplication,
finding
with
variables
using
matrix
method.
This project provides a way in which matrix
operations
can
be
done
easily
without
to
all
and
at
the
same
time
3 | Page
REQUIREMENTS
HARDWARE
Intel Pentium
512 MB RAM
CD ROM
Higher resolution monitor
Mouse
Keyboard
SOFTWARE
Turbo C++
Notepad
Windows xp,7,8,10
4 | Page
HEADER FILES
#include<fstream.h>
#include<conio.h>
#include<process.h>
#include<string.h>
#include<stdio.h>
char id[40];
char pass[40];
IN PUBLIC
char*usercheck();
char* passcheck();
void create();
void passch();
void reset()
void error()
OBEJCTS:- 1. a - For creating account and deleting
2. temp temporary object to do swapping
CLASS add_mul_sub
IN PRIVATE
int a[5][5],b[5][5],c[5][5];
int r1,c1,r2,c2,r3,c3,i,j,k,d[5][5],n;
IN PUBLIC
Void create();
int passchangecheck();
OBJECT:- 1. ams Used to access the member funtions to
perform
the
required
operation
like
multiplication
CLASS det
IN PRIVATE
Int r,c,a[5][5],b[5][5],i,j,k,w[5][5],de;
[5],e[5][5];
IN PUBLIC
void inpu();
6 | Page
void eqn();
void inv();
void trans();
void dete();
OBJECTS:- 1. deter Object called to perform operations like
finding inverse , determinant , solving equations with 2
variables and transpose.
7 | Page
FUNCTIONS
MEMBER FUNCTIONS
char* usercheck();
To check whether the username exists
char* passcheck();
To check whether the password is right
void create();
To create a new account
voidpasschange();
To change password
void create();
To get input for matrix
void display();
To display the final matrix
void add();
To add 2 or 3 matrices
void sub();
To subtract 2 matrices
void mul();
To multiply 2 matrices
void eqn();
To solve equations of 2 variables
void inv();
To find the inverse of a matrix
void trans();
To find the transpose of a matrix
void dete();
To find determinant of a Matrix
8 | Page
SOURCE CODE:
int n,vha=0;
float m;
void reset(void)
{
vha=0;
}
void error(void)
{
9 | Page
vha++;
if(vha==3)
exit(0);
}
class user
{
char id[40];
char pass[40];
char sec1a[40];
char sec2a[40];
public:
char sec1[200];
char sec2[200];
char* usercheck();
char* passcheck();
int passchangecheck(char a[],char b[]);
void create();
int passchangecheck();
}a,temp,*newn;
char* user::usercheck()
{return id;}
char* user::passcheck()
{return pass;}
int user::passchangecheck(char a[],char b[])
10 | P a g e
{
int i=-1;
//not case sensitive as strcmp
while(a[++i]!='\0')
{
if(!((a[i]==sec2a[i])||(a[i]==sec2a[i]+32)))
return -1;
}
if( !(sec1a[i--]=='\0'))
return -1;
i=-1;
while(b[++i]!='\0')
{
if(!(a[i]==sec2a[i]||a[i]==sec2a[i]+32))
return -1;
}
if(!(sec2a[i--]=='\0'))
return -1;
clrscr();
cout<<"Sucessfully Answered\n";
system("pause");
G:
clrscr();
cout<<"\nUser Name
11 | P a g e
: "<<id;
12 | P a g e
cout<<"Sucessfully changed";
system("pause");
clrscr();
return 1;
}
void user::create()
{
clrscr();
cout<<"\n\t\tNew Account \n";
system("pause");
n=n+1;
A://if user name already exist's
cout<<"\nUser Name : ";
cin>>id;
ifstream check("USERS.DAT",ios::binary|ios::app);
while(check)
{
check.read((char*)&temp,sizeof(temp));
if(!(strcmp(temp.usercheck(),id)))
{
clrscr();
cout<<"\t\tUser Name already exist\n";
system("pause");
clrscr();
13 | P a g e
goto A;
}
}
check.close();
clrscr();
B:
cout<<"\nUser Name
: "<<id;
cout<<"\nPassword:";
cin>>pass;
int len;
len=strlen(pass);
int i=-1;
//Password integrity check
int c,s,num=s=c=-1;
while(++i<len)
{
if(pass[i]>='A'&&pass[i]<='Z')
c++;
else if(pass[i]>='a'&&pass[i]<='z')
s++;
else
num++;
}
if(!((c>2)&&(s>2)&&(num>2)))
14 | P a g e
{
cout<<"\n\t\tPassword is weak.It must contain 3 atleast 3 alphabets and 3
integers\n"";
system("pause");
clrscr();
goto B;
}
clrscr();
cout<<"\nJust one step ahead to completion\n";
system("pause");
clrscr();
cout<<"Type Security question 1:";
gets(sec1);
cout<<'\n';
cout<<"Answer :";
gets(sec1a);
cout<<'\n';
cout<<"Type Security question 2:";
gets(sec2);
cout<<'\n';
cout<<"Answer :";
gets(sec2a);
clrscr();
ofstream users("USERS.DAT",ios::binary|ios::app);
15 | P a g e
users.seekp(0,ios::end);
users.write((char *)newn,sizeof(user));
users.close();
cout<<"Sucessfull Creation";
}
void passchange()
{
reset();
F:
char id[40];
clrscr();
cout<<"\nUser Name : ";
cin>>id;
fstream check("USERS.DAT",ios::binary|ios::app|ios::in|ios::out);
while(check)
{
check.read((char*)&temp,sizeof(temp));
if((strcmp(temp.usercheck(),id))&&!(check))
{
clrscr();
error();
cout<<"\n\t\tUser Name doesn't exist\n";
system("pause");
clrscr();
16 | P a g e
goto F;
}
else if(!(strcmp(temp.usercheck(),id)))
break;
}
reset();
clrscr();
char sec1a[40],sec2a[40];
H:
cout<<"\nUser Name :"<<id<<'\n';
cout<<temp.sec1<<" :";
cin>>sec1a;
cout<<'\n'<<temp.sec2<<" :";
cin>>sec2a;
int ch;
ch=temp.passchangecheck(sec1a,sec2a);
if(ch!=1)
{
cout<<"\nAnswer is Wrong\n";
system("pause");
clrscr();
goto H;
}
check.seekg(-1*sizeof(user),ios::cur);
17 | P a g e
check.write((char*)&temp,sizeof(temp));
}
void usercheck()
{
char id[40];
C:
cout<<"\nUser Name : ";
cin>>id;
fstream check("USERS.DAT",ios::binary|ios::app|ios::in|ios::out);
while(check)
{
check.read((char*)&temp,sizeof(temp));
if(strcmp(temp.usercheck(),id)&&!(check))
{
clrscr();
error();
cout<<"\n\t\tUser Name doesn't exist\n";
system("pause");
clrscr();
goto C;
}
else if(!strcmp(temp.usercheck(),id))
break;
}
18 | P a g e
reset();
char temps[100];
strcpy(temps,temp.passcheck());
clrscr();
D:
cout<<"\nUser Name : "<<id;
cout<<"\nPassword :";
char pass[40];
cin>>pass;
if(strcmp(pass,temps))
{
clrscr();
error();
cout<<"\n\t\t Wrong password\n";
system("pause");
clrscr();
goto D;
}
clrscr();
cout<<"Sucessfull";
system("pause");
clrscr();
}
void del()
19 | P a g e
{
reset();
cout<<"\t\tDelete Account\n";
C:
char id[50];
int vha=0;
cout<<"\nUser Name : ";
cin>>id;
fstream check("USERS.DAT",ios::binary|ios::app|ios::in|ios::out);
while(check)
{
check.read((char*)&temp,sizeof(temp));
if(strcmp(temp.usercheck(),id)&&!(check))
{
clrscr();
vha++;
cout<<"\t\tUser Name doesn't exist\n";
error();
system("pause");
clrscr();
goto C;
}
else if(!strcmp(temp.usercheck(),id))
break;
20 | P a g e
}
char temps[100];
strcpy(temps,temp.passcheck());
clrscr();
reset();
D:
cout<<"\nUser Name : "<<id;
cout<<"\nPassword :";
char pass[40];
cin>>pass;
if(strcmp(pass,temp.passcheck()))
{
clrscr();
cout<<"\n\t\t Wrong password\n";
error();
system("pause");
clrscr();
goto D;
}
check.seekg(-1*sizeof(temp),ios::cur);
fstream check2("USERS.DAT",ios::binary|ios::in|ios::out);
check2.seekg(check.tellg()+1*sizeof(temp),ios::beg);
while(check2)
{
21 | P a g e
check2.read((char*)&temp,sizeof(temp));
check.write((char*)&temp,sizeof(temp));
}
user *newo=new user;
check.write((char *)newo,sizeof(temp));
delete newo;
}
class add_sub_mul
{
int a[5][5],b[5][5],c[5][5];
int r1,c1,r2,c2,r3,c3,i,j,k,d[5][5],n;
public:
void inpu();
void displ(int f[5][5],int c1);
void add();
void sub();
void mul();
}ams;
void add_sub_mul::inpu()
{
cout<< "\n Enter the no of matrices ( 2 or 3) ";
cin>>n;
cout<<" \n Enter the row or column of the square matrix ( one input ) ";
22 | P a g e
cin>>c1;
for(i=1;i<=n;i++)
{ cout<<"\nEnter elements of matrix "<<i;
for(j=0;j<c1;j++)
for(k=0;k<c1;k++)
{
if(i==1)
cin>>a[j][k];
if(i==2)
cin>>b[j][k];
if(i==3)
cin>>c[j][k];
}
if(i==1)
displ(a,c1);
if(i==2)
displ(b,c1);
if(i==3)
displ(c,c1);
}}
void add_sub_mul::displ(int f[5][5],int c1)
{
for(j=0;j<c1;j++)
{cout<<"\n";
23 | P a g e
for(k=0;k<c1;k++)
{
cout<<f[j][k]<<" ";
}}}
void add_sub_mul::add()
{
inpu();
for(i=0;i<c1;i++)
for(j=0;j<c1;j++)
if(n==2) d[i][j]=a[i][j]+b[i][j];
else d[i][j]=a[i][j]+b[i][j]+c[i][j];
cout<<"\nThe required matrix after addition is \n";
displ(d,c1);
}
void add_sub_mul::sub()
{
cout<<" \n Enter the row or column of the square matrix ( one input ) ";
cin>>c1;
cout<<"\n Enter the elements of matrix 1 ";
for(i=0;i<c1;i++)
for(j=0;j<c1;j++)
cin>>a[i][j];
24 | P a g e
for(i=0;i<c1;i++)
{
for(j=0;j<c1;j++)
cout<<a[i][j]<<" ";
cout<<"\n";
}
cout<<"\n Enter the elements of matrix 2 ";
for(i=0;i<c1;i++)
for(j=0;j<c1;j++)
cin>>b[i][j];
for(i=0;i<c1;i++)
{
for(j=0;j<c1;j++)
cout<<b[i][j]<<" ";
cout<<"\n";
}
for(i=0;i<c1;i++)
for(j=0;j<c1;j++)
d[i][j]=a[i][j]-b[i][j];
cout<<"\nThe required matrix after sutraction is \n";
displ(d,c1);
}
25 | P a g e
void add_sub_mul::mul()
{
cout<<"\n Enter rows and columns of 2 matrices ";
d:cin>>r1>>c1>>r2>>c2;
if(c1!=r2)
{
cout<<"\nMatrix multiplication not possible (c1=r2) . Re-enter the rows and
columns";
goto d;
}
cout<<"\nEnter elements of matrix 1 ";
for(j=0;j<r1;j++)
for(k=0;k<c1;k++)
cin>>a[j][k];
for(j=0;j<r1;j++)
{
for(k=0;k<c1;k++)
cout<<a[j][k]<<" ";
cout<<"\n";
}
cout<<"\nEnter elements of matrix 2 ";
for(j=0;j<r2;j++)
for(k=0;k<c2;k++)
26 | P a g e
cin>>b[j][k];
for(j=0;j<r2;j++)
{
for(k=0;k<c2;k++)
cout<<b[j][k]<<" ";
cout<<"\n";
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
d[i][j]=0;
for(k=0;k<r2;k++)
d[i][j]+=(a[i][k]*b[k][j]);
cout<<d[i][j]<<" ";
}
cout<<"\n";
}
}
class det
{
int r,c,a[5][5],b[5][5],i,j,k,w[5][5],de;
float f[5][5],e[5][5];
27 | P a g e
int det;
}deter;
void det::inpu()
{cout<<"\n Enter the row or column ofthe square matrix (one inpuut - 2 or 3) ";
cin>>r;
cout<<"\nEnter matrix ";
for(i=0;i<r;i++)
for(j=0;j<r;j++)
cin>>e[i][j];
}
void det::dete()
{
inpu();
if(r==3)
{
det=e[0][0]*((e[1][1]*e[2][2])-(e[2][1]*e[1][2]))
-e[0][1]*((e[1][0]*e[2][2])-(e[2][0]*e[1][2]))
28 | P a g e
+e[0][2]*((e[1][0]*e[2][1])-(e[2][0]*e[1][1]));
cout<<"\nDeterminant ="<<det;
}
else
{
de=e[0][0]*e[1][1]-(e[1][0]*e[0][1]);
cout<<"\n Determinant = "<<de;
}}
void det::inv()
{
inpu();
if(r==3)
{
det=e[0][0]*((e[1][1]*e[2][2])-(e[2][1]*e[1][2]))
-e[0][1]*((e[1][0]*e[2][2])-(e[2][0]*e[1][2]))
+e[0][2]*((e[1][0]*e[2][1])-(e[2][0]*e[1][1]));
if(det==0)
{
cout<<"\nInverse doesn't exist as determinant is "<<det;
}
else{
cout<<det<<"\n";
for(j=0;j<3;j++)
{
29 | P a g e
for(i=0;i<3;i++)
{
f[i][j]=((e[(i+1)%3][(j+1)%3] *
e[(i+2)%3][(j+2)%3]) - (e[(i+1)%3][(j+2)%3]*
e[(i+2)%3][(j+1)%3]));
m=f[i][j]/det;
cout<<m<<" ";
cout<<'\n'; }
} }
else
{
de=e[0][0]*e[1][1]-(e[1][0]*e[0][1]); if(de==0) cout<<"\nInverse doesn't exist as
determinant is "<<de;
else{w[0][0]=e[1][1]/de;
w[0][1]=-e[0][1]/de;
w[1][0]=-e[1][0]/de;
w[1][1]=e[0][0]/de;
cout<<"\n The inverse is ";
for(i=0;i<2;i++)
{
cout<<"\n";
for(j=0;j<2;j++)
cout<<w[i][j]<<" ";
30 | P a g e
}
} }}
void det::eqn()
{int n1,r[5][5];
cout<<"\nEquations of the form \na1 x + b1 y = c1\na2 x + b2 y = c2 ";
cout<<"\nEnter a1 ,b1, c1 "; cin>>a[0][0]>>a[0][1]>>b[0][0];
cout<<"\n ENter the a2,b2 ,c2 ";cin>>a[1][0]>>a[1][1]>>b[1][0];
int d[5][5];
de=a[0][0]*a[1][1]-(a[1][0]*a[0][1]);
if(de==0) cout<<"\nInverse doesn't exist as determinant is "<<de;
else
{
d[0][0]=a[1][1]/de;
d[0][1]=-a[0][1]/de;
d[1][0]=-a[1][0]/de;
d[1][1]=a[0][0]/de;
for(i=0;i<2;i++)
for(j=0;j<1;j++)
{r[i][j]=0;
for(k=0;k<2;k++)
r[i][j]+=(d[i][k]*b[k][j]);
}
cout<<"\nx is ="<<r[0][0];
31 | P a g e
cout<<"\ny is ="<<r[1][0];
}
}
void det::trans()
{
inpu();
if(r==2)
{
for(i=0;i<2;i++)
{
cout<<endl;
for(j=0;j<2;j++)
{
cout<<e[j][i]<<" ";
}}}
else
{
for(i=0;i<3;i++)
{
cout<<endl;
for(j=0;j<3;j++)
{
cout<<e[j][i]<<" ";
32 | P a g e
}}
}}
void options(char &op)
{ //int x;
cout<<"\n Enter your choice \n1.Addition of matrices\n2.Subtraction of
matrices\n3.Multiplication
of
matrices\n4.Determinant
of
matrix\n5.Inverse
of
char cham=getch();
clrscr();
switch(cham)
{
case '1':usercheck();
break;
case '2':newn=new user;
newn->create();
delete newn;
break;
case '3':del();
goto T;
case '4':passchange();
goto T;
case '5':clrscr();
cout<<"\nExit\n";
system("pause");
clrscr();
exit(0);
break;
}
do
34 | P a g e
{
char op2;
options(op2);
switch(op2)
{
case '1':
ams.add();
cout<<"\nPress any key to continue ";
getch();
break;
case '2':
ams.sub();
cout<<"\nPress any key to continue ";
getch();
break;
case '3':
ams.mul();
cout<<"\nPress any key to continue ";
getch();
break;
case '4':
deter.dete();
cout<<"\nPress any key to continue ";
getch();
35 | P a g e
break;
case '5':
deter.inv();
cout<<"\nPress any key to continue ";
getch();
break;
case '6':
deter.eqn();
cout<<"\nPress any key to continue ";
getch();
break;
case '7':
deter.trans();
cout<<"\nPress any key to continue ";
getch();
break;
getch();
clrscr();
}
37 | P a g e
OUTPUT
38 | P a g e
39 | P a g e
CONCLUSION
40 | P a g e
Thus
we
are
able
operations like
1.
Addition
2.
Subtraction
3.
Multiplication
4.
Finding
Determinant
Inverse
Solving equations
Transpose
41 | P a g e
to
perform
matrix
FUTURE ENHANCEMENTS
Background colours and other decorative
things may be introduces that the system
looks more interactive and attractive.
The administrative system can be well
defined to a complex grading system
42 | P a g e
BIBILIOGRAPHY
BOOKS:
CBSE Computer Science with C++(Laxmi
Publication)
C++Textbook XI by Sumita Arora
WEBSITES
www.cbsecsnip.com
www.cplusplus.com
www.indiaexam.com
43 | P a g e