0% found this document useful (0 votes)
20 views10 pages

Lab 6

The document contains 3 lab reports submitted by Irtaza Ali Nasir. The first report details a C++ program that displays an arithmetic operator menu, takes operands from the user, and calls functions to perform the selected operation. The second report details a similar program that performs calculations by passing operands by reference to functions. The third report details a program that takes a numeric range from the user and calls a function to find and display the prime numbers within that range.

Uploaded by

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

Lab 6

The document contains 3 lab reports submitted by Irtaza Ali Nasir. The first report details a C++ program that displays an arithmetic operator menu, takes operands from the user, and calls functions to perform the selected operation. The second report details a similar program that performs calculations by passing operands by reference to functions. The third report details a program that takes a numeric range from the user and calls a function to find and display the prime numbers within that range.

Uploaded by

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

2020

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;

cout << "ENTER ANY OPREATION FROM THE GIVEN MENU : ( + , - ,


* , / )" << endl;
cin >> sign;
cout << "ENTER VALUE OF a" << endl;
cin >> a;
cout << "ENTER VALUE OFb" << endl;
cin >> b;

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

You might also like