C ++程序检查罐在给定时间内是否会溢出,下溢或充满
给定储罐的填充速度,储罐的高度和储罐的半径,任务是检查储罐在给定时间内是否溢出,下溢和填充。
示例
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 计算水箱体积
float volume(int rad, int height)
return ((22 / 7) * rad * 2 * height)
step 2-> declare 检查上溢,下溢和填充的功能
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;
//计算水箱体积
float volume(int rad, int height) {
return ((22 / 7) * rad * 2 * height);
}
//检查上溢,下溢和填充的功能
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