Muhammad Hamid OOP Lab Assignment2
Muhammad Hamid OOP Lab Assignment2
Q1: Find Maximum: Create a function that accepts three numbers and
returns the maximum of the three. Use a built in function max().
Solution:
#include<iostream>
return max(a, max(b, c)); // Using max() to find the maximum of three numbers
int main() {
cout << "The maximum of the three numbers is: " << maximum << endl;
return 0;
}
Q2: Even or Odd: Write a function that checks if a number is even or odd.
Solution:
#include<iostream>
if (num % 2 == 0)
cout << num << " is even." << endl; // If divisible by 2, it's even
else
cout << num << " is odd." << endl; // Otherwise, it's odd
int main() {
int number;
evenOdd(number);
return 0;
}
Q3: Fahrenheit to Celsius: Create a function to convert Fahrenheit to
Celsius. Formula:
Solution:
#include<iostream>
int main() {
float fahrenheit;
cout << fahrenheit << " Fahrenheit is equal to " << celsius << " Celsius." << endl;
return 0;
}
Q4: Area of Circle: Write a function that takes the radius as input and
returns the area of the circle.
Solution:
#include<iostream>
int main() {
float radius;
cout << "The area of the circle with radius " << radius << " is: " << area << endl;
return 0;
#include<iostream>
int main() {
cout << "The Simple Interest is: " << simpleInterest << endl;
return 0;
Q6: Check Prime: Write a function that checks if a given number is prime.
Solution:
#include<iostream>
if (num <= 1)
return false;
return false;
int main() {
int number;
if (isPrime(number))
else
cout << number << " is not a prime number." << endl;
return 0;
}
Q7: Factorial Calculation: Create a function that returns the factorial of a
given number.
Solution:
#include<iostream>
int result = 1;
int main() {
int number;
cout << "The factorial of " << number << " is: " << fact << endl;
return 0;
Q8: Find Smallest Element: Write a function to find the smallest number in
a list.
Solution:
#include<iostream>
int main() {
int size;
int arr[size];
cout << "Enter " << size << " elements: ";
cout << "The smallest element in the array is: " << smallest << endl;
return 0;
}
Q9: Reverse String: Write a function that reverses a character in string and
the reverse the character stored in array.
Solution:
#include<iostream>
#include<string>
int n = str.length();
int main() {
string inputString;
int size;
char arr[size];
cout << "Enter " << size << " characters: ";
reverseArray(arr, size);
return 0;
int main() {
int number;
multiplicationTable(number);
return 0;