Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.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++ 将变量中的数字添加到对象的属性 #包括 #包括 使用名称空间std; 类航天器 { 私人: 整数大小; 公众: int setSize(int new_size); int getSize(); int descripe(); 航天器(国际尺寸); }; _C++_Class - Fatal编程技术网

C++ 将变量中的数字添加到对象的属性 #包括 #包括 使用名称空间std; 类航天器 { 私人: 整数大小; 公众: int setSize(int new_size); int getSize(); int descripe(); 航天器(国际尺寸); };

C++ 将变量中的数字添加到对象的属性 #包括 #包括 使用名称空间std; 类航天器 { 私人: 整数大小; 公众: int setSize(int new_size); int getSize(); int descripe(); 航天器(国际尺寸); }; ,c++,class,C++,Class,将变量中的数字添加到对象的属性 #包括 #包括 使用名称空间std; 类航天器 { 私人: 整数大小; 公众: int setSize(int new_size); int getSize(); int descripe(); 航天器(国际尺寸); }; int航天器::设置大小(int新尺寸) { 尺寸=新尺寸; 返回0; } 航天器::航天器(新尺寸) { 尺寸=新尺寸; } int::getSize() { 返回大小; } int::descripe() { 你可以写下: #include

将变量中的数字添加到对象的属性
#包括
#包括
使用名称空间std;
类航天器
{
私人:
整数大小;
公众:
int setSize(int new_size);
int getSize();
int descripe();
航天器(国际尺寸);
};
int航天器::设置大小(int新尺寸)
{
尺寸=新尺寸;
返回0;
}
航天器::航天器(新尺寸)
{
尺寸=新尺寸;
}
int::getSize()
{
返回大小;
}
int::descripe()
{
你可以写下:

#include <cstring>
#include <iostream>
using namespace std;

class Spacecraft
{
private:
    int size;
public:
    int setSize( int new_size );
    int getSize();
    int describe();
    Spacecraft (int size);
};
int Spacecraft::setSize( int new_size)
{
    size = new_size;
    return 0;
}
Spacecraft::Spacecraft (int new_size)
{
    size = new_size;
}
int Spacecraft::getSize()
{
    return size;
}
int Spacecraft::describe()
{

    cout <<"Your spacecraft is size " (adding Customcraft.getSize() here);
    return 0;
}



int main() {
    int size;
    cout <<"Type in the size of your spacecraft: ";
    cin >>size;
        cout <<endl;

    Spacecraft Customcraft(the value of size to here);
    Customcraft.describe();




    return 0;
}

cout试一试:cout我正在做一个练习,它想让我使用descripe函数来输出用户的输入,所以我不得不这样做。如果我们在做有用的代码片段:
If(std::cin>>size){…}否则{std::cout我知道,在你的descripe函数中试试。@user2746748你误解了凯文说的话。
cout <<"Your spacecraft is size " << size);