Solution Lab Assignment 2.docx

# Solution Lab Assignment 2.docx - Solution Lab Assignment 2...

This preview shows pages 1–3. Sign up to view the full content.

Solution Lab Assignment # 2 1. Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes and seconds. The program then store the time in a variable of type struct time, and finally print out the total number of seconds represented by this time value. Source Code #include <iostream> using namespace std; struct Time { int Hours; int Minutes; int Seconds; int TotalTime_inSeconds; }; int main() { char Choice, Answer, c; Time T; do { cout<<"Enter (a) to enter a time"<<endl; cout<<"Enter (d) to display time in seconds"<<endl; cout<<"Enter (e) to exit"<<endl;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
cin>>Choice; if(Choice=='a') { cout<<"Enter a Time in format HH:MM:SS "<<endl; cin>>T.Hours>>c>>T.Minutes>>c>>T.Seconds; } else if(Choice=='d') { T.TotalTime_inSeconds = (T.Hours*3600) + (T.Minutes*60) + T.Seconds; cout<<"Time in seconds ="<<T.TotalTime_inSeconds<<endl; } else if(Choice=='e') { cout<<"Thankew for Using Time Calculation Program "<<endl; } else { cout<<"A wrong Choice, please enter a correct one"<<endl; } cout<<"Do you want to continue?(y/n)"<<endl;
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern