开发基本的C++代码+检查错误/警告
Develop basic C++ code + Check the errors/warnings
嗨,这是一个uni赋值我在parta中要做的是:使用Kouti类声明编写main()代码-将变量ogkos的值初始化为0.0(在此变量中,将存储稍后计算的每个盒子的体积)-它将使用值2.0、3.2和6.0初始化KoutiA-它将使用值2.5、4.0和5.0初始化KoutiB-盒子A的体积将被计算并保存在变量ogkos中,然后显示在屏幕上-盒子B的体积将被计算并保存在变量ogkos中,然后显示在屏幕上
这是类声明
class Kouti
{
public:
double length;
double breadth;
double height;
};
到目前为止,我已经完成了parta。这是我的代码:
#include <iostream>
using namespace std;
class Kouti
{
public:
//constructor that initialize Box dimensions
explicit Kouti(double lengthOfKouti, double breadthOfKouti,
double heightOfKouti)
: length(lengthOfKouti), breadth(breadthOfKouti),
height(heightOfKouti)
{
//empty body
}
double length;
double breadth;
double height;
double ogkos = 0.0;
/*
void displayMessage() const
{
cout << "Welcome to the Kouti program!" << endl;
}
*/
/*
void calculateOgkos() const
{
ogkos = length*breadth*height;
cout << ogkos;
}
*/
};
int main()
{
Kouti KoutiA(2.0, 3.2, 6.0);
Kouti KoutiB(2.5, 4.0, 5.0);
KoutiA.ogkos = KoutiA.length*KoutiA.breadth*KoutiA.height;
KoutiB.ogkos = KoutiB.length*KoutiB.breadth*KoutiB.height;
// Display the volume of each box
cout << "KoutiA volume is: " << KoutiA.ogkos
<< "nKoutiB volume is: " << KoutiB.ogkos
<< endl;
return 0;
}
它似乎运行得很好不过,它给了我一个关于非静态数据成员初始化器的警告,该初始化器仅在-std=c++11或-std=gnu++11时可用。我正在使用代码块
Partb
在第b部分中,我必须执行以下操作:将类成员数据转换为private,并提供适当的公共函数calculateOgkos(),该函数将计算每个对象的体积。在main()中进行适当的更改,使其像在parta中一样工作。你能帮我吗?
还有一些不相关的。。。我一直在尝试注册代码块论坛,但我没有收到激活电子邮件。我试过好几次了。感谢
您几乎已经完成了工作…:
class Kouti
{
public:
//constructor that initialize Box dimensions
explicit Kouti(double lengthOfKouti, double breadthOfKouti,
double heightOfKouti)
: length(lengthOfKouti), breadth(breadthOfKouti),
height(heightOfKouti)
{
//empty body
}
double calculateOgkos() const
{
return length*breadth*height;
}
private:
double length;
double breadth;
double height;
};
Main:
int main()
{
Kouti KoutiA(2.0, 3.2, 6.0);
Kouti KoutiB(2.5, 4.0, 5.0);
// Display the volume of each box
cout << "KoutiA volume is: " << KoutiA.calculateOgkos()
<< "nKoutiB volume is: " << KoutiB.calculateOgkos()
<< endl;
return 0;
}
相关文章:
- error_code:如何设置和检查错误
- CocoaPod - 在头文件中使用 C++ 时出现 Podspec 检查错误
- 在编写包装现有函数并检查错误的模板函数时,如何使用完美转发?
- swscanf_s - 运行时检查错误
- 为什么C++字符串迭代器不检查错误?
- 如何使用运行时检查错误来修复我的C 格斗游戏
- XCode -Mac App -Bootstrap启动时检查错误
- 挂钩发送/WSASEND返回运行时检查错误#0
- 从整数到枚举值时,如何和何处检查错误
- C .如何检查错误的输入
- C++ 输入字符而不是 int 会导致无限循环.如何检查错误的输入
- 检查错误时重载>>运算符中的无限循环
- 开发基本的C++代码+检查错误/警告
- 在C++中,如何在使用gzstream编写压缩文件时检查错误
- 如何使 cuda-memcheck 在出现泄漏检查错误时返回非零
- 是否可以使用GetLastError检查错误代码是否已恢复
- 何时检查错误,使用 QIODevice 的阻塞接口(QTcpSocket 和 QFile)
- 在调用 recv() 之前检查错误
- C++类型检查错误
- 如何修复配置 PHP 7.0.1 时C++预处理器"/lib/cpp"健全性检查错误