Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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
Visual studio 2010 我的C++温度转换器有什么问题?_Visual Studio 2010_C++11 - Fatal编程技术网

Visual studio 2010 我的C++温度转换器有什么问题?

Visual studio 2010 我的C++温度转换器有什么问题?,visual-studio-2010,c++11,Visual Studio 2010,C++11,我正试图编写一个程序,获取华氏度的值,验证该值以确保其合法性,并返回华氏度、摄氏度和牛顿的正确值 下面的代码不断为void的第21、25、29行提供错误消息 #include <iostream> using namespace std; class temperature { public: double getFahrenheit(); double getCelsius(); double getNewton(); void setFahrenheit(); void s

我正试图编写一个程序,获取华氏度的值,验证该值以确保其合法性,并返回华氏度、摄氏度和牛顿的正确值

下面的代码不断为void的第21、25、29行提供错误消息

#include <iostream>
using namespace std;

class temperature {
public:

double getFahrenheit();
double getCelsius();
double getNewton();

void setFahrenheit();
void setCelsius();
void setNewton();

private:
    double fahrenheit, Celsius;
    double c, f;

};
void freezing.setFahrenheit(){
    f = 32;
    fahrenheit = f;
}
void freezing.setCelsius(){
    c = (5.0/9.0) * ( f - 32);
    celsius = c;
}
void freezing.setNewton(){
n=(33.0/100.0)*c;
newton=n;

double freezing.getFahrenheit(){
    return fahrenheit;
}

double freezing.getCelsius(){
    return Celsius;
}
Double freezing.getNewton(){
Return Newton;
}
int main() {



Temperature freezing(32);
Freezing.setFahrenheit();                                                                         Freezing.setCelsius();
Freezing.setNewton();

cout << "water freezes at " << freezing.getFahrenheit() << " Fahrenheit, " << freezing.getCelsius() << " Celisus, and " << freezing.getNewton() << " Newton" << endl;




return 0;
}您需要使用::而不是。此外,你们的课程叫做“温度与非冻结”

另见

还有一些其他错误:

void temperature::setCelsius(){ //and not void freezing.setCelsius
    c = (5.0/9.0) * ( f - 32);
    celsius = c;
}
这里引用的是摄氏度,但temperature类使用大写C定义摄氏度

void freezing.setNewton(){
n=(33.0/100.0)*c;
newton=n;
这里使用n和newton变量,但没有在任何地方定义它们。他们也许应该是你的温度班的成员

Double freezing.getNewton(){
    Return Newton;
}
这里有大写字母,没有意义,应该是

double temperature::getNewton(){
     return newton; //you need to make this a member variable of your class too..
}

Temperature freezing(32);
您的温度类有一个小写的t,温度类不存在。 并且没有定义构造函数,所以不能在其中传递32

Freezing.setFahrenheit();
Freezing.setCelsius();

这两行引用了冻结,但您将变量冻结称为

@user3238772您在使用大写字母时也有很多错误,例如Double vs Double,冻结vs冻结等等。@user3238772您没有名为冻结的类,它叫做温度。@No,谢谢,我已经解决了这些问题。现在,在每次双温后,我都会收到以下错误消息。此处不允许在您可能想要签出的“{”标记之前使用函数定义,因为您确实需要对该语言有一些基本的了解。
Freezing.setFahrenheit();
Freezing.setCelsius();