Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Add time using structures in C++

Add time using structures in C++

This is a C++ implementation of adding time using structures or struct. A structure is a convenient tool for handling a group of logically related data items. Structure help to organize complex data is a more meaningful way. It is powerful concept that we may after need to use in our program Design.

Write a program having a structure named Time which has three integer data items i.e. hour, minute and second. The task is to add the variables of the Time data type though a function
void AddTime(Time *time1, Time *time2)
which takes as arguments the addresses of two Time type variables, adds these variables and stores the result in time2. The function must satisfy the following:

  1. If second exceeds 60 then add 1 in minutes and subtract 60 from seconds.
  2. If minute exceeds 60 then add 1 in hours and subtract 60 from minutes.
  3. If hour exceeds 24 then subtract 24 from hours.

Test this function and print the result in the calling function.

C++ For Dummies 7th Edition
Unlock the world of programming with C++ for Dummies – the perfect beginner’s guide to mastering C++ with ease and confidence!
View on Amazon

Output of the C++ Program

 

About The Author

M. Saqib

Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.