In: Computer Science
Inside “Lab1” folder, create a project named “Lab1Ex3”. Use this
project to develop a C++ program that performs the following:
Define a function called “Find_Min” that takes an array, and array
size and return the minimum value on the array. Define a function
called “Find_Max” that takes an array, and array size and return
the maximum value on the array. Define a function called
“Count_Mark” that takes an array, array size, and an integer value
(mark) and prints the number of marks that are greater than mark.
Call Find_Min and Find_Max functions. Call Count_Mark
function.
Here our task is to create a c++ program which have 3 functions to find maimum ,minimum and marks greater than given marks
Now let's see what are the the steps to follow,
CODE
(Please read all comments for the better understanding of the pogram)
OUTPUT
I am also attching the text version of the code in case you need to copy paste
#include <iostream>
using namespace std;
int Find_Max(int arr[],int length){ //defining Find_max
function
int max; // declaring a variable to store current maximum
value
max=arr[0]; //initializing max as the first element
for (int i = 0; i < length; ++i) { //loop that iterate through
each element in array
if (arr[i]>max){ //checking whether current element is greater
than current max or not
max= arr[i]; //if yes max variable is changed with value of current
element
}
}
return max; //returning the max
}
int Find_Min(int arr[],int length){ //defining Find_Min
function
int min; // declaring a variable to store current minimum
value
min=arr[0]; //initializing min as the first element
for (int i = 0; i < length; ++i) { //loop thta iterate through
each element in array
if (arr[i]<min){ //checking whether current element is less than
current min or not
min= arr[i]; //if yes min variable is changed with value of current
element
}
}
}
return min; //returning the min
}
int Count_Mark(int arr[],int length,int mark){ //defining
Find_Min function
cout<<"\nMarks greater than "<<mark<<" are";
//print statement
for (int i = 0; i < length; ++i) { //loop that iterate through
each element in array
if (arr[i]>mark){ //checking whether current element is greater
than mark or not
cout<<"\n"<<arr[i]; //if yes ,print current
element
}
}
}
int main() //main function starts here
{
int arr[10]={77,48,17,64,7,45,94,25,15,36}; //initializing array
with values
int max; //declaring min and max
int min;
min=Find_Min(arr,10); //calling Find_Min and store value to
min
max=Find_Max(arr,10); //calling Find_Max and store value to
max
cout<<"\n max = "<<max; //print statement
cout<<"\n min = "<<min;
Count_Mark(arr,10,35); //calling Count_Mark
return 0;
}