- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to check if tank will 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
- Related Articles
- Java overflow and underflow
- Range Overflow and Range Underflow properties in JavaScript.
- C++ Program to check if given numbers are coprime or not
- Program to check if water tank overflows when n solid balls are dipped in the water tank in C++
- C program to check if a given string is Keyword or not?
- Java Program to check for Integer overflow
- C++ Program to Check if a Given Graph must Contain Hamiltonian Cycle or Not
- C++ program to Check if a Given Binary Tree is an AVL Tree or Not
- Python program to check if a given string is Keyword or not
- Check for Integer Overflow in C++
- Program to check whether given words are maintaining given pattern or not in C++
- Program to check if two given matrices are identical in C++
- Program to check if the given list has Pythagorean Triplets or not in Python
- C++ Program to check whether given password is strong or not
- C++ program to check whether given string is bad or not

Advertisements