Anda di halaman 1dari 43

OVERVIEW OF C++

C++

is

statically

typed,

compiled,

general-purpose, case-sensitive, free-form


programming

language

that

supports

procedural, object-oriented, and generic


programming.
C++
is
regarded

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

Ease of fabrication and maintenance


The

object

oriented

programming

has

been

developed with a view to overcome the drawbacks


of conventional programming approaches.

OBJECT ORIENTED PROGRAMMING


DATA ABSTRACTION: Refers to the act of
representing

essential

features

without

including the background details.


Data Encapsulation: The wrapping up of data
and operations/functions into a single unit is
know as Encapsulation
Modularity: Property of a system that has been
developed into a set of cohesive and loosely
coupled modules.
Inheritance: Capability of one class to derive
properties from another class.
Polymorphism: Ability for a message or data to
be processed in more than one form.

2 | Page

NEED FOR THE PROJECT


We present you a project that handles matrix
operations

such

subtraction,

as

matrix

addition,

multiplication,

finding

determinant, inverse, transpose and solving


equations

with

variables

using

matrix

method.
This project provides a way in which matrix
operations

can

be

done

easily

without

compromising the simplicity so that it is


intelligent

to

all

and

at

the

same

time

preserving the real world concept by making


use of classes.

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>

FUNCTIONS OF EACH HEADER FILE


#include<fstream.h>
It is used to implement input and output
facilities
#include<conio.h>
It implements clear screen. clrscr(), get a
character from user getch()
#include<process.h>
To execute exit() function
#include<string.h>
Performs operations like
string copy and compare
#include<stdio.h>
Defines macros and types needed for I/O
package.

CLASSES AND OBJECTS


CLASS USER
IN PRIVATE
5 | Page

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

subtraction and addition.


GLOBAL FUNCTIONS
void passchange();
void userchangecheck();
void add();
void sub();
void mul();

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

int det; float f[5]

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:

/* PROJECT: MATRIX MAN CBSE: 2016


by
SANJAY.S
SREERAMJI.K.S
NIRMAL.V*/
#include<fstream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<process.h>
#include<string.h>
#include<stdio.h>

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;

cout<<"\nPassword (It must atleast contain 4 capital , 4 small alphabets and 4


integers):";
cin>>pass;
int len;
len=strlen(pass);
i=-1;
//Password integrity check
int s,num=s=-1;
while(++i<len)
{
if(pass[i]>='a'&&pass[i]<='z')
s++;
else
num++;
}
if(!((s>1)&&(num>1)))
{
cout<<"\n\t\tPassword is weak.It must contain 3 atleast 3 alphabets and 3
integers\n";
system("pause");
clrscr();
goto G;
}
clrscr();

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;

public: void inpu();


void eqn();
void inv();
void trans();
void dete();

}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

matrix\n6.Equation solver\n7.Transpose of a matrix\nYour choice :";


//cout<<op;
op=getch();
clrscr();
}
void main()
{
clrscr();
cout<<"\n\n\n\n\n\n\t\t\t\a\aMATRIX MAN\n\n";
cout<<"\t\t\t\a\a______ ___\n";
cout<<"\t\t\t\a\a------ ---";
cout<<"\nBY\n";
cout<<"NIRMAL.V\nSANJAY.S\nK.S.SREERAMJI";
delay(1000);
char names[30],passw[30],newpass[30],choi;
int x,cp,op1;
T:
cout<<"\n1.Log in with your account\n2.Sign up (create a new account)\n3.Delete
Account\n4.Password Change\n5.Exit\nYour Choice:";
33 | P a g e

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;

default:cout<<"\n Wrong choice , Reenter your choice ";


getch();
}
clrscr();
cout<<"\nDo you want to continue? Enter y if yes.";
choi=getch();
}while(choi=='y'||choi=='Y');
36 | P a g e

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

Anda mungkin juga menyukai