Sunteți pe pagina 1din 13

Scientific Calculator

Run this code at Microsoft Visual C++


Note: Password is “farhan” if prompt.

/* ============= Header Files =============*/

#include <math.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>

/* ============= Basic Mathematics Fuctions =============*/

float sum(float no1,float no2)


{

return no1+no2;

float sub(float no1,float no2)


{

return no1-no2;

float mul(float no1,float no2)


{

return no1*no2;

float div(float no1,float no2)


{

return no1/no2;

int rem(int no1,int no2)


{
int t;
t=no1%no2;
return t;
}

/* ============= Trignometric Fuctions =============*/

double getSin(double angle)


{
angle=(3.14159*angle)/180;
return sin(angle);
}

double getCos(double angle)


{
angle=(3.14159*angle)/180;
return cos(angle);
}

double getTan(double angle)


{

angle=(3.14159*angle)/180;
return tan(angle);
}

double getSec(double angle)


{
angle=(3.14159*angle)/180;
return 1/cos(angle);
}

double getCosec(double angle)


{
angle=(3.14159*angle)/180;
return 1/sin(angle);
}

double getCotan(double angle)


{
angle=(3.14159*angle)/180;
return 1/tan(angle);
}

bool password(){
char pas[10];
system("cls");
cout<<"\n\n\n\n\n\n\n\n\t\t\tEnter the Password.... ";
cin>>pas;
if(strcmp(pas,"farhan")){
system("cls");
cout<<"\n\n\n\n\n\n\n\n\n\t\t\t Access was Denied";
return false;
}
return true;
}

void menue(){
int op;
do{
cout<<"--------------------------- Menue Driven Calculator
---------------------------";
cout<<"\n--------------\t\t By Muhammad Farhan Saleem
\t\t---------------";
cout<<"\n--------------------------- PF 1st Semester
---------------------------";
cout<<"\n\n\n\n\n\n\n\n\t\t\t\t[1]- Enter in the Program";
cout<<"\n\n\t\t\t\t[2]- Exit";
cout<<"\n\n\t\t\t\tYour Choice.... ";
cin>>op;
if(op!=1 && op!=2){
system("cls");
cout<<"\n\n\n\n\n\n\n\n\n\t\t\t\tInvalid Option";
}
else
if(op==1){
if(password()){
system("cls");
cout<<"\n\t\t =============
Password Accepted =============\n";
int ch;

do{
cout<<"\n\n\n\n\t\t\t\t[1]- Simple
Calculator";
cout<<"\n\n\t\t\t\t[2]- Scientific
Calculator";
cout<<"\n\n\t\t\t\t[3]- Up";
cout<<"\n\n\t\t\t\tYour Choice.... ";
cin>>ch;

if(ch!=1 && ch!=2 && ch!=3){


system("cls");
cout<<"\n\n\n\n\n\n\n\n\n\t\t\t\tInvalid Option";
}

/* =====================
Simple Calculator ===================== */
else
if(ch==1){
system("cls");
int op;

do{
cout<<"\n\t\t
============= Simple Calculator =============";

cout<<"\n\n\n\n\n\t\t\t\t [1]- Addition";


cout<<"\n\n\t\t\t\t
[2]- Subtration";
cout<<"\n\n\t\t\t\t
[3]- Multiplication";
cout<<"\n\n\t\t\t\t
[4]- Division";
cout<<"\n\n\t\t\t\t
[5]- Remainder";
cout<<"\n\n\t\t\t\t
[6]- Up";
cout<<"\n\n\t\t\t\t
Your Choice.... ";
cin>>op;

if(op!=1 && op!=2 &&


op!=3 && op!=4 && op!=5 && op!=6){
system("cls");

cout<<"\n\n\n\n\n\n\n\n\n\t\t\t\tInvalid Option";
}
else
if(op==1){

system("cls");
float
no1,no2;

cout<<"\n\n\t\t\t============= Addition
=============";

cout<<"\n\n\n\t\t\t Enter the Value of No1 = ";


cin>>no1;

cout<<"\n\t\t\t Enter the Value of No2 = ";


cin>>no2;

system("cls");

cout<<"\n\n\t\t\t============= Addition
=============";

cout<<"\n\n\n\t\t\t\t -----------------------";

cout<<"\n\t\t\t\t Result of "<<no1<<"+"<<no2<<" =


"<<sum(no1,no2);

cout<<"\n\t\t\t\t -----------------------";

}
else
if(op==2){

cout<<"\n\n\t\t\t============= Subtraction
=============";

system("cls");
float
no1,no2;

cout<<"\n\n\t\t\t Enter the Value of No1 = ";


cin>>no1;

cout<<"\n\t\t\t Enter the Value of No2 = ";


cin>>no2;

system("cls");

cout<<"\n\n\t\t\t============= Subtraction
=============";

cout<<"\n\n\n\t\t\t\t -----------------------";

cout<<"\n\t\t\t\t Result of "<<no1<<"-"<<no2<<" =


"<<sub(no1,no2);

cout<<"\n\t\t\t\t -----------------------";
}
else
if(op==3){
system("cls");
float
no1,no2;

cout<<"\n\n\t\t\t============= Multiplication
=============";

cout<<"\n\n\t\t\t Enter the Value of No1 = ";


cin>>no1;

cout<<"\n\t\t\t Enter the Value of No2 = ";


cin>>no2;

system("cls");

cout<<"\n\n\t\t\t============= Multiplication
=============";

cout<<"\n\n\n\t\t\t\t -----------------------";

cout<<"\n\t\t\t\t Result of "<<no1<<"*"<<no2<<" =


"<<mul(no1,no2);

cout<<"\n\t\t\t\t -----------------------";
}
else
if(op==4){

system("cls");
float
no1,no2;

cout<<"\n\n\t\t\t============= Division
=============";

cout<<"\n\n\t\t\t Enter the Value of No1 = ";


cin>>no1;

cout<<"\n\t\t\t Enter the Value of No2 = ";


cin>>no2;
if(no2!=0){

system("cls");

cout<<"\n\n\t\t\t============= Division
=============";
cout<<"\n\n\n\t\t\t\t -----------------------";

cout<<"\n\t\t\t\t Result of "<<no1<<"/"<<no2<<" =


"<<div(no1,no2);

cout<<"\n\t\t\t\t -----------------------";
}
else

if(no2==0){

system("cls");

cout<<"\n\n\t\t\t============= Division
=============";

cout<<"\n\n\n\t\t\t\t -----------------------";

cout<<"\n\t\t\t\t\tUndefined";

cout<<"\n\t\t\t\t -----------------------";
}
}
else
if(op==5){

system("cls");
int no1,no2;

cout<<"\n\n\t\t\t============= Remainder
=============";

cout<<"\n\n\t\t\t Enter the Value of No1 = ";


cin>>no1;

cout<<"\n\t\t\t Enter the Value of No2 = ";


cin>>no2;

system("cls");

cout<<"\n\n\t\t\t============= Remainder
=============";

cout<<"\n\n\n\t\t\t\t -----------------------";

cout<<"\n\t\t\t\t Result of "<<no1<<"%"<<no2<<" =


"<<rem(no1,no2);
cout<<"\n\t\t\t\t -----------------------";
}
else
if(op==6)
break;
cout.flush();
getch();
system("cls");
}while(op!=6); // -----
Nested Loop SimCal -----
}

/* =====================
Scientific Calculator ===================== */
else
if(ch==2){

system("cls");
int op;

do{
cout<<"\n\t\t
============= Scientific Calculator =============";

cout<<"\n\n\n\n\t\t\t\t [1]- Sin";

cout<<"\n\n\t\t\t\t [2]- Cos";

cout<<"\n\n\t\t\t\t [3]- Tangent";

cout<<"\n\n\t\t\t\t [4]- Secant";

cout<<"\n\n\t\t\t\t [5]- Cosecant";

cout<<"\n\n\t\t\t\t [6]- Cotangent";

cout<<"\n\n\t\t\t\t [7]- Up";

cout<<"\n\n\t\t\t\t Enter yr Choice ";


cin>>op;

if(op!=1 && op!


=2 && op!=3 && op!=4 && op!=5 && op!=6 && op!=7){

system("cls");

cout<<"\n\n\n\n\n\n\n\n\n\t\t\t\tInvalid Option";
}
else
if(op==1){
double
angle;

system("cls");

cout<<"\n\n\t\t\t============= Sin =============";

cout<<"\n\n\t\t\tEnter the Angle ";

cin>>angle;

system("cls");

cout<<"\n\n\t\t\t============= Sin =============";

cout<<"\n\n\n\t\t\t -----------------------------";

cout<<"\n\t\t\t Result of Angle "<<angle<<" = "<<getSin(angle);

cout<<"\n\t\t\t -----------------------------";

}
else
if(op==2){
double
angle;

system("cls");

cout<<"\n\n\t\t\t============= Cos =============";

cout<<"\n\n\t\t\tEnter the Angle ";

cin>>angle;

system("cls");

cout<<"\n\n\t\t\t============= Cos =============";

cout<<"\n\n\n\t\t\t -----------------------------";

cout<<"\n\t\t\t Result of Angle "<<angle<<" = "<<getCos(angle);

cout<<"\n\t\t\t -----------------------------";
}
else
if(op==3){

double
angle;

system("cls");

cout<<"\n\n\t\t\t============= Tangent
=============";

cout<<"\n\n\t\t\tEnter the Angle ";

cin>>angle;

system("cls");

cout<<"\n\n\t\t\t============= Tangent
=============";

cout<<"\n\n\n\t\t\t -----------------------------";

cout<<"\n\t\t\t Result of Angle "<<angle<<" = "<<getTan(angle);

cout<<"\n\t\t\t -----------------------------";

}
else
if(op==4){

double
angle;

system("cls");

cout<<"\n\n\t\t\t============= Secant =============";

cout<<"\n\n\t\t\tEnter the Angle ";

cin>>angle;

system("cls");

cout<<"\n\n\t\t\t============= Secant =============";

cout<<"\n\n\n\t\t\t -----------------------------";
cout<<"\n\t\t\t Result of Angle "<<angle<<" = "<<getSec(angle);

cout<<"\n\t\t\t -----------------------------";

}
else
if(op==5){

double
angle;

system("cls");

cout<<"\n\n\t\t\t============= Cosecant
=============";

cout<<"\n\n\t\t\tEnter the Angle ";

cin>>angle;

system("cls");

cout<<"\n\n\t\t\t============= Cosecant
=============";

cout<<"\n\n\n\t\t\t -----------------------------";

cout<<"\n\t\t\t Result of Angle "<<angle<<" =


"<<getCosec(angle);

cout<<"\n\t\t\t -----------------------------";

}
else
if(op==6){

double
angle;

system("cls");

cout<<"\n\n\t\t\t============= Cotangent
=============";

cout<<"\n\n\t\t\tEnter the Angle ";

cin>>angle;
system("cls");

cout<<"\n\n\t\t\t============= Cotangent
=============";

cout<<"\n\n\n\t\t\t -----------------------------";

cout<<"\n\t\t\t Result of Angle "<<angle<<" =


"<<getCotan(angle);

cout<<"\n\t\t\t -----------------------------";

}
else if(op==7){
break;
}
cout.flush();
getch();
system("cls");
}while(ch!=7); // -----
Nested Loop ScCal -----
}
else
if(ch==3)
break;
cout.flush();
getch();
system("cls");
}while(ch!=3);// -----
Nested Loop_1 -----
}
else
cout<<"\n\t\t\t Inavlid
Password!";
}
else
if(op==2){
cout.flush();
system("cls");

cout<<"\n\n\n\n\n\n\n\n\n--------------------------- Muhammad
Farhan Saleem ----------------------------";
cout<<"\n--------------\t\t
farhan.saleem@hotmail.com \t\t---------------";

cout<<"\n--------------------------- 03008855006
----------------------------\n\n\n\n\n\n\n";
exit(0);
}
cout.flush();
getch();
system("cls");
}while(op!=2);// ----- End of Outer
While Loop -----
} // ---- End of Menue ----

/* ===================== Main =====================


*/

void main()
{
menue();
}

Click the link below to see more examples

URL: http://ravianeducation.blogspot.com
E-Mail: mail2ravian@gmail.com

Farhan: 03008855006
farhan.saleem@hotmail.com
farhan.saleem26@yahoo.com

S-ar putea să vă placă și