Rahmacplab 08

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

RAHMA ZAMIR BSCS 1-A 02-134222-096

Computer Programming Lab Assignment 08

Task 01
#include<iostream>
#include<math.h>
using namespace std;
int MY_POWER(int b, int p)
{
int w = pow(b, p);
return w;
}
void main()
{
int b, p;
cout << "Enter base : ";
cin >> b;
cout<< "Enter power : ";
cin>> p;
int w = MY_POWER(b, p);
cout << b << "^" << p << " = " << w << endl;
system("pause");
}

Task 02
RAHMA ZAMIR BSCS 1-A 02-134222-096
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
using namespace std;
#include <ctime>
#include <stdlib.h>
int average(int a, int b, int c, int& avg)
{
avg = (a + b + c) / 3;
return(avg);
}
int Sd(int x, int y, int z, int& sd)
{
int mean = (x + y + z) / 3;

int v = (pow(x - mean, 2)) + (pow(y - mean, 2)) + (pow(z - mean, 2));
sd = sqrt(v / 3);
return(sd);
}
int Var(int x, int y, int z, int& V)
{
int mean = (x + y + z) / 3;
V = (pow(x - mean, 2)) + (pow(y - mean, 2)) + (pow(z - mean, 2));
return(V);
}
int main()
{
int i{}, j{}, k{}, x, y, z, A, SD, f{}, g{}, h;
int n[3] = { i,j,k };
srand(time(NULL));
i = (rand() % 100) + 1;
j = (rand() % 100) + 1;
k = (rand() % 100) + 1;
cout << "Three Random Numbers Are: " << i << " " << j << " " << k << endl;

average(i, j, k, A);
cout << "Average of the Three Random Numbers: " << A << endl;
Var(i, j, k, h);
cout << "Variance " << h << endl;

Sd(f, g, h, SD);
cout << "Standard Deviation: " << SD;
}
RAHMA ZAMIR BSCS 1-A 02-134222-096
Task 03
#include<iostream>
using namespace std;
int add(int& a, int& b)
{
return(a + b);
}
int sub(int& a, int& b)
{
return(a - b);
}
int mult(int& a, int& b)
{
return(a * b);
}
float divide(int& a, int& b)
{
return(a / b);
}
void main()
{
int a, b;
cout << " Enter your first number: ";
cin >> a;
cout << " Enter your second number: ";
cin >> b;
cout << "\n\ Sum" << "= " << add(a, b);
cout << "\n Difference" << "= " << sub(a,b);
cout << "\n Product" << "= " << mult(a, b);
cout << "\n Quotient" << " : " << divide(a,b) << endl<<endl;
system(" pause");
}
RAHMA ZAMIR BSCS 1-A 02-134222-096
Task 04
#include<iostream>
using namespace std;
int value;
void Cal_pric(int a, int b, int c, int d, int e)
{
cout << " Price for Apples: " << a * 160;
cout << "\n Price for Bananas: " << b * 120;
cout << "\n Price for Mangos: " << c * 110;
cout << "\n Price for Peaches: " << d * 160;
cout << "\n Price for Grapes: " << e * 160;
cout << "\n\n";
}
void main()
{
int a, b, c, d, e;
cout << " How many kgs of apples did you purchase: ";
cin >> a;
cout << " How many kgs of bannana did you purchase: ";
cin >> b;
cout << " How many kgs of mango did you purchase: ";
cin >> c;
cout << " How many kgs of peach did you purchase: ";
cin >> d;
cout << " How many kgs of grapes did you purchase: ";
cin >> e;
Cal_pric(a, b, c, d, e);
system("pause");
}

You might also like