Professional Documents
Culture Documents
Semester : BS CS – 1A
Name : Muhammad Zain
Enroll no : (02-134182-037)
LAB 8
EXERCISE 1
Write a C++ Program that contains one user defined function month().
In main() function:
o Read an integer input in between (1 to 12) and store
it month_of_year.
o Call month(month_of_year) In month() function:
o Print the corresponding month of year in month(). o
Example: Value of parameter is 4… Print “April”.
SOURCE CODE
#include<iostream>
using namespace std;
else if (month_of_year==6)
cout<<"June";
else if (month_of_year==7)
cout<<"July";
else if (month_of_year==8)
cout<<"August";
else if (month_of_year==9)
cout<<"September";
else if (month_of_year==10)
cout<<"October";
else if (month_of_year==11)
cout<<"November";
else if (month_of_year==12)
cout<<"December";
else if (month_of_year>12)
cout<<"Sorry I need a number from 1-12."<<endl;
else if(month_of_year<=12)
cout<< "month of year "<<month_of_year;
int main ()
{
int n ,month_of_year;
cout<<"enter number between 1 to 12 : ";
cin>>n;
cout<<"\n";
month_of_year=n;
Department of computer science Semester BSCS-1A
CSL-113: Computer Programming Lab Lab 08: Funcion-1
CSL-113 : Computer Programming Lab
Semester : BS CS – 1A
Name : Muhammad Zain
Enroll no : (02-134182-037)
month(month_of_year);
OUTPUT
EXERCISE 2
Write a C++ Program that contains one user defined function cal_grades().
• In main() function:
o Prompt user to enter obtained(0 - 100) marks for one subject. o Call
cal_grades(marks_subject).
o Print the corresponding Grade with respect to Marks.
• In user defined function:
o Perform conditioning with else if statement return char value. o Function
must return value.
SOURCE CODE
#include<iostream>
using namespace std;
else
return 'F';
}
int main()
{
int n,marks_subject;
cout<<"enter marks : ";
cin>>n;
marks_subject=n;
EXERCISE 3
Write a C++ Program that contains four user defined function(s) addition(), subtraction(), division(),
multiplication(). Develop a calculator as follows
• In main() function:
o A menu with choices addition,subtraction,division and multiplication must be
displayed. o Get two numbers and a choice from user o Call the
respective functions with user given number as parameter using switch statement
o Print the result from addition(), subtraction, division(), multiplication().
• In user defined functions:
o Plus and Minus function get two integer values and return integer. o Multiply
and Divide functions get two integer values and return float.
SOURCE CODE
#include <iostream>
using namespace std;
mul =n1*n2;
return mul;
}
int main()
{
int n,n1,n2;
cout<<"\t\tmenu";
switch(n)
{
case 1 :
cout<<add(n1,n2);
break;
case 2 :
cout<<sub(n1,n2);
break;
case 3 :
multiply(n1,n2);
break;
case 4 :
divi(n1,n2);
break;
default :
cout<<"invalid press";
}
}
OUTPUT