gpt4 book ai didi

带有类错误消息的 C++ 温度计

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:57:25 27 4
gpt4 key购买 nike

我知道温度计的问题已经解决了,但我想我会试一试。

我不断收到错误消息“使用未声明的标识符‘converterc’”和“使用未声明的标识符‘converterf’”。有什么想法吗?

秒杀

 #include <iostream>
#include "converters.h"
using namespace std;

int main()
{
int degree;
int weehoo;

cout<<"\n\n\n\t\t Enter the temperature : ";
cin>>degree;
cout<<"\n\n\t\t If the temperature is in Celsius enter 0, if Farenheit enter 1 :";
cin>>weehoo;

if (weehoo==0)
{
cout<<"\n\n\t\tThe temperature in Farenheit is "<<converterc(degree,weehoo)<<endl;
}
else
{
cout<<"\n\n\t\tThe temperature in Celsius is "<<converterf(degree,weehoo)<<endl;
}
return 0;
}
#ifndef __again_converters_h
#define __again_converters_h
#endif
#pragma once

class Thermometer
{
private:
float degreeC; //celcius
float degreeF; //farenheit

public:
void setCelcius (float c) {degreeC=c;}
void setFarenheit (float f) {degreeF=f;}
float getCelcius (void){return degreeC;}
float getFarenheit (void){return degreeF;}
Thermometer (float degree=0,float f=0, float c=0,float outtemp=0);
float converterc(int degree,int weehoo);
float converterf(int degree,int weehoo);
};

转换器.cpp 文件 #include "converters.h"

 float Thermometer::converterf(int degree,int weehoo)
{
degreeC=((degree-32) * (.5556));
return degreeC ;

}
float Thermometer::converterc(int degree,int weehoo)
{
degreeF=((1.8)*degree)+32;
return degreeF;
}

最佳答案

convertercconverterf 是类 Thermometer 的成员函数,但您在没有 Thermometer 的情况下调用它们实例。

如何在您的 main 中创建一个 Thermometer 实例?

Thermometer tm;
tm.converterc(degree, weehoo);

关于带有类错误消息的 C++ 温度计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16391060/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com