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.

Review Questions

Chapter I: Principles of Object-Oriented Programming 1. Which of the following languages is not a procedure-oriented programming language? a) ALGOL b) COBOL c) FORTRAN d) None of the above 2. Which of the following programming approach used functions as a key concept to perform action-oriented tasks? a) Structured programming b) Modular programming c) Procedure-oriented programming d) Object-oriented programming 3. Identify the drawback of using procedure-oriented programming, if any: a) Data is hidden from external functions b) New functions can be added whenever necessary c) Does not reflect real world problems d) All of the above 4. Which is not associated with Object-oriented programming? a) Data abstraction b) Automatic initialization c) Dynamic binding d) None 5. The term operator overloading in C++ refers to: a) Inheritance b) Message passing c) Polymorphism d) None 6. Which one of the following OOP concepts enables reusability of components? a) Inheritance b) Encapsulation c) P

Quiz4

..................................................................................................... 1. When light is scattered from an atom or molecule, most photons are elastically scattered (Rayleigh scattering), such that the scattered photons have the same energy (frequency) and wavelength as the incident photons. However, a small fraction of the scattered light (approximately 1 in 10 million photons) is scattered by an excitation, with the scattered photons having a frequency different from, and usually lower than, the frequency of the incident photons. Which phenomenon are we talking about? Answer: Raman Effect 2. Who was the first scientist to win Nobel prize twice? Answer: Madam Marrie Currie 3. Formally designated as the MED, it refers specifically to the period of the project from 1939–1946 under the control of the U.S. Army Corps of Engineers, under the administration of General Leslie R. Groves. The scientific research was directed by American physicist J. Robert Oppenhei