Thursday, April 30, 2009

Extra in OOP_C++

/* Scientific Calculator */

#include< iostream.h >
#include< conio.h >
#include< math.h >
#include< stdio.h >
#include< process.h >
#include< graphics.h >
#include< ctype.h >
double rfact(double);
void main()
{
int ch;
int k,n,choice;
float sinx,cosx,tanx,cotx,secx,cosecx;
float x,j,i;
clrscr();
cin>>ch;
if(ch==4444)
{
int gdriver=DETECT,gmode, errorcode;
initgraph(&gdriver,&gmode,"e:\\tc\\bgi");
setbkcolor(LIGHTRED);
settextstyle(7,0,9);
outtextxy(45,160,"..WELCOME!..");//page1
getch();
closegraph();
}
getch();
clrscr();
textcolor(YELLOW+128);
gotoxy(30,12);
cprintf("COMPUTER EXHIBITION\n\r");//page2
textcolor(GREEN);
gotoxy(30,14);
cprintf(" Dhanoop Bhaskar \n\r");
textcolor(BLUE);
gotoxy(30,15);
cprintf(" C2 Batch\n\r");
textcolor(CYAN);
gotoxy(30,16);
cprintf(" CARDINAL .HSS\n\r ");
textcolor(RED+128);
gotoxy(33,19);
cprintf("INSTRUCTIONS:\n\r");
textcolor(YELLOW);
gotoxy(22,20);
cprintf("\(The Scientific Calculator enables to\n\r");
gotoxy(22,21);
cprintf("Find the values of trigonometric funtions\)\n\r ");
textcolor(LIGHTGREEN);
gotoxy(22,22);
cprintf(":Please try to give appropiate values only\n\r ");
gotoxy(22,23);
cprintf(":Follow the instructions given in brackets\n\r");
gotoxy(22,24);
cprintf(":Donot attempt malpractices\n\r");
gotoxy(22,25);
cprintf(":Use only numerical values\n\r");
getch();
do
{
clrscr();
gotoxy(30,9);
textcolor(YELLOW+128) ;textbackground(RED) ;
cprintf(" SCIENTIFIC CALCULATOR \n\r");//page3
textcolor(YELLOW) ;textbackground(BLACK) ;
gotoxy(30,13);
cprintf(" MAIN MENU \n\r" );
gotoxy(30,15);
cprintf("1.SINE: \n\r");
gotoxy(30,16);
cprintf("2.COSINE: \n\r");
gotoxy(30,17);
cprintf("3.TANGENT: \n\r");
gotoxy(30,18);
cprintf("4.COTANGENT: \n\r");
gotoxy(30,19);
cprintf("5.SECANT: \n\r");
gotoxy(30,20);
cprintf("6.COSECANT: \n\r");
gotoxy(30,21);
cprintf("7.EXIT: \n\r");
cout<<"\n Enter your choice ";
cin>>choice;
if(choice< 7)
{
cout<<"\n Enter the angle in degrees ";
cout<<"\n (Please enter angle between -360&+360 ) ";
cin>>i;
if(i>360||i< -360)
{
cout<<"\n Sorry!!!!... cannot find the values at present ";
getch();
exit(0);
}
x=i*0.01745;
}

switch(choice)
{
case 1:sinx=0;//sine
for(j=1,k=1;j< 50;j+=2,k++)
{
if(k%2==0)
n=-1;
else
n=1;
sinx=(sinx)+((n*pow(x,j))/(rfact(j)));
}
if(i==0||i==180||i==360)
cout<<"\n sinx="<< 0;
else if(i==90)
cout<<"\n sinx="<< 1;
else if(i==270)
cout<<"\n sinx="<< -1;
else
cout<<"\n sin x="<< sinx;
getch();
break;
case 2:cosx=1;//cosine
for(j=2,k=1;j< 50;j+=2,k++)
{
if(k%2==0)
n=1;
else
n=-1;
cosx=(cosx)+((n*pow(x,j))/(rfact(j)));
}
if(i==0||i==360)
cout<<"\n cosx="<< 1;
else if(i==180)
cout<<"\n cosx="<< -1;
else if(i==90||i==270)
cout<<"\n cosx="<<0;
else
cout<<"\n cos x="<< cosx;
getch();
break;
case 3:sinx=0;//tangent
for(j=1,k=1;j< 50;j+=2,k++)
{
if(k%2==0)
n=-1;
else
n=1;
sinx=(sinx)+((n*pow(x,j))/(rfact(j)));
}
cosx=1;
for(j=2,k=1;j< 50;j+=2,k++)
{
if(k%2==0)
n=1;
else
n=-1;
cosx=(cosx)+((n*pow(x,j))/(rfact(j)));
}
if(i==90||i==270||cosx==0)
{
cout<<"\n tan x is not defined ";
cout<<"\n\( cosx="<< 0<<" appro\)";
}
else if(i==0||i==180||i==360)
cout<<"\n tanx="<< 0;
else
{
tanx=sinx/cosx;
cout<<"\n tan x="<< tanx;
getch();}
break;
case 4:sinx=0;//cotangent
for(j=1,k=1;j< 50;j+=2,k++)
{
if(k%2==0)
n=-1;
else
n=1;
sinx=(sinx)+((n*pow(x,j))/(rfact(j)));
}
cosx=1;
for(j=2,k=1;j< 50;j+=2,k++)
{
if(k%2==0)
n=1;
else
n=-1;
cosx=(cosx)+((n*pow(x,j))/(rfact(j)));
}
if(i==0||i==90||i==180||i==270||i==360||sinx==0)
{
cout<<"\n cot x is not defined ";
cout<<"\n\( sinx="<< 0<<" appro\)";
}
else
{
cotx=cosx/sinx;
cout<<"\n cot x="<< cotx;
getch();
}
break;
case 5:cosx=1;//secant
for(j=2,k=1;j< 50;j+=2,k++)
{
if(k%2==0)
n=1;
else
n=-1;
cosx=(cosx)+((n*pow(x,j))/(rfact(j)));
}
if(i==90||i==270||cosx==0)
{
cout<<"\n sec x is not defined ";
cout<<"\n\( cosx="<< 0<<" appro\)";
}
else if(i==0||i==360)
cout<<"\n secx="<< 1;
else if(i==180)
cout<<"\n secx="<< -1;
else
{
secx=1/cosx;
cout<<"\n sec x="<< secx;
getch();
}
break;
case 6:sinx=0;//cosecant
for(j=1,k=1;j< 50;j+=2,k++)
{
if(k%2==0)
n=-1;
else
n=1;
sinx=(sinx)+((n*pow(x,j))/(rfact(j)));
}
if(i==0||i==180||i==360||sinx==0)
{
cout<<"\n cosec x is not defined ";
cout<<"\n\( sinx="<< 0<<" appro\)";
}
else if(i==90)
cout<<"\n cosecx="<< 1;
else if(i==270)
cout<<"\n cosecx="<< -1;
else
{
cosecx=1/sinx;
cout<<"\n cosec x="<< cosecx;
getch();
}
break;
case 7:exit(0);
default:cout<<"\n Invalid choice ";
}
getch();
}while(1);
}

