PERMUTATION PROGRAM
A permutation is one of the possible different arrangement or ordering a set of objects. The set of
number of permutations of n objects taken r at a time is defined by the formula n! /(n-r)!. Develop logic
and design a program that accepts values for n and r and computes the number of permutations
possible. Enter values for 7 and 5 to test your program. The answer should be 2520.
SOURCE CODE
/* This program cannot be access if the code is not correct. if the code is accepted the permutation
program will take place. The program will ask the user to input a value for n and r. if the inputted value
for n is greater than r, there will be a message regarding the error that occurred.*/
/* If the values are correct, the program will display the answer using the formula in getting the
permutation*/
/* The program has a function in computing the factorial needed in solving the permutation*/
#include <iostream>
#include <conio.h>
using namespace std;
long factorial (int);
int main()
{
int n,r,x;
long fact = 1;
string a;
cout<<" This part of the program is not allowed for your access. "<<endl;
cout<<" Enter the correct crack code to proceed. "<<endl<<endl;
cout<<" Enter the Crack Code :";
cin>>a;
if(a != "permutationcalculator")
{
do
{
cout<<" You are not listed for authorization access in this program"<<endl<<endl;
cout<<" Please be careful in typing the code, slight changes to the actual code will not
suffice."<<endl<<endl;
cout<<" Please try again."<<endl<<endl;
cout<<" Thank you for your understanding"<<endl<<endl;
cout<<" Enter the Crack Code :";
cin>>a;
cout<<endl;
}while (a !="permutationcalculator");
}
else
cout<<" Well done!!! You crack the code."<<endl;
cout<<" You may now continue using this program "<<endl<<endl;
cout << " Welcome to PERMUTATION CALCULATOR\n";
cout<<endl;
cout << " Enter the value of n: \n";
cin>>n;
cout << " Enter the value of r: \n";
cin>>r;
x=n-r;
while (x<0)
{
cout<<"\t MATH ERROR!!!!!!!";
cout<<endl;
cout << " Remember:The inputted number for n should always be greater than the value of r\n";
cout<<endl;
cout << "Enter the value of n: \n";
cin>>n;
cout << "Enter the value of r: \n";
cin>>r;
break;
}
cout<<endl;
cout << "The formula of Permutation is: \n" << "n!/(n-r)!\n";
cout<<endl;
cout << n<<"!="<<factorial(n)<<"\n"<< "("<<n<<"-"<<r<<")"<<"!="<<factorial(x)<<"\n";
cout<<endl;
cout << "The number of permutations of n = " << n <<" different things taken r = " << r <<" at a time
is " << endl<< (factorial(n))/(factorial(x)) << endl ;
cout<<endl;
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
for(c=1;c<=n;c++)
result=result*c;
return result;
}
SCIENTIFIC CALCULATOR PROGRAM
SOURCE CODE
/* This program is about a scientific calculator. it has functions that can be found in one.*/
/* The program let the user choose which operation or function he/she wants to perform.*/
/* After choosing, the user will enter the value he/she wants to solve.*/
/* The program displays the answers in decimal form and uses switch statement*/
#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;
int main ()
{
float a,b,PI;
int c;
string x;
cout<<" This part of the program is not allowed for your access. "<<endl;
cout<<" Enter the correct crack code to proceed. "<<endl<<endl;
cout<<" Enter the Crack Code :";
cin>>x;
if (x != "scientificcalculator")
{
do
{
cout<<" You are not listed for authorization access in this program"<<endl<<endl;
cout<<" Please be careful in typing the code, slight changes to the actual code will not
suffice."<<endl<<endl;
cout<<" Please try again."<<endl<<endl;
cout<<" Thank you for your understanding"<<endl<<endl;
cout<<" Enter the Crack Code :";
cin>>x;
cout<<endl;
} while (x !="scientificcalculator");
}
else
cout<<" Well done!!! You crack the code."<<endl;
cout<<" You may now continue using this program "<<endl<<endl;
cout<<"******************************* Calculator
*************************************\n";
cout<<"===============================================================================
=\n";
cout<<"Operations\t"<<"\tTrigonometric Functions"<<"\t\tLogarithmic Functions\n";
cout<<"===============================================================================
=\n";
cout<<"1: Division\t\t"<<"7: Sin\t\t"<<"\t\t13: Log"<<endl;
cout<<endl;
cout<<"2: Multiplication\t"<<"8: Cos\t\t"<<"\t\t14: Log with base 10"<<endl;
cout<<endl;
cout<<"3: Subtraction\t\t"<<"9: Tan\t\t"<<endl;
cout<<endl;
cout<<"4: Addition\t\t"<<"10: Inverse of Sin"<<endl;
cout<<endl;
cout<<"5: Exponent\t\t"<<"11: Inverse of Cos"<<endl;
cout<<endl;
cout<<"6: Square root\t\t"<<"12: Inverse of Tan"<<endl;
cout<<endl;
cout<<"Enter the function that you want to perform : ";
cin>>c;
cout<<endl;
PI=3.14159265;
switch(c)
{
case 1:
cout<<"Enter 1st number : ";
cin>>a;
cout<<endl;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<endl;
cout<<"Division = "<<a/b<<endl;
break;
case 2:
cout<<"Enter 1st number : ";
cin>>a;
cout<<endl;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<endl;
cout<<"Multiplication = "<<a*b<<endl;
break;
case 3:
cout<<"Enter 1st number : ";
cin>>a;
cout<<endl;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<endl;
cout<<"Subtraction = "<<a-b<<endl;
break;
case 4:
cout<<"Enter 1st number : ";
cin>>a;
cout<<endl;
cout<<"Enter 2nd number : ";
cin>>b;
cout<<endl;
cout<<"Addition = "<<a+b<<endl;
break;
case 5:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Enter the exponent : ";
cin>>b;
cout<<endl;
cout<<"Exponent = "<<pow(a,b)<<endl;
break;
case 6:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Square Root = "<<sqrt(a)<<endl;
break;
case 7:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Sin = "<<sin(a)<<endl;
break;
case 8:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Cos = "<<cos(a)<<endl;
break;
case 9:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Tan = "<<tan(a)<<endl;
break;
case 10:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Inverse of Sin = "<<a*sin(a)*180.0/PI<<endl;
break;
case 11:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Inverse of Cos = "<<a*cos(a)*180.0/PI<<endl;
break;
case 12:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Inverse of tan = "<<a*tan(a)*180.0/PI<<endl;
break;
case 13:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Log = "<<log(a)<<endl;
break;
case 14:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Log with base 10 = "<<log10(a)<<endl;
break;
default:
cout<<"Wrong Input"<<endl;
cout<<"Try again."<<endl;
}
getch();
return 0;
}
CONVERSION OF TEMPERATURE PROGRAM
SOURCE CODE
/* This program converts the temperature to other conversions using switch statement*/
/* This program is password protected using do while loop statement*/
/* This will display the temperature you want to convert or input and the converted temperature or
output*/
#include<iostream>
using namespace std;
int main()
{
char b;
float c;
float f;
float k;
string a;
cout<<" This part of the program is not allowed for your access. "<<endl;
cout<<" Enter the correct crack code to proceed. "<<endl<<endl;
cout<<" Enter the Crack Code :";
cin>>a;
if(a != "conversionoftemperature")
{
do
{
cout<<" You are not listed for authorization access in this program"<<endl<<endl;
cout<<" Please be careful in typing the code, slight changes to the actual code will not
suffice."<<endl<<endl;
cout<<" Please try again."<<endl<<endl;
cout<<" Thank you for your understanding"<<endl<<endl;
cout<<" Enter the Crack Code :";
cin>>a;
cout<<endl;
}while (a !="conversionoftemperature");
}
else
cout<<" Well done!!! You crack the code."<<endl;
cout<<" You may now continue using this program "<<endl<<endl;
cout<<" Conversion of Temperature\n";
cout<<"\tA. C-->F\n";
cout<<"\tB. F-->C\n";
cout<<"\tC. C-->K\n";
cout<<"\tD. K-->C\n";
cout<<"\tE. F-->K\n";
cout<<"\tF. K-->F\n";
cout<<"\tG. Exit\n";
cout<<"\t"<<endl;
cout<<"\tChoose an action: ";
cin>>b;
switch (b)
{
case 'a':
case 'A':
cout<<"\tEnter the Temperature: ";
cin>>c;
cout<<endl;
cout<<"\t"<<c<<"\tC = "<<((c*9/5)+32);
cout<<"\tF";
case 'b':
case 'B':
cout<<"\tEnter the Temperature: ";
cin>>f;
cout<<endl;
cout<<"\t"<<f<<"\tF = "<<((f-32)*5/9);
cout<<"\tC";
break;
case 'c':
case 'C':
cout<<"\tEnter the Temperature: ";
cin>>c;
cout<<endl;
cout<<"\t"<<c<<"\tC = "<<(c+273.15);
cout<<"\tK";
break;
case 'd':
case 'D':
cout<<"\tEnter the Temperature: ";
cin>>k;
cout<<endl;
cout<<"\t"<<k<<"\tK = "<<(k-273.15);
cout<<"\tC";
break;
case 'e':
case 'E':
cout<<"\tEnter the Temperature: ";
cin>>f;
cout<<endl;
cout<<"\t"<<f<<"\tF = "<<((f-32)*5/9)+273.15;
cout<<"\tK";
break;
case 'f':
case 'F':
cout<<"\tEnter the Temperature: ";
cin>>k;
cout<<endl;
cout<<"\t"<<k<<"\tK = "<<((k-273.15)*9/5)+32;
cout<<"\tF";
break;
case 'g':
case 'G':
return 0;
default:
cout<<"\tThis is not in the choices. Try again."<<endl;
return 0;