User-defined function can be defined as a function written by the programmers to accomplish certain specific tasks.
(a) List down the FOUR (4) types of user-defined function.
(b) Write the function prototype for each of the following user-defined functions:
i. Function calcPower() that receives the voltage and current of type double. This function will return a value to calling function.
ii. Function DisplayWelcome() that does not receives any values and does not return a value.
M
iii. Function triangleArea() that receives the height and the base of a triangle of type float. This function will not return any value to calling function.
using namespace std;
/*
User-defined function can be defined as a function written by the programmers to accomplish certain specific tasks.
(a) List down the FOUR (4) types of user-defined function.
(b) Write the function prototype for each of the following user-defined functions:
i. Function calcPower() that receives the voltage and current of type double. This function will return a value to calling function.
ii. Function DisplayWelcome() that does not receives any values and does not return a value.
iii. Function triangleArea() that receives the height and the base of a triangle of type float. This function will not return any value to calling function.
*/
double calcPower(double V, double I)
{
float Power = V*I;
return(Power);
}
void DisplayWelcome(void)
{
cout<<"\n\tWELCOME";
}
void triangleArea(float h, float b)
{
float Area = 0.5*h*b;
cout<<"\n\tTriangle Area = "<<Area;
}
int main()
{
cout<<"\n\tPower = "<<calcPower(5, 2);
DisplayWelcome();
triangleArea(5, 6);
return(0);
}
Comments
Leave a comment