c++ - 如何使用函数调用失败或通过多个测试?
问题描述
我试图弄清楚如何调用一个函数。我必须能够输入负载量并查看它是否通过了三个测试。这些是给出的方程。
Buckling Load:
Max Load = (0.3*E*area) / ((length/width) * (length/width))
Compressive stress:
Max Load = area * maximum compressive strength
Slenderness limits:
Length/width <= 50
E 是弹性模量 (1,700,000 psi),面积是以平方英寸为单位的横截面积,最大抗压强度 = 445 psi (花旗松)。假设要使用的柱子是方形的,并且有 2 英寸的间隔(2x2、4x4、6x6 等)。我必须为每个人使用不同的功能!帮助 :/
我目前有:
{
int strength, area, length, width, e, maxLoad, bucklingLoad, compressiveLoad, slenderness;
float bucklingLoad;
e = 1700000,
maxLoad =
cout << "Jessica's Engineering Company Analysis" ;
cout << "\n*************************************";
cout <<"\n\nPlease enter the expected load on the column in pounds: ";
cin << maxLoad;
cout << "\nPlease enter the length of the column in inches: ";
cin << length;
cout << "\n\n_Beam with wide of 2 inches - " ;
cout << "\n_Beam with wide of 4 inches - " ;
cout << "\n_Beam with wide of 6 inches - " ;
cout << "\n_Beam with wide of 8 inches - " ;
}
解决方案
I'm not going to do the whole thing, and you should absolutely learn C++ properly from a book or other resource, because asking open-ended questions is going to be a really slow, frustrating and inefficient way to figure it out - but I can give you a hint to get started.
Buckling Load:
Max Load = (0.3*E*area) / ((length/width) * (length/width))
So we can translate this directly into a function, like
double calcBucklingLoad(int length, int width, int area)
{
return (0.3*E*area) / ((length/width) * (length/width));
}
(so long as we first define E somewhere, like
const double E = 1700000;
or something similar. It could be another function parameter if you want to reuse the code for different materials).
Then testing whether the max load is greater than the buckling load is just
bool isBucklingLoadOK(int maxload, int length, int width, int area)
{
return maxload < calcBucklingLoad(length, width, area);
}
推荐阅读
- html - W3C 标记验证:此时元素“样式”上不允许属性“ng-transition”
- javascript - 如何使铯的可见颜色透明
- java - 替换Java中的html编码字符
- javascript - 折线图未显示单击单选按钮时的数据
- php - 如何调用类的函数从 angularjs 代码中获取 .php 文件中的数据?
- python - Ansible:如何更改 Python 版本
- c - 编译器如何处理数据类型?
- excel - 使用 VBA。如何限制 MS PowerPoint 中的对象相互重叠?
- jvm - 在 JVM 启动参数中隐藏纯文本密码。“ ps -ef | grep 'javax.net.ssl.keyStorePassword'”
- amazon-web-services - AWS Lambda 停止 EC2 但排除两个实例