第3周项目3-用对象数组操作长方柱体

本文介绍了一个基于对象的程序设计案例,通过定义长方柱类并实现其体积和表面积的计算方法。该程序利用对象数组存储五个长方柱实例,并演示了不同构造函数的使用方式以及成员函数的应用。
/*
*copyright (c)2015,烟台大学计算机学院
*All rights reserved
*文件名称:project.cpp
*作者:孙春红
*完成日期:2015年3月31日
*版本号:v1.0
*
*问题描述:编写基于对象的程序,求5个长方柱的体积和表面积。
长方柱类Bulk的数据成员包括长(length)、宽(width)、高(heigth)等。
对照已经给出的代码,要做的工作及要求有:
1、需要你定义长方柱类,代码中已经给出由5个长方柱对象构成的对象数组b;
2、B数组中的前3个对象b[0]、b[1]、b[2]直接参数初始了,需要定义构造函数,
而初始化中,各对象提供的参数数目不同,需要有默认参数的构造函数(未给
出的参数默认为1.0)
3、第4个对象b[3]用默认构造函数初始化;
4、第5个长方柱b[4]定义时不初始化,设计成员函数get_value,由键盘输入长、宽、高;
5、设计成员函数output,在main中调用输出这5个长方柱的体积和表面积;
*输入描述:略。
*程序输出:略。
*/
#include <iostream>
using namespace std;
class Bulk
{
private:
    double lengh,width,height;
public:
    double surface();
    double volume();
    void get_value();
    Bulk(double l=1,double w=1,double h=1):lengh(l),width(w),height(h){}
};
int main()
{
     Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
     b[4].get_value();
     for(int i=0;i<5;i++)
     {
         cout<<"长方柱体"<<i<<"的体积是:"<<b[i].volume()<<endl;
         cout<<"长方柱体"<<i<<"的表面积是:"<<b[i].surface()<<endl;
     }
}
void Bulk::get_value()
{
    cout<<"请输入长方柱体的长宽高:"<<endl;
    cin>>lengh>>width>>height;
}
double Bulk::volume()
{
    return (lengh*width*height);
}
double Bulk::surface()
{
    return (2*(lengh*width+lengh*height+height*width));
}

运行结果:


知识点总结:

学会使用对象数组解决问题,以及对象数组的结构以及声明运用时注意的问题。

c++题目,代码禁止有注释 A Angry Birds 作者 刘春英 单位 杭州电子科技大学 Aris is playing the classic game, Angry Birds! Because Aris has been playing for too long, Yuuka confiscated Aris’s game console and demanded that Aris complete today’s math homework before getting it back. However, Sensei did not assign any math homework to Aris today, so Yuuka had to come up with a problem for Aris to solve. Consider the game field of Angry Birds as a three-dimensional Euclidean space, and the bird as a sphere with radius R 3 ​ . Establish a spatial Cartesian coordinate system O−xyz, such that the trajectory of the bird’s center lies in the horizontal plane z=0. It is known that the trajectory of the bird’s center is a closed polyline, consisting of n segments connected end to end. The connection points are n points: (x 1 ​ ,y 1 ​ ,0),(x 2 ​ ,y 2 ​ ,0),⋯,(x n ​ ,y n ​ ,0). The i-th segment has endpoints (x i ​ ,y i ​ ,0) and (x imodn+1 ​ ,y imodn+1 ​ ,0). However, due to sensor errors, the actual n points may deviate from (x i ​ ,y i ​ ,0) by a distance not exceeding R 2 ​ (the sensor deviation R 2 ​ is the same for all points). That is, the actual i-th point (x i ′ ​ ,y i ′ ​ ,0) can be anywhere within the circle (which is still contained in the plane z=0) centered at (x i ​ ,y i ​ ,0) with radius R 2 ​ . Let S be the set of all points that the entire bird may pass through, i.e., points in 3D space whose distance to the bird’s center trajectory is at most R 3 ​ . Yuuka requires Aris to compute the volume of the convex hull of S. Convex hull: The convex hull of a point set S is defined as the smallest set T such that for any two points in S, all points on the line segment between them are contained in T. Input Format The first line contains a positive integer T (1≤T≤10 3 ), indicating the number of test cases. For each test case, the first line contains three integers n,R 2 ​ ,R 3 ​ (1≤n≤10 5 ,0≤R 2 ​ ,R 3 ​ ≤10 6 ), representing the number of connection points, the sensor error radius, and the bird radius, respectively. The next n lines each contain two integers x i ​ ,y i ​ (∣x i ​ ∣,∣y i ​ ∣≤10 6 ), representing the i-th connection point of the trajectory. It is guaranteed that the sum of n over all test cases in a single test point does not exceed 10 5 . Output Format For each test case, output a single floating-point number representing answer. Your answer is considered correct if the relative or absolute error compared to the standard answer is at most 10 −9 . Let your answer be a and the standard answer be b. If max{b,1} ∣a−b∣ ​ ≤10 −9 , it is considered correct. Sample 1 5 1 1 0 0 3 1 2 3 2 2 -1 3 77.622211120429587 Notes The convex hull of all points that the bird’s center may pass through: sample.png 代码长度限制 32 KB Java (javac) 时间限制 2000 ms 内存限制 256 MB Python (python2) 时间限制 2000 ms 内存限制 256 MB Python (python3) 时间限制 2000 ms 内存限制 256 MB Python (pypy3) 时间限制 2000 ms 内存限制 256 MB Kotlin (kotlinc) 时间限制 2000 ms 内存限制 256 MB 其他编译器 时间限制 1000 ms 内存限制 256 MB 栈限制 131072 KB
10-23
内容概要:本文提出了一种基于融合鱼鹰算法和柯西变异的改进麻雀优化算法(OCSSA),用于优化变分模态分解(VMD)的参数,进而结合卷积神经网络(CNN)与双向长短期记忆网络(BiLSTM)构建OCSSA-VMD-CNN-BILSTM模型,实现对轴承故障的高【轴承故障诊断】基于融合鱼鹰和柯西变异的麻雀优化算法OCSSA-VMD-CNN-BILSTM轴承诊断研究【西储大学数据】(Matlab代码实现)精度诊断。研究采用西储大学公开的轴承故障数据集进行实验验证,通过优化VMD的模态数和惩罚因子,有效提升了信号分解的准确性与稳定性,随后利用CNN提取故障特征,BiLSTM捕捉时间序列的深层依赖关系,最终实现故障类型的智能识别。该方法在提升故障诊断精度与鲁棒性方面表现出优越性能。; 适合人群:具备一定信号处理、机器学习基础,从事机械故障诊断、智能运维、工业大数据分析等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①解决传统VMD参数依赖人工经验选取的问题,实现参数自适应优化;②提升复杂工况下滚动轴承早期故障的识别准确率;③为智能制造与预测性维护提供可靠的技术支持。; 阅读建议:建议读者结合Matlab代码实现过程,深入理解OCSSA优化机制、VMD信号分解流程以及CNN-BiLSTM网络架构的设计逻辑,重点关注参数优化与故障分类的联动关系,可通过更换数据集进一步验证模型泛化能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值