You are on page 1of 7

EUROPEAN UNIVERSITY OF LEFKE

Faculty of Engineering
Department of Computer Engineering

COMP 218
OBJECT-ORIENTED
PROGRAMMING

Lab Work No. 2


Prepared by Aqil Ahmad Burki (194525)

Submitted to Mr. Salman Khan


Task 1:
Code:
#include<iostream>
using namespace
std; int main()
{
float Values[5],Sum=0.0;
cout<<"\nEnter 5 Float Values: \n";
for(int i=0;i<5;i++)
{
cin>>Values[i];
Sum+=Values[i];
}
cout<<"\nSum = "<<Sum;
int intValues[5],smallest;
cout<<"\nEnter 5 Integer Values: \n";
for(int i=0;i<5;i++)

{
cin>>intValues[i];
}
smallest=intValues[0];
for(int i=1;i<5;i++)
if(intValues[i]<smallest)
smallest=intValues[i];
cout<<"\nSmallest= "<<smallest;
int numberN,powerM,result;
cout<<"\nEnter a number N: ";
cin>>numberN;
cout<<"\nEnter a power M: ";
cin>>powerM;
result=1;
for(int i=0;i<powerM;i++)
result*=numberN;
cout<<"\n"<<numberN<<" raised by "<<powerM<<" is: "<<result;
return 0;
}
Output:
Task 2:
Code:
#include<iostream>
using namespace std;
int main()
{
double num1,num2,result=0;
int option;
cout<<"\n1. Add"<<"\n2. Subtract"<<"\n3. Multiply"<<"\n4. Quit";
cout<<"\nChoose an Option: ";
cin>>option;
if(option!=4)
{
cout<<"\nEnter number 1: ";
cin>>num1;
cout<<"\nEnter number 2: ";
cin>>num2;
}
switch(option)
{
case 1:
result=num1+num2;
break;
case 2:
result=num1-num2;
break;
case 3:
result=num1*num2;
break;
case 4:
exit(1);
default:
cout<<"\nEnter a valid choice!! ";
break;
}
cout<<"\nResult= "<<result;
return 0;
}
Output:
Task 3:
Code:
#include<iostream>
using namespace std;
int main()
{
double num1,num2,result=0;
char option;
cout<<"\n'+' Add"<<"\n'-' Subtract"<<"\n'*' Multiply"<<"\n'.' Quit";
cout<<"\nChoose an Option: ";
cin>>option;
if(option!='.')
{
cout<<"\nEnter number 1: ";
cin>>num1;
cout<<"\nEnter number 2: ";
cin>>num2;
}
switch(option)
{
case '+':
result=num1+num2;
break;
case '-':
result=num1-num2;
break;
case '*':
result=num1*num2;
break;
case '.':
exit(1);
break;
default:
cout<<"\nEnter a valid choice!! ";
}
cout<<"\nResult= "<<result;
return 0;
}
Output:

You might also like