Lab 6
Lab 6
LAB REPORT # 6
SUBMITTED BY : IRTAZA ALI NASIR
SUBMITTED TO : SIR ASAD
Task 1:
Write a C++ program that displays a menu to the user to choose
among four arithmetic operations, gets the operands from the user and
finally call the relevant functions to perform that particular operation. After
the display of the results, it must ask the user to perform another calculating
call by value.
ASSINGED PROGRAM
#include <iostream>
using namespace std;
void add(int x, int y)
{
cout << "Adittion of two numbers: " << x + y;
}
void sub(int x, int y)
{
cout << "subtraction of two numbers: " << x - y;
}
void div(float x, float y)
{
cout << "division of two numbers: " << x / y;
}
void mul(int x, int y)
{
cout << "multiplication of two numbers: " << x * y;
}
int main()
{
ali:
int a = 0, b = 0, c;
char sign;
if (sign == '+')
{
add(a, b);
cout << endl;
cout << endl;
}
else if (sign == '-')
{
sub(a, b);
cout << endl;
cout << endl;
}
else if (sign == '/')
{
div(a, b);
cout << endl;
cout << endl;
}
else if (sign == '*')
{
mul(a, b);
cout << endl;
cout << endl;
}
else
{
cout << "NO RECORD FOUND" << endl;
}
cout << " IF YOU WANT ANYOTHER OPREATION WANT TO DO THEN ENTER
OPREATION ELSE PRESS ANY KEY TO STOP" << endl << endl;
cin >> sign;
if (sign == '+' || sign == '-' || sign == '*' || sign == '/')
{
goto ali;
}
else
{
cout << "THANK YOU" << endl;
}
}
RESULT S ON SECREEN:
Task 2
:Write a C++ program that displays a menu
to the user to choose among four arithmetic
operations, gets the operands from the user and
finally call the relevant functions to perform that
particular operation. After the display of the
results, it must ask the user to perform another
calculationusing function call by reference.
ASSINGED PROGRAM
#include <iostream>
using namespace std;
void add(float& x, float& y)
{
cout << "Adittion of two numbers: " << x + y << endl;
}
void sub(float& x, float& y)
{
cout << "Subtraction of two numbers: " << x - y << endl;
}
void divide(float& x, float& y)
{
cout << "Division of two numbers: " << x / y << endl;
}
void multi(float& x, float& y)
{
cout << "Multiplication of two numbers: " << x * y << endl;
}
int main()
{
ali:
float a = 0, b = 0;
char sign;
cout << "ENTER ONE OF FOLLOWING OPREATION ('+' '-' '*'and '/' ):
"<<endl;;
cin >> sign;
cout << "ENTER VALUE OF a: "<< endl;
cin >> a;
cout << "ENTER VALUE OF b: " << endl;
cin >> b;
if (sign == '+')
{
add(a, b);
cout << endl;
}
else if (sign == '-')
{
sub(a, b);
cout << endl;
}
else if (sign == '/')
{
divide(a, b);
cout << endl;
}
else if (sign == '*')
{
multi(a, b);
cout << endl;
}
else
{
cout << "NO RECORD FOUND" << endl;
}
cout << " IF YOU WANT ANYOTHER OPREATION WANT TO DO THEN ENTER
OPREATION ELSE PRESS ANY KEY TO STOP" << endl << endl;
cin >> sign;
if (sign == '+' || sign == '-' || sign == '*' || sign == '/')
{
goto ali;
}
else
{
cout << "THANK YOU" << endl;
}
}
RESULT ON SECREEN
TASK NO 3 :
Write a C++ Program that gets a range of number from the user
and finds out the prime numbers in that range using function. (The
numbers that defines the range are excluded from the list of prime
numbers).Task
#include <iostream>
using namespace std;
void Prime(int num1, int num2) // user-defined function to check prime number
{
int i = ++num1;
while (i < num2)
{
bool prime = true;
if (i > 1)
{
int j = 2;
while (j <= i / 2)
{
if (i % j == 0)
{
prime = false;
break;
}
j++;
}
}
if (prime)
{
cout << i << "\t";
}
i++;
}
}
int main()
{
int from, to;
cout << "Enter Range: " << endl;
cout<<"Starting From: ";
cin >> from;
cout << "Ending on: ";
cin >> to;
Prime(from , to); // calling function
}
RESULT ON SECREEN