Need a project done?

C++ Programming Developer

Search This Blog

Default Arguments in C++


/*
(Default arguments)
Write a program by defining a function "time" that takes three default arguments of integer type for Hours, Minutes and Seconds.
The function should print the time in standard format. The function should be called four times as:
*Function call without using any argument.
*Function call by passing values only for hours as arguments.
*Function call by passing values of hours and minutes as arguments.
*Function call by passsing values of hours, minutes and seconds as arguments
*/

#include <iostream>
using namespace std;

void time(int hours = 12, int minutes = 0, int seconds = 0);
int main()
{
cout<<"Function called without using any argument : ";time();
cout<<"Function called by passing value only for hours as argument";time(2);
cout<<"Function called by passing values of hours and minutes as argument";time(5,4);
cout<<"Function called by passing values of hours, minuts and seconds as arguments"; time(3,2,1);

return 0;
}

void time(int hours, int minutes, int seconds)
{
cout<<hours << ":" << minutes << ":" << seconds << endl;
}
"Don't let anyone ever make you feel like you don't deserve what you want."