Initial Basics – Algebra – Problem #34

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: Hard

Problem Statement

An aeroplane can travel at a speed of 700km/h from a source A either eastwards or westwards. If it travels east, the time advances at a rate of 1 hour per 500 km and if it travels west time recedes back at the equal rate, with respect to the starting point A. Write a program to take input i) the starting time of the aeroplane in hours and minutes only (you can consider 24 hour clock so 1PM becomes 13 hour 0 minutes), ii) the duration of the flight (you can assume the maximum duration to be 6 hours) and iii) a character representing eastward or westward travel (like ‘e’ for eastwards and ‘w’ for westwards). Hence perform the following, (A) Check whether the starting time is a valid time or not. If the starting time is invalid, print “Error” and you can exit from the program. (B) Depending on the duration of flight and eastward or westward direction of travel, display the local time of arrival (i.e the local time at the arrival point) in the same 24 hour format. Consider the case of adjusting the time of arrival as per the standard 24 hour day format and take care of hour overflow (in case of eastward travel) or underflow (in case of westward travel). (C) Also print “same day” or “previous day” or “next day” depending on the day of arrival with respect to the starting day Assume that the aeroplane travels in the given speed uniformly from source to destination. Also you can assume all integer values. Example1: (Please take the input and display the output as shown) Input: Starting hour: 14 Starting minute: 15 Duration: 5 Direction: e Output: Starting time is valid Arrival time hour: 21 Arrival time minute: 15 Arrival day: same day Example2: (Please take the input and display the output as shown) Input: Starting hour: 26 Starting minute: 15 Duration: 6 Direction: w Output: Starting time is invalid

Back to Lab Problems
Initial Basics/Algebra/Problem #34

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #34

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.