double rfact(double d)
{
if(d<2)
return (1);
else
return (d*rfact(d-1));
}


/* Matrix Manipulation */

#include< iostream.h >
#include< conio.h >
#include< stdio.h >
#include< math.h >
#include< process.h >
#include< graphics.h >
void main()
{
clrscr();
int choice;
int a[20][20],i,j,m,n,flag;
{
int gdriver=DETECT,gmode, errorcode;
initgraph(&gdriver,&gmode,"e:\\tc\\bgi");
setbkcolor(LIGHTRED);
settextstyle(7,0,9);
outtextxy(40,100,"COMPUTER");
outtextxy(45,170," PROJECT");//page1
getch();
closegraph();
}
do
{
clrscr();
textcolor(YELLOW+128);textbackground(RED);
gotoxy(30,10);
cprintf(" MAIN MENU \n\r");
textcolor(YELLOW);textbackground(BLACK);
gotoxy(30,12);
cprintf("1.ROW SUM \n\r");
textcolor(YELLOW);
gotoxy(30,13);
cprintf("2.COLUMN SUM \n\r");
textcolor(YELLOW);
gotoxy(30,14);
cprintf("3.TRACE \n\r");
textcolor(YELLOW);
gotoxy(30,15);
cprintf("4.TRANSPOSE \n\r");
textcolor(YELLOW);
gotoxy(30,16);
cprintf("5.DIAGONAL MATRIX \n\r");
textcolor(YELLOW);
gotoxy(30,17);
cprintf("6.SCALAR MATRIX \n\r");
textcolor(YELLOW);
gotoxy(30,18);
cprintf("7.IDENTITY MATRIX \n\r");
textcolor(YELLOW);
gotoxy(30,19);
cprintf("8.EXIT \n\r");
cprintf(" Enter your choice \n\r");
cin>>choice;
if(choice==8)
exit(0);
else
{
cout<<"\n Enter the rowsize & columnsize";
cin>>m>>n;
cout<<"\n Enter the matrix ";
for(i=0;i< m;i++)
{
for(j=0;j< n;j++)
{
cin>>a[i][j];
}
}
}//end of else
cout<<"\n The matrix is ";
for(i=0;i< m;i++)
{cout<<"\n";
for(j=0;j< n;j++)
{cout<< a[i][j]<<"\t";
}
}
switch(choice)
{
case 1:int rsum;
for(i=0;i< m;i++)
{
rsum=0;
for(j=0;j< n;j++)
rsum+=a[i][j];
cout<<"\n Sum of row "<< i+1<<"= "<< rsum;
}
getch();
break;
case 2:int csum;
for(i=0;i< m;i++)
{
csum=0;
for(j=0;j< n;j++)
csum+=a[j][i];
cout<<"\n Sum of column "<< i+1<<"= "<< csum;
}
getch();
break;
case 3:int tsum;
if(m==n)
{
tsum=0;
for(i=0;i< m;i++)
tsum+=a[i][i];
cout<<"\n Trace "<< tsum;
}
else cout<<"\n Impossible to find the trace";
getch();
break;
case 4:cout<<"\n The transpose is ";
for(j=0;j< n;j++)
{
cout<<"\n";
for(i=0;i< m;i++)
cout<< a[i][j]<<"\t";
}
getch();
break;
case 5:if(m==n)
{
for(i=0;i< m;i++)
{
flag=0;
for(j=0;j< n;j++)
{
if(i==j)
continue;
else if((a[i][j]!=0)||(a[i][i]==0))
flag=1;
}
if(flag==1)
break;
}
if(flag==0)
cout<<"\n The matrix is a diagonal matrix ";
else
cout<<"\n The matrix is not a diagonal matrix ";
}
else
cout<<"\n Please enter a square matrix ";
getch();
break;
case 6:if(m==n)
{
int x;
for(i=0;i< m;i++)
{
x=a[0][0];
flag=0;
for(j=0;j< n;j++)
{
if((i==j)&&(a[i][j]==x))
continue;
else if((a[i][j]!=0)||(a[i][i]==0))
flag=1;
}
if(flag==1)
break;
}
if(flag==0)
cout<<"\n It is a scalar matrix ";
else
cout<<"\n It is not a scalar matrix ";
}
else
cout<<"\n Please enter a square matrix ";
getch();
break;
case 7:if(m==n)
{
int x;
for(i=0;i< m;i++)
{
x=a[0][0];
flag=0;
for(j=0;j< n;j++)
{
if((i==j)&&(a[i][j]==x))
continue;
else if((a[i][j]!=0)||(a[i][i]==0))
flag=1;
}
if(flag==1)
break;
}
if((flag==0)&&(x==1))
cout<<"\n It is an identity matrix ";
else
cout<<"\n It is not an identity matrix ";
}
else
cout<<"\n Please enter a square matrix ";
getch();
break;
default:cout<<"\n Invalid choice ";
}
getch();
}while(1);
}

No comments:

Post a Comment

Please let us know your comments and suggestions on this blog. Your comments are of great value to us.