Anda di halaman 1dari 7

PROGRAM FOR CALCULATOR

AND LINEAR INTERPOLATION

NAME: MUHAMMAD HAMZA


ID: 242906
CLASS: ME 10 B
SUBMITTED TO : SIR AHMAD SUBHANI
TITLE : PROGRAM TO CREATE A CALULATOR USING A CH
COMMAND IN C++

ABSTRACT:
Instead of nested loop we have used the switch command to guide the user about
the calculator and at the same time we have used the switch command in the
char data type so that it can take the sign of the operators from the user and can
perform the calculation

EXPLANATION:
In this program we have to do simple arithematic operations so we do not need
the cmath library to be included in it and at the same time we have declared two
numbers that should be given by the user in the float or double data type to avoid
any loss of the data

After that we have done all of our operations in the cases that are written after
that and to specify which operation is going to be performed we have used
character data type instead of numbers to guide the user

Break command is also used to separate these operations from each other and
we have set an error message if the user want to perform operation other than
the four specified cases

CODING:
# include <iostream>
using namespace std;

int main()
{
char sys ;
float x1, x2;

cout << "Enter + ,- , * or / "<<endl;


cin >> sys;

cout << "Enter two operands: ";


cin >> x1 >> x2;

switch(sys)
{
case '+'://just an alphabets and no use and guide user to perform the
required operation
cout << x1+x2;
break;

case '-':
cout << x1-x2;
break;

case '*':
cout << x1*x2;
break;

case '/':
cout << x1/x2;
break;

default:
cout << "Error! Not correct";
break;
}

return 0;
}

OUTPUT:
CONCLUSION:
The program is the very basic interpolation of creating a calculator which leads in
performing a high level programming

TASK 2:
PROGRAM FOR THE LINEAR INTERPOLATION OF THE GRAPH

ABSTRACT:
The Program works just like the slope formula where we have to specify two
points and the x coordinate of the third lying somewhere between them and then
we have to find the freezing temperature at that point

EXPLANATION:
In this program we first have mentioned the required set of things in which the
values of salinity are initially given and after that we have to take the values of the
freezing temperature from the user
Then we use the condition of IF and ELSE so that we want to print the freezing
temperature at only the specified values and except that it will go to the else
statement and give the error message

CODING:
#include <iostream>
using namespace std ;
int main()
{
double a(1) , f_a , b(40) , f_b ,c ,f_c , f_d ;
cout<<"enter the values of salinity as x coordinate \n";
cout<<"enter the values oof freezing temperature as y coordinate \n" ;

cout<<"enter for first point";


cin>>f_a;

cout<<"enter for second point";


cin>>f_b;

cout<<"enter for third point";


cin >> c ;

if (c==3 || c==8.5 || c==19 || c==23.5 || c==26.8 || c==30.5)


{
f_c = f_a + (((f_b - f_a)/(b-a)) * (c-a));
f_d = (f_c - 32)*0.56;

cout<<"interpolated value of salinity is = "<<f_c << endl;


cout<<"freezing temperature in centigrade =" <<f_d<<" C";
}
else
cout<<"error value not found";
return 0;

}
OUTPUT:
CONCLUSION:
It shows that how we can use simple IF and ELSE statement to measure the
temperature at the specified salinities

TASK 3:
VALUES ARE GIVEN IN CENTIGRADE

EXPLANATION:
It will do the calculation in centigrade as it is the slope and if we want to convert
our answer in the Fahrenheit than use the formula (9/5*C )+32

TASK 4:
To find salinity when the freezing temperatures are given
ABSTRACT:
It is the simple program in which we just now have to make the x coordinate as a
subject and the temperature goes on the right side of the equation

EXPLANATION:
The program explains the inverse process of what we have done in the task 2 and
with the same explanation as given above now we have to cout the value of “c” in
our output as :

CODING AND OUTPUT:

CONCLUSION:
The program give the output in the opposite manner of the salinity.

Anda mungkin juga menyukai