탱크를 채우는 비율, 탱크의 높이, 탱크의 반경을 고려하여 주어진 시간 내에 탱크가 오버플로, 언더플로 및 채워져 있는지 확인하는 작업입니다.
예시
Input-: radius = 2, height = 5, rate = 10 Output-: tank overflow Input-: radius = 5, height = 10, rate = 10 Output-: tank undeflow
아래에 사용된 접근 방식은 다음과 같습니다. -
- 탱크의 충전 시간, 높이 및 반경을 입력
- 탱크의 부피를 계산하여 원래 물의 흐름 속도를 찾습니다.
- 결과를 결정하기 위한 조건 확인
- 예상되는 경우 <탱크보다 원본이 넘칠 것입니다.
- 예상되는 경우> 탱크보다 원본이 언더플로됩니다.
- 예상되는 경우 =탱크가 제 시간에 채워지는 것보다 원본
- 결과 출력 인쇄
알고리즘
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
예시
#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; }
출력
tank overflow