将变量中的数字添加到对象的属性中
Adding number from variable to the property of an object
#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;
}
我正在尝试将用户输入放入航天器客户(大小(中。这不起作用,所以我想知道如何将大小值添加到其中,以便计算机不会查看单词而是整数值。
是否可以将 Customcraft.getSize(( 链接到 describe(( 函数?当我尝试定制时,无法识别。我是这门课的新手,所以请尽量将解释保持在初学者的水平。
编辑:我还有最后一个问题,谢谢你解决我的第一个问题。在学校,当我把尺寸放入航天器定制飞船(size(时,日食无法识别变量的整数值。那么可能是因为日食(靛蓝(而不是开普勒吗?
你可以写:
cout <<"Your spacecraft is size " << size);
相关文章:
- 类对象属性是否可以调用返回属性应具有的值的方法C++?
- 对象属性同级访问
- 迭代 Napi::对象属性(键)在 Node.js C++ N-API 中
- 是否可以在C++(17)中捕获某些对象属性的破坏性赋值事件
- 分配以下对象属性在哪里
- sutex作为对象属性和对象的向量
- C++ - 在类中包含不是类对象属性的变量是否是一种不好的做法
- 根据对象属性从列表中删除对象
- 将对象属性替换为列表
- 查找对象属性是否位于对象向量C++中
- 未知EABI对象属性44
- 按矢量中的对象属性合并排序
- 如何访问带有静态回调的对象属性
- c++中对象属性的内存分配
- 为什么对象属性的值在 c++ 中将其指针添加到映射后返回零
- 如何检查对象属性更新是否存在 std::map 键,否则插入一个新键?
- 从ASP.NET应用程序查询Active Directory对象属性将返回旧结果
- 性能对象属性与范围变量
- 无法访问对象属性
- 如何从对象方法中访问对象属性