
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check Tank Status: Overflow, Underflow, or Filled in Given Time
Given with the rate of filling the tank, height of a tank and radius of a tank and the task is to check whether the tank is overflow, underflow and filled in given time.
Example
Input-: radius = 2, height = 5, rate = 10 Output-: tank overflow Input-: radius = 5, height = 10, rate = 10 Output-: tank undeflow
Approach used below is as follows −
- Input the rate of filling time, height and radius of a tank
- Calculate the volume of a tank to find the original rate of flow of water.
- Check for the conditions to determine the result
- If expected < original than tank will overflow
- If expected > original than tank will underflow
- If expected = original than tank will fill on time
- Print the resultant output
Algorithm
Start Step 1->declare function to calculate volume of tank float volume(int rad, int height) return ((22 / 7) * rad * 2 * height) step 2-> declare function to check for overflow, underflow and filled void check(float expected, float orignal) IF (expected < orignal) Print "tank overflow" End Else IF (expected > orignal) Print "tank underflow" End Else print "tank filled" End Step 3->Int main() Set int rad = 2, height = 5, rate = 10 Set float orignal = 70.0 Set float expected = volume(rad, height) / rate Call check(expected, orignal) Stop
Example
#include <bits/stdc++.h> using namespace std; //calculate volume of tank float volume(int rad, int height) { return ((22 / 7) * rad * 2 * height); } //function to check for overflow, underflow and filled void check(float expected, float orignal) { if (expected < orignal) cout << "tank overflow"; else if (expected > orignal) cout << "tank underflow"; else cout << "tank filled"; } int main() { int rad = 2, height = 5, rate = 10; float orignal = 70.0; float expected = volume(rad, height) / rate; check(expected, orignal); return 0; }
Output
tank overflow
Advertisements