我正在编写这个基本程序并且被卡住了。我是 C++ 新手。我的程序必须 为各种罪行计算罚款。它将通过以下方式实现:
用户将输入实际速度、限速、违法行为是否发生在工作区/住宅区/以及法庭费用
显示票的总金额
提示用户是否希望输入另一张票或退出
这是预期输出的示例:
超速
罚款:超过限速每英里 5 美元加上法庭费用超速高速公路工作区
罚款:超过限速每英里 6 美元,另加法庭费用在住宅区超速
罚款:超过限速每英里 7 美元外加 200 美元外加法庭费用
这是代码:
#include <iostream>
class FineCalculator
{
public:
~FineCalculator() {}
FineCalculator(int courtFees);
int getFine(int zone, int speedLimit, int actualSpeed) const;
private:
int courtFees;
int balance;
};
FineCalculator::FineCalculator(int courtFees)
{
//return courtFees;
}
int getFine(int zone, int speedLimit, int actualSpeed)
{
//define IF you are speeding or not
if (actualSpeed > speedLimit)
{
/* define speeding zones
1. Regular
2. Highway
3. Residential
*/
if (zone==1)
{
int balanceCounter=actualSpeed-speedLimit;
//balance=courtfees+(loopcounter*5)
//balance
}
}
return 0;
}
int main()
{
int courtFee=0;
int inputFee=0;
int accumulator=0;
int programLooper=1;
int speedLimitz=0;
int vechicleSpeed=0;
std::cout<<"Please enter the court fee $";
std::cin >>courtFee;
FineCalculator fine1(courtFee);
while (programLooper !=0)
{
//1 for regular, 2 for highway, 3 for residential
//loop selection of offenses
std::cout<<"Please make numerical ticket selection for where the offense occured: \n";
std::cout<<"1. Regular \n";
std::cout<<"2. Highway \n";
std::cout<<"3. Residential \n";
std::cin >>programLooper;
std::cout<<"\n \n \n";
std::cout<<"Please Enter the speed limit \n";
std::cin >>speedLimitz;
std::cout<<"\n \n \n";
std::cout<<"Please Enter the vechile speed \n";
std::cin >>vechicleSpeed;
fine1.getFine(programLooper,speedLimitz,vechicleSpeed);
}
if (programLooper==0)
{
//end program loop
return (0);
}
}
对于该FineCalculator::FineCalculator(int courtFees)
方法的初学者,我不确定在 return 中输入什么,因为 return 之后我输入的任何内容都会出错。
同样在fine1.getFine(programLooper,speedLimitz,vechicleSpeed);
我收到一个错误消息:
Error 2 error LNK1120: 1 unresolved externals
Error 1 error LNK2019: unresolved external symbol "public: int __thiscall FineCalculator::getFine(int,int,int)const " (?getFine@FineCalculator@@QBEHHHH@Z) referenced in function _main
这里发生了什么?我完全被难住了。