Cp Lab 8 Function
Cp Lab 8 Function
Lab Journal: 8
Date: 10 - 13 - 2024
Documentation
Task Wise Marks Total
Task Marks Marks
No:
Assigned Obtained Assigned Obtained (20)
1 3
2 3
3 3 5
4 3
5 3
Comments:
Signature
Hayat Nabi Computer Programming Engr. M Amin Khan
09-131242-097 Lab # 08 Dept of SE, BUIC
double F , C , K;
2
Hayat Nabi Computer Programming Engr. M Amin Khan
09-131242-097 Lab # 08 Dept of SE, BUIC
Screenshot:
Task 2:
Implement two functions: one to find the maximum and another to find the minimum of three
user-input numbers. The program should call these functions and display the maximum and
minimum values.
Code:
#include<iostream>
using namespace std;
3
Hayat Nabi Computer Programming Engr. M Amin Khan
09-131242-097 Lab # 08 Dept of SE, BUIC
cin>>b;
cout<<"Enter Third Number (Non-Negative ) : ";
cin>>c;
Screenshot:
Task 3:
Create a function that takes an integer as input and returns true if it is a prime number and
false otherwise. Write a main program that allows the user to input a number and uses this
function to display whether the number is prime.
Code:
#include<iostream>
using namespace std;
int N ;
bool Check;
bool Prime_Check(int Number ){
Check = true;
for(int i=2;i<N ;i++){
if(N % i == 0 )
Check = false ;
}
return Check;
}
int main(){
cout<<"Enter Any Positive Number to Check Prime or Not : ";
cin>>N;
if(Prime_Check(N) == 1){
cout<<"Prime Number ";
4
Hayat Nabi Computer Programming Engr. M Amin Khan
09-131242-097 Lab # 08 Dept of SE, BUIC
}else{
cout<<"Non - Prime Number ";
}
}
Screenshot:
Task 4:
Create a program that calculates the monthly payroll for employees in a company. Using
Functions ……..
Code:
#include<iostream>
using namespace std;
string Name ;
int Worked_Hours;
double Hourly_Rate , Gross_pay;
5
Hayat Nabi Computer Programming Engr. M Amin Khan
09-131242-097 Lab # 08 Dept of SE, BUIC
Screenshot:
Task 5:
Write a program that calculates the average grade and final grade for multiple students based
on several test scores Using Funtions……
Code:
#include<iostream>
using namespace std;
int T1 , T2 , T3;
double Average(int T1 ,int T2 ,int T3){
double Test_Average = (T1 + T2 + T3 ) / 3;
return Test_Average;
}
int main(){
6
Hayat Nabi Computer Programming Engr. M Amin Khan
09-131242-097 Lab # 08 Dept of SE, BUIC
Screenshot: