Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

OBJECT ORIENTED PROGRAMMING LAB

OBJECT ORIENTED PROGRAMMING LAB

FUNCTIONS

DESIGNED BY ALI MUHAMMAD


Question:01
1- Write a function to convert temperature from Fahrenheit to Celsius. Ask the user
to enter temperature in degree Fahrenheit and then convert it to Celsius using a
function. Celsius=(F-32)*(5/9).
*Hint: 5/9 = 0.5555, if you want to use division operator, you may need to perform
typecasting into double

CODE:

#include<iostream>
#include<conio.h>
using namespace std;
double ToCelsius(double F){
double C;
C = (F - 32) * 5 / 9;
cout << "Temeperature in Celsius : " << C;
return C;
}
int main()
{
char choice;
do{
double Fahrenheit;
cout << "Enter the Temperature in Fahrenheit : ";
cin >> Fahrenheit;
cout << endl;
ToCelsius(Fahrenheit);
cout << endl << "Do you want to convert more(Y/N) : ";
cin >> choice;
} while (choice == 'y' || choice == 'Y');
_getch();
return 0;
}

OUTPUT:

1|Page
Question:02
1- Write a C++ function to swap (interchange) two numbers. Write a function which
takes two variable values and then swaps them. Program sequence: Enter the
value of variable a:5 Enter the value of variable b:10 ///After swapping the output
would be The value of variable a is=10 The value of variable b is=5

CODE:
#include<iostream>
#include<conio.h>
using namespace std;
void Swap(int *a,int *b){
int temp;
temp = *a;
*a = *b;
*b = temp;
}
int main()
{
int x, y;
cout << "Enter the value of x : ";
cin >> x;
cout << "Enter the value of y : ";

2|Page
cin >> y;
cout << endl << "The value of x=" << x << " and y=" << y;
Swap(&x, &y);
cout << endl << "After swap value of x=" << x << "and y=" << y;
_getch();
return 0;
}

OUTPUT:

+++++++THE END+++++++++

3|Page

You might also like