Scientific Calculator Run this code at Microsoft Visual C++ Note: Password is “farhan” if prompt. /* ============= Header Files =============*/ #include #include #include #include #include
<math.h>
<stdlib.h> <string.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{ Calculator"; Calculator";
cout<<"\n\n\n\n\t\t\t\t[1]- Simple cout<<"\n\n\t\t\t\t[2]- Scientific 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"; [2]- Subtration"; [3]- Multiplication"; [4]- Division"; [5]- Remainder"; [6]- Up"; Your Choice.... ";
cout<<"\n\n\t\t\t\t cout<<"\n\n\t\t\t\t cout<<"\n\n\t\t\t\t cout<<"\n\n\t\t\t\t cout<<"\n\n\t\t\t\t cout<<"\n\n\t\t\t\t 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"); no1,no2; cout<<"\n\n\t\t\t============= Addition ============="; cout<<"\n\n\n\t\t\t Enter the Value of No1 = ";
float
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"); no1,no2;
float
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<<" = "<
} 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<<" = "<
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;
=2 && op!=3 && op!=4 && op!=5 && op!=6 && op!=7){
if(op!=1 && op!
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 "<
if(op==2){ double
system("cls"); cout<<"\n\n\t\t\t============= Cos ============="; cout<<"\n\n\t\t\tEnter the Angle "; cin rel="nofollow">>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 "<
else
} if(op==3){ double
angle; system("cls"); cout<<"\n\n\t\t\t============= Tangent ============="; cout<<"\n\n\t\t\tEnter the Angle "; cin rel="nofollow">>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 "<
else
} if(op==4){
angle;
double
system("cls"); cout<<"\n\n\t\t\t============= Secant ============="; cout<<"\n\n\t\t\tEnter the Angle "; cin rel="nofollow">>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 "<
if(op==5){ double
angle; system("cls"); cout<<"\n\n\t\t\t============= Cosecant ============="; cout<<"\n\n\t\t\tEnter the Angle "; cin rel="nofollow">>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 "<
if(op==6){ double
angle; system("cls"); cout<<"\n\n\t\t\t============= Cotangent ============="; cout<<"\n\n\t\t\tEnter the Angle "; cin rel="nofollow">>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 "<
Nested Loop ScCal ----} else
if(ch==3) break; cout.flush(); getch(); system("cls"); }while(ch!=3);// ----Nested Loop_1 -----
Password!";
} else } else
cout<<"\n\t\t\t
Inavlid
if(op==2){ cout.flush(); system("cls");
cout<<"\n\n\n\n\n\n\n\n\n--------------------------- Muhammad Farhan Saleem ----------------------------"; cout<<"\n--------------\t\t [email protected] \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: [email protected] Farhan: 03008855006 [email protected] [email protected]