0% found this document useful (0 votes)
93 views7 pages

OOP Assignment

Write a program that asks the user to input marks of five courses and then computes the average, variance and standard deviation of them. The formula for variance is; S 2 = [∑ (xi - a)2 ]/n Where S2 is the variance and a is the average of the five scores x1, x2, x3, x4 and x5. The standard deviation is the square root of variance. The program must have at least 3 functions to compute average, variance and a display function that displays these values. Your program should ask the user to exit

Uploaded by

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

OOP Assignment

Write a program that asks the user to input marks of five courses and then computes the average, variance and standard deviation of them. The formula for variance is; S 2 = [∑ (xi - a)2 ]/n Where S2 is the variance and a is the average of the five scores x1, x2, x3, x4 and x5. The standard deviation is the square root of variance. The program must have at least 3 functions to compute average, variance and a display function that displays these values. Your program should ask the user to exit

Uploaded by

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

Hamdard University,

Islamabad
(HIET)
Task: Assignment “01”
Subject: OOP LAB
Class: “BCS”
Semester: 3rd/ Fall 2021
Submission to: Ma’am Nafeesa
Submission by: Ali sher
CMS ID: 2055-2020
Date: 08 Nov, 2021

Object Oriented Programming Page 1


Lab Tasks
Task # 1

Write a program that asks the user to input marks of five courses and then computes the average,
variance and standard deviation of them. The formula for variance is; S2 = [∑ (xi - a)2]/n

Where S2 is the variance and a is the average of the five scores x1, x2, x3, x4 and x5. The standard
deviation is the square root of variance.

The program must have at least 3 functions to compute average, variance and a display function
that displays these values. Your program should ask the user to exit or input the scores again.

Task.1: Program;

//Student: Ali sher 2055-2020

//Task: OOP Lab No.1

#include <iostream>

Using namespace std;

Int main()

Float Phy, Chem, Bio, Eng, Math, total, average, percent;

// Phy, Chem, Bio, Eng, and Math are the five subjects

// Phy = Physics

// Chem = Chemistry

// Bio = Biology

// Eng = English

// Math = Mathematics

Cout<< “Enter Physics Marks: “;

Cin>>Phy;

Object Oriented Programming Page 2


Cout<< “Enter Chemistry Marks: “;

Cin>>Chem;

Cout<< “Enter Biology Marks: “;

Cin>>Bio;

Cout<<” Enter English Marks: “;

Cin>>Eng;

Cout<< “Enter Maths Marks: “;

Cin>>Math;

// Calculate total, average and percentage

Total = Phy + Chem + Bio + Eng + Math;

Average = total / 5.0;

Percent = (total / 500.0) * 100;

// Output

Cout << “The Total marks = “ << total << “/500\n”;

Cout << “The Average marks = “ << average << “\n”;

Cout<< “Your Percentage is: “ << percent<< “%”<< endl;

Return 0;

Object Oriented Programming Page 3


Task # 2

1. void populate_array(int *array, int N);


// this initializes an array of size N with random values.
2. void print_array(int *array, int N);
// this function prints the entire array.
3. void sort (int *array, int N)
//sort the elements of array

4. bool find (int *array, int x);


//find the element in the array:

Task.2: Program;
//Student: Ali sher 2055-2020
//Task: OOP Lab Assignment 01

#include <iostream>
Using namespace std;

Void populate_array(int* arr, int n);


Void print_array(int* arr, int N);
Void sort(int* arr, int n);
Bool find(int* array, int x);

Int main()

{
Int* arr = nullptr;
Populate_array(arr, 8);
Return 0;
}

Void populate_array(int* arr, int N)


{
Arr = new int[N];
For (int I = 0; I < N; i++)
{
Int num = rand() % N + 1;
Arr[i] = num;
}

Print_array(arr, N);
Cout << endl;
Sort(arr, N);

Object Oriented Programming Page 4


Cout << endl;
Int x;

Cout << “Please Enter a Number and Let’s See If It Exists or Not: “<<endl;
Cin >> x;
If (find(arr, x))
{
Cout << “Hey! Your Number Does Exists”;
}
Else
{
Cout << “Opps! Your Number does not exists Sorry”;
}
}

Void sort(int* arr, int N)


{
Int x, y, min, temp;
For (x = 0; x < N – 1; x++)
{
Min = x;
For (y = x + 1; y < N; y++)
{
{
If (arr[y] < arr[min])
Min = y;
}
}
Temp = arr[x];
Arr[x] = arr[min];
Arr[min] = temp;
}

Print_array(arr, N);
}
Void print_array(int* arr, int N)
{

For (int I = 0; I < N; i++)


{
Cout << arr[i] << endl;
}
}

Object Oriented Programming Page 5


Bool find(int* arr, int x)
{
Int size = sizeof(arr) / sizeof(arr[0]);
For (int I = 0; I < 6; i++)
{
If (arr[i] == x)
{
Return true;
}
}

return false;

Object Oriented Programming Page 6


Object Oriented Programming Page 7

You might also like