0% found this document useful (0 votes)
45 views6 pages

COMP 218: Lab Work No. 2

Uploaded by

Academic Hub
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views6 pages

COMP 218: Lab Work No. 2

Uploaded by

Academic Hub
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

EUROPEAN UNIVERSITY OF LEFKE

Faculty of Engineering Department of


Software Engineering

COMP 218
OBJECT-ORIENTED PROGRAMMING

Lab Work No. 2

Prepared by Celal Emir Türkmenoğlu(192560)

Submitted to Mr. Salman Khan


Task –1

#include <iostream>
#include <cmath>

int main() {
// Task (a): Sum of five floating-point values
double sum = 0.0;
for (int i = 0; i < 5; ++i) {
double value;
std::cout << "Enter a floating-point value: ";
std::cin >> value;
sum += value;
}
std::cout << "Sum of the values: " << sum << std::endl;

// Task (b): Find the smallest integer


int smallest = 0;
for (int i = 0; i < 5; ++i) {
int num;
std::cout << "Enter an integer: ";
std::cin >> num;
if (smallest == 0) {
smallest = num;
}
else if (num < smallest) {
smallest = num;
}
}
std::cout << "Smallest integer: " << smallest << std::endl;

// Task (c): Calculate n raised to the power of m


double n, m;
std::cout << "Enter a value for n: ";
std::cin >> n;
std::cout << "Enter a value for m: ";
std::cin >> m;
double result = std::pow(n, m);
std::cout << n << " raised to the power of " << m << " is: " << result << std::endl;
return 0;
}

Task –2

#include <iostream>
using namespace std;

int main() {
int x = 1;
int choice;
double num1, num2, result;
while (x == 1) {
cout << "\nMenu Options:" << endl;
cout << "1. Addition" << endl;
cout << "2. Subtraction" << endl;
cout << "3. Multiplication" << endl;
cout << "4. Quit" << endl;
cout << "Choose an option (1-4): ";
cin >> choice;

switch (choice) {
case 1:
cout << "Enter two numbers: ";
cin >> num1 >> num2;
result = num1 + num2;
cout << "Sum: " << result << endl;
break;
case 2:
cout << "Enter two numbers: ";
cin >> num1 >> num2;
result = num1 - num2;
cout << "Difference: " << result << endl;
break;
case 3:
cout << "Enter two numbers: ";
cin >> num1 >> num2;
result = num1 * num2;
cout << "Product: " << result << endl;
break;
case 4:
cout << "Exiting the program." << endl;
x = 0;
break;
default:
cout << "Invalid choice!" << endl;
}
}
return 0;
}

Task –3
#include <iostream>
using namespace std;

int main() {
double num1, num2, result;
char operation;

cout << "Enter an operation (+, -, *, or . to quit): ";


cin >> operation;

while (operation != '.') {


cout << "Enter two numbers: ";
cin >> num1 >> num2;

switch (operation) {
case '+':
result = num1 + num2;
cout << "Sum: " << result << endl;
break;
case '-':
result = num1 - num2;
cout << "Difference: " << result << endl;
break;
case '*':
result = num1 * num2;
cout << "Product: " << result << endl;
break;
default:
cout << "Invalid operation. Please use +, -, *, or . to quit." << endl;
}

cout << "Enter an operation (+, -, *, or . to quit): ";


cin >> operation;
}

cout << "Exiting the program." << endl;

return 0;
}

You might also like