Question

Use activity diagrams using Rhapsody for C++ and code in visual studio C++ 9. Given two...

Use activity diagrams using Rhapsody for C++ and code in visual studio C++

9. Given two time periods, determine if they are overlapping or not.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

In case of any query do comment. Please rate answer as well. Thanks

Code:

#include <iostream>
using namespace std;
  
//structure for TimePeriod
struct TimePeriod {
int start;
int end;
  
};

  
// main program
int main()
{
//declare timeperiod variables
TimePeriod timePeriod1, timePeriod2;
  
//take input from user
cout << "Enter first time period: " << endl;
cin >> timePeriod1.start >> timePeriod1.end;
  
cout << "Enter second time period: " << endl;
cin >> timePeriod2.start >> timePeriod2.end;
  
/*if you want to measure 9-10 and 10-11 as overlapping than change > to >=
time period may not be in order so check for both ways
*/
if((timePeriod1.start < timePeriod2.start && timePeriod1.end > timePeriod2.start) || (timePeriod1.start > timePeriod2.start && timePeriod2.end > timePeriod1.start))
cout << "Both the time periods are overlapping.";
else
cout << "Both the time periods are not overlapping.";
return 0;
}

===============screen shot of the code for indentation====

Output:

Add a comment
Know the answer?
Add Answer to:
Use activity diagrams using Rhapsody for C++ and code in visual studio C++ 9. Given two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT