Professional Documents
Culture Documents
Page 1 of 3
Q2: (05 Marks)
Default argument is a type of function arguments. Elaborate its functionality and use with the help of an
example.
Answer: A default argument is a worth given in a capacity presentation that is consequently appointed by the
compiler if the guest of the capacity doesn't offer a benefit for the contention with a default esteem. ... We don't need
to compose 3 entirety capacities, just one capacity works by utilizing default values for third and fourth contentions.
For example: Calling of function sum (10, 15, 25, 30) overwrites the value of c and d to 25 and 30
respectively. During calling of function, arguments from calling function to called function are copied from
left to right
#include<iostream>
using namespace std;
// A function with default arguments, it can be called with
// 2 arguments or 3 arguments or 4 arguments.
int sum(int x, int y, int z=0, int w=0)
{
return (x + y + z + w);
}
/* Driver program to test above function*/
int main()
{
cout << sum(10, 15) << endl;
cout << sum(10, 15, 25) << endl;
cout << sum(10, 15, 25, 30) << endl;
return 0;
}
void show(Dimensions);
int main()
{
Dimensions X = {40,50}, Y, Z;
Z = X;
X.C += 10;
Y = Z;
Y.C += 10;
Y.R += 20;
Z.C -= 15;
show(X);
show(Y);
show (Z);
return 0;
}
void show(Dimensions D)
{
cout << "X coordinate "<< D. x_cord << " Y coordinate " << D. y_cord << endl;
}
Suppose you own a Car Showroom and you have 10 different cars at the showroom. You need to maintain the record
of all the registered cars and display their data when required.
Create a structure Cars, containing registration number (int), name (char []), model number(int), date of
arrival(nested) as structure members. (03 Marks)
1. Main function should ask the user to enter username and password to proceed further. (02 Marks)
2. Main function should display a menu either to enter the record or display the record. Program should call the
function according to user’s choice. (02 Mark)
3. If user chooses to enter the record, program should store the data in a structure array of 10 members. Program
should ask the user if he wants to enter the next record. (02 Mark)
4. If user chooses to display the record and there is record present, program should display the list of record (in
ascending order of date of arrival, as mentioned in point 5), if there is no record present then it should display a
message of “no record found”. (03 Marks)
5. Record displayed by point number 4 should be sorted in descending order of date of arrival of cars by using a sort
function. (03 Marks)
***END***
Page 3 of 3