COMP 218: Lab Work No. 2
COMP 218: Lab Work No. 2
Faculty of Engineering
Department of Software Engineering
COMP 218
OBJECT-ORIENTED PROGRAMMING
int main() {
cout << "Task-1a: Enter five floating-point values:" << endl;
double sum = 0;
for (int i = 0; i < 5; ++i) {
double value;
cout << "Enter value " << (i + 1) << ": ";
cin >> value;
sum += value;
}
cout << "Sum of the values is: " << sum << endl;
return 0;
}
// TASK1
// b
#include <iostream>
#include <climits>
using namespace std;
int main() {
cout << "Task-1b: Enter five integers:" << endl;
int minInt = INT_MAX;
for (int i = 0; i < 5; ++i) {
int intValue;
cout << "Enter integer " << (i + 1) << ": ";
cin >> intValue;
if (intValue < minInt) {
minInt = intValue;
}
}
cout << "The smallest integer is: " << minInt << endl;
return 0;
}
// TASK1
// c
#include <iostream>
#include <cmath>
using namespace std;
int main() {
cout << "Task-1c: Enter values for n and m to calculate n^m:" << endl;
double n, result;
int m;
cout << "Enter value for n: ";
cin >> n;
cout << "Enter value for m: ";
cin >> m;
result = calculatePower(n, m);
cout << n << " raised to the power of " << m << " is: " << result << endl;
return 0;
}
// TASK2
#include <iostream>
using namespace std;
int main() {
int choice;
double num1, num2, result;
case 2:
cout << "Enter two numbers to subtract:" << endl;
cin >> num1 >> num2;
result = num1 - num2;
cout << "Difference: " << result << endl;
break;
case 3:
cout << "Enter two numbers to multiply:" << endl;
cin >> num1 >> num2;
result = num1 * num2;
cout << "Product: " << result << endl;
break;
case 4:
cout << "Quitting the program." << endl;
break;
default:
cout << "Invalid choice. Please enter a number between 1 and 4." << endl;
}
return 0;
}
// TASK3
#include <iostream>
using namespace std;
int main() {
char symbol;
double num1, num2, result;
switch (symbol) {
case '+':
cout << "Enter two numbers to add:" << endl;
cin >> num1 >> num2;
result = num1 + num2;
cout << "Sum: " << result << endl;
break;
case '-':
cout << "Enter two numbers to subtract:" << endl;
cin >> num1 >> num2;
result = num1 - num2;
cout << "Difference: " << result << endl;
break;
case '*':
cout << "Enter two numbers to multiply:" << endl;
cin >> num1 >> num2;
result = num1 * num2;
cout << "Product: " << result << endl;
break;
case '.':
cout << "Quitting the program." << endl;
break;
default:
cout << "Invalid choice. Please enter one of the specified symbols." << endl;
}
return 0;
}