Skip to main content

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);
}

Comments

Popular posts from this blog

Blog Directory

..................................................................................................... Read this before accessing the blog resources For new posts please visit  https://theinsantechie.in NB: You can have access to each post in this blog by just clicking on the corresponding link given below. Note that the gadget named "Blog Archive" also includes the links to these posts. But it is easier to refer to the posts through the links provided below. ..................................................................................................... 1. Data structure programs. 2. OOP Extra Questions with Answers. 3. OOP in C++ - extra programs. 4. Quiz Questions with answers :1 5. Quiz Questions with answers :2 6. Quiz Questions with answers :3 7. Quiz Questions with answers :4 8. Quiz Questions with answers :5 9. Aptitude questions with answers. 10. Infosys Questions with Answers. 11. DS lab Extra Questions. ...

Infosys Questions with Answers

  Father's age is three years more than three times the son's age. After three years, father's age will be ten years more than twice the son's age. What is the father's present age. 33 years. (2 marks) Find the values of each of the alphabets. N O O N S O O N + M O O N ---------- J U N E 9326 (2 marks) There are 20 poles with a constant distance between each pole A car takes 24 second to reach the 12th pole. How much will it take to reach the last pole. 41.45 seconds (2 marks) Let the distance between two poles = x Hence 11x:24::19x:? A car is travelling at a uniform speed. The driver sees a milestone showing a 2-digit number. After travelling for an hour the driver sees another milestone with the same digits in reverse order. After another hour the driver sees another milestone containing the same two digits. What is the average speed of the driver. 45 kmph (4 marks) The minute and the hour hand of a watch meet every 65 minutes. How much does the watch lo...

Aptitude Questions

Aptitude Questions 1. Hans is standing behind Gerrie and at the same time Gerrie is standing behind Hans. How is this possible ? 2. A cyclist drove one kilometer, with the wind in his back, in three minutes and drove the same way back, against the wind in four minutes. If we assume that the cyclist always puts constant force on the pedals, how much time would it take him to drive one kilometer without wind ? 3. A cyclist drove one kilometer, with the wind in his back, in three minutes and drove the same way back, against the wind in four minutes. If we assume that the cyclist always puts constant force on the pedals, how much time would it take him to drive one kilometer without wind? 4. Below is an equation that isn't correct yet. By adding a number of plus signs and minus signs between the ciphers on the left side (without changes the order of the ciphers), the equation can be made correct. 123456789 = 100 How many different ways are there to make the equation correct? 5. Tom has...