Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;yard.h收割台以编程方式获取面积 我对C++比较陌生,它本质上只是我大学的一个填充类。我被困在这个院子里。我需要创建具有以下要求的标题:_C++_Oop - Fatal编程技术网

C++;yard.h收割台以编程方式获取面积 我对C++比较陌生,它本质上只是我大学的一个填充类。我被困在这个院子里。我需要创建具有以下要求的标题:

C++;yard.h收割台以编程方式获取面积 我对C++比较陌生,它本质上只是我大学的一个填充类。我被困在这个院子里。我需要创建具有以下要求的标题:,c++,oop,C++,Oop,庭院类中的以下5个公共功能: getWidth(),setWidth(),getLength(),setLength(),以及getAcres() 验证宽度和长度以确保它们不是负值 仅供参考:一英亩有43560平方英尺 注意:我还没有学习任何关于头、类和对象的知识 以下是老师给我的预制代码: // Yard class class Yard { private: double width, length; // Feet public: }; // C++ Classes e

庭院类中的以下5个公共功能:
getWidth()
setWidth()
getLength()
setLength()
,以及
getAcres()

验证宽度和长度以确保它们不是负值

仅供参考:一英亩有43560平方英尺

注意:我还没有学习任何关于头、类和对象的知识

以下是老师给我的预制代码:

// Yard class 

class Yard 
{ 
private:
    double width, length; // Feet

public:
};

// C++ Classes end with a semicolon!

//Program requirements:
//⦁ Create the following 5 public functions in the Yard class://
//⦁ getWidth(), setWidth(), getLength(), setLength(), and getAcres() 
//⦁ The main() driver code is already setup to use these 5 functions
//⦁ Validate the width and length to ensure they are not negative
//⦁ FYI: There are 43560 square feet in an acre

以下是老师在main.cpp中为我设置的代码:

/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo/
/O::::::::::::::::::::::::::::::::::::::::::::::::O/
/o:::::::::::Programmer: Tristan Moore::::::::::::o/
/:::::::::::::::::Date: 02/07/2021::::::::::::::::o/
/O::::::::::::::::::::::::::::::::::::::::::::::::O/
/oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOo*/

#include <iostream>
#include <iomanip>

#include "yard.h"

using namespace std;

int main()
{
    /////////////////////////
    //                     //
    //   MINI PROGRAM #3   //
    //                     //
    /////////////////////////

    Yard yard1, yard2, yard3;
    double length, width;

    cout << endl;
    cout << "------------------------------------------------------" << endl;
    cout << "INPUTTING WIDTH (FT) AND LENGTH (FT), OUTPUTTING ACRES" << endl;
    cout << "------------------------------------------------------" << endl;
    cout << endl;

    yard1.setLength(150);
    yard1.setWidth(75);

    yard2.setLength(220);
    yard2.setWidth(200);

    // Input
    cout << "Enter the length of your Yard (ft): ";
    cin >> length;
    cout << "Enter the width of your Yard (ft): ";
    cin >> width;

    if (length < 0){
        length = 0;
    }

    if (width < 0){
        width = 0;
    }

    //set Width
    //set Length

    cout << endl << fixed << setprecision(2);

    // Output
    cout << "Acres in Yard #1 (" << yard1.getLength() << "ft X " << yard1.getWidth() << "ft): " << yard1.getAcres() << endl;
    cout << "Acres in Yard #2 (" << yard2.getLength() << "ft X " << yard2.getWidth() << "ft): " << yard2.getAcres() << endl;
    cout << "Acres in Yard #3 (" << yard3.getLength() << "ft X " << yard3.getWidth() << "ft): " << yard3.getAcres() << endl;
    cout << endl;
}
/*oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo/
/O::/
/o::/
/:日期:2021年7月2日:/
/O::/
/oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*/
#包括
#包括
#包括“码h”
使用名称空间std;
int main()
{
/////////////////////////
//                     //
//小型节目#3//
//                     //
/////////////////////////
码1、码2、码3;
双倍长度、宽度;

所以,这里有一个院子,可以回答老师的简短问题

class Yard
{
    const double _dSqFtToAcre = 43560;
    
    double _length;
    double _width;
public:
    Yard(const double& length = 0, const double& width = 0)
        :_length(length),_width(width)
    {}

    void setLength(const double& length)
    {
        if (length > 0) _length = length;
    }
    
    double getLength() const
    {
        return _length;
    }   
    
    void setWidth(const double& width)
    {
        if (width > 0) _width = width;
    }

    double getWidth() const
    {
        return _width;
    }

    double getAcres() const
    {
        return (_length * _width) / _dSqFtToAcre;
    }
};
main.cpp中的这一部分。请注意,长度或宽度大于零的检查由Yard类处理

// Input
cout << "Enter the length of your Yard (ft): ";
cin >> length;
yard3.setLength(length);

cout << "Enter the width of your Yard (ft): ";
cin >> width;
yard3.setWidth(width);
//输入
长度;
码3.设置长度(长度);
宽度;
码3.设置宽度(宽度);

如果你想得到答案,你需要一个问题……你的问题是什么?@Heyji在上面的帖子中。它返回错误。我很困惑。我正在尝试让yard.h中的所有公共函数在我的main.cpp中正常工作。如果你能顺利通过,那会有很大帮助。通常,我们希望看到a,以及你收到的确切错误消息ing,至少是这样,但事实上,所有这些代码中都有很多明显的错误。
yard3
从未分配任何值,所有用户输入在验证后都会被完全忽略。在
Yard
类中,
i
m
区域
成员没有理由公开,并且另外,
width
length
成员从未使用过。
getLength
由于某种原因写入输出,其数学是错误的。独立的方法定义通常不属于标题。好的,我已经从我第一次开始的地方对代码进行了编辑。我不太知道如何简化我的要求。那完美地工作。因为我已经落后了(很清楚)你会建议什么来作为参考来学习上面的。@黑桃首先,如果回答了你的问题,请点击滴答声来表示。第二,C++不是真正的入门级。语言,所以你进入C++的路径将取决于你是否已经知道另一种语言。我恐怕是25年前在一个IT小组里学习的:即使现在我已经很不幸地在语言的发展上落后了。我会问你的老师,好像这已经被设定为课程工作,他们应该能够把你指给一个阅读列表。首先,如果你认为这是一个值得回答的体面的问题,那么请点击滴答声,以表示这一点。