Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

INTRODUCTION: Several seasons of hot summers and cold winters have taken their toll on Farmer John's fence, and he decides it is time to repaint

INTRODUCTION: Several seasons of hot summers and cold winters have taken their toll on Farmer John's fence, and he decides it is time to repaint it, along with the help of his favorite cow, Bessie. Unfortunately, while Bessie is remarkably proficient at painting, she is not as good at understanding Farmer John's instructions.

If we regard the fence as a one-dimensional number line, Farmer John paints the interval between x=a and x=b. For example, if a=3 and b=5, then Farmer John paints an interval of length 2. Bessie, misunderstanding Farmer John's instructions, paints the interval from x=c to x=d, which may possibly overlap with none, part, or all of Farmer John's interval. Please determine the total length of fence that is now covered with paint.

INPUT FORMAT:

Your program must open and read an input file containing the following two lines of data:

The first line of the input file contains the integers a and b, separated by a space (a

The second line of the input file contains integers c and d, separated by a space (c

The values of a, b, c, and d all lie in the range 0100, inclusive.

OUTPUT FORMAT:

Please output a single line containing the total length of the fence covered with paint.

SAMPLE INPUT:

7 10

4 8

SAMPLE OUTPUT:

6

Here, 6 total units of fence are covered with paint, from x=4 all the way through x=10.

INCLUDE IN YOUR ASSIGNMENT

At the top of each of your C++ programs, you should have at least four lines of documentation:

// Program name: tictactoe.cpp

// Author: Twilight Sparkle

// Date last updated: 5/26/2016

// Purpose: Play the game of Tic-Tac-Toe

1.The Source code for the lab assignment (*.cpp)

2.And any Header files for the lab assignment (*.h)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

a. How will the leader be selected?

Answered: 1 week ago

Question

b. Will new members be welcomed?

Answered: 1 week ago