University of Maiduguri: Department of Computer Engineering

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

UNIVERSITY OF MAIDUGURI

FACULTY OF ENGINEERING

DEPARTMENT OF COMPUTER ENGINEERING

CPE 303:-
(Computer Programming Lab)

Mini project Topic


A Simple Scientific Calculator

ID NUMBERS;
07/05/04/004
07/05/04/009
07/05/04/010
07/05/04/025
08/05/04/062
/*This is a standard Calculator Which can perform
Addition, Subtraction, Multiplication, Division,
give out the percentage of a number in another, e.t.c*/
#include<iostream.h>
#include<math.h>
#include<process.h>
void main()
{
float num1,num2,res,p=3.142; //These are variables that can accept decimal points
char ch,choice,count;
count=0;
z:
cout<<"\t\t\t\tSELECT OPERATION\n"<<endl;

cout<<"*****************************************************************
**************"<<endl;
cout<<"Press * for multiplication, + for addition, - for subtraction, / for division"<<endl;
cout<<"\np for percentage, r for square root, i for inverse, q for square, P for
power"<<endl;
cout<<"\nT for tan, S for sin, C for cos, t for tan inverse, s for sine inverse, \n\nc for cos
inverse"<<endl;

cout<<"*****************************************************************
**************\n"<<endl;
cin>>ch;
count++;

//We have to use switch case in other to select our choice


switch(ch)
{
case '+': //This is case one, for addition
cout<<"\n/////////////////////////"<<endl;
cout<<"Enter two numbers"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1>>num2;
res=num1+num2;
cout<<"\n"<<num1<<" + "<<num2<<" = "<<res<<endl;
break;

case '-': //This is case two, for subtraction


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter two numbers"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1>>num2;
res=num1-num2;
cout<<"\n"<<num1<<" - "<<num2<<" = "<<res<<endl;
break;

case '*': //This is case three, for multiplication


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter two numbers"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1>>num2;
res=num1*num2;
cout<<"\n"<<num1<<" * "<<num2<<" = "<<res<<endl;
break;

case '/': //This is case four, for division


m:
cout<<"\n/////////////////////////"<<endl;
cout<<"Enter two numbers"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1>>num2;
if(num2==0)
{
cout<<"\nSorry, please enter a value which is not zero\n"<<endl;
goto m;
}
res=num1/num2;
cout<<"\n"<<num1<<" / "<<num2<<" = "<<res<<endl;
break;

case 'r': //This is case five, for square root


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter a number"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1;
res=sqrt(num1);
cout<<"\nSquare root of "<<num1<<" = "<<res<<endl;
break;

case 'p': //This is case six, for percentage


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter two numbers"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1>>num2;
res=(num1/num2)*100;
cout<<"\n"<<num1<<" percent of "<<num2<<" is "<<res<<endl;
break;

case 'i': //This is case seven, for inverse


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter a number"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1;
res=1/num1;
cout<<num1<<" inverse = "<<res<<endl;
break;
case 'q': //This is case eight, for square of a number
cout<<"\n/////////////////////////"<<endl;
cout<<"Enter a number"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1;
res=pow(num1,2);
cout<<num1<<" squared = "<<res<<endl;
break;

case 'T': //This is case nine, for tangent of a number


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter a number"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1;
res=tan(p*num1/180);
cout<<"\nTangent of "<<num1<<" = "<<res<<endl;
break;

case 'S': //This is case ten, for sine of a number


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter a number"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1;
res=sin(p*num1/180);
cout<<"\nSine of "<<num1<<" = "<<res<<endl;
break;

case 'C': //This is case eleven, for cosine of a number


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter a number"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1;
res=cos(p*num1/180);
cout<<"\nCosine of "<<num1<<" = "<<res<<endl;
break;

/*case 't': //This is case twelve, for tan inverse of a number


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter a number"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1;
res=tan(num1);
cout<<"\nTan inverse of "<<num1<<" = "<<res<<endl;
break;

case 's': //This is case thirteen, for sin inverse of a number


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter a number"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1;
res=asin(num1);
cout<<"\nsin inverse of "<<num1<<" = "<<res<<endl;
break;

case 'c': //This is case fourteen, for cos inverse of a number


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter a number"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1;
res=acos(num1);
cout<<"\nCos inverse of "<<num1<<" = "<<res<<endl;
break; */

case 'P': //This is case fifteen, for power of a number


cout<<"\n/////////////////////////"<<endl;
cout<<"Enter two numbers"<<endl;
cout<<"/////////////////////////\n"<<endl;
cin>>num1>>num2;
res=pow(num1,num2);
cout<<num1<<" to power of "<<num2<<" = "<<res<<endl;
break;

default:
cout<<"\nPlease select any of the above options\n"<<endl;
};

if(count==3)
{
cout<<"\nYou already used the program thrice...\n\nYou have to run the
program again...";
exit(0);
}
cout<<"\n::::::::::::::::::::::::::::::::::::::::"<<endl;
cout<<"Do you want perform another operation? (Press Y/N)"<<endl;
cout<<"::::::::::::::::::::::::::::::::::::::::\n"<<endl;
cin>>choice;
if((choice=='Y')||(choice=='y'))
{
goto z;
}
}
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
int d,N,n=1;
float a,nth_term,Sn;
cout<<"\n\nThis Program Evaluate Arthmetic Progression"<<endl;
cout<<"\n\nTo calculate Enter the following"<<endl;
cout<<"\n\nFirst term(a),common difference(d),the Number of Terms(n)"<<endl;
cin>>a>>d>>N;
cout<<"\n\nThe Arthmetic Progression Is"<<endl;
if(n<=N)
{
nth_term=a+(n-1)*d;
n++;
cout<<"\t"<<nth_term<<"\t"<<endl;
}
cout<<"\n"<<endl;
Sn=(N/2)*(2*a+((N-1)*d));
cout<<"\n"<<endl;
cout<<"\nThe Sum of the first"<<N<<""<<"term is"<<""<<Sn<<endl;
return 0;
}

You might also like