Coders Packet

Addition of time using friend function with concept of bridge in C++

By Pankhuri

Friend function is used in addition of 2 time formats along with the concept of bridge. It gives output in hours:minutes:seconds.

In this project, two classes are formed where class A takes the input in public mode. It takes the input from the user for an hour, a minute, and seconds two times. Input and show functions are there in class A. There is a friend function that is used to access the data. In the main function, objects are created to access the function from the respective class. Thus, after addition output is shown in hours:minutes: seconds format after considering the fact that 60 minutes is the highest value for minute rest goes to hour similarly for seconds where the rest goes to minute.

 C++ program shows the usage of the friend function along with the concept of the bridge. a friend function is that function that can access the private, protected, and public members of a class. If the friend function is not a part of a class then the object is not required for invocation. class B is declared before class A that is a forward declaration of that class. The friend function acts as a bridge. So, this is how the program works using this concept and gives the desired output.

Download Complete Code


No comments yet

Download Packet

Reviews Report

Submitted by Pankhuri (Pankhuri)

Download packets of source code on Coders Packet