【发布时间】:2014-01-28 04:02:46
【问题描述】:
大家好,我想我真的很亲密,但我不太确定如何继续。所有与我的问题相关的问题都没有真正回答任何问题。我现在遇到的错误是
(33): error C2064: term does not evaluate to a function taking 1 arguments
(41): error C2064: term does not evaluate to a function taking 1 arguments
头文件:
using namespace std;
class romanType
{
public:
void printRoman(char romanNum);
int printDecimal(int& total);
int convertRoman(int& total);
void setRoman(char& roman);
romanType();
romanType(char);
private:
char romanNum[6];
int decimal;
int total;
};
实施:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include "romanType.h"
using namespace std;
romanType::romanType(char)
{
};
void romanType::printRoman(char romanNum)
{
cout << "Here is your number in Roman Numeral form: " << romanNum << endl;
};
int romanType::printDecimal(int& total)
{
cout << "Here is your number in Decimal form: " << total << endl;
return total;
};
void romanType::setRoman(char& romanNum)
{
};
int romanType::convertRoman(int& total)
{
int len = 0;
len = strlen(romanNum);
int count[1];
for(int i = 0; i < len; i++)
{
switch(romanNum[i])
{
case 'M':
count[i] = 1000;
break;
case 'm':
count[i] = 1000;
break;
case 'D':
count[i] = 500;
break;
case 'd':
count[i] = 500;
break;
case 'C':
count[i] = 100;
break;
case 'c':
count[i] = 100;
break;
case 'L':
count[i] = 50;
break;
case 'l':
count[i] = 50;
break;
case 'X':
count[i] = 10;
break;
case 'x':
count[i] = 10;
break;
case 'V':
count[i] = 5;
break;
case 'v':
count[i] = 5;
break;
case 'I':
count[i] = 1;
break;
case 'i':
count[i] = 1;
break;
default:
cout << "Error.." << endl;
}
total = total + count[0];
}
return total;
};
我的主要:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include "romanType.h"
using namespace std;
int main()
{
romanType r;
char romanNum;
char choice;
int decimal;
int total;
cout << "Hello! Please enter your Roman Numeral: " << endl;
cin >> romanNum;
cout << endl;
r.setRoman(romanNum);
r.convertRoman(total);
cout << "Do you want the Roman Numeral or the Decimal?" << endl;
cout << "Press [D] for Decimal!" << endl << "Press [R] for Roman Numeral!" << endl;
cin >> choice;
if (choice == 'D' || choice == 'd')
r.printDecimal(total);
else if (choice == 'R' || choice == 'r')
r.printRoman(romanNum);
else
cout << "That wasn't the right button!" << endl;
system ("pause");
return 0;
}
我很确定我在正确的轨道上。很高兴看到与我的错误有关的任何提示或建议。
提前致谢
【问题讨论】:
-
第 33 行和第 41 行是什么?
-
顺便说一句,问题是编写一个程序,将罗马数字输入的数字转换为十进制。需要包含一个名为 romanType 的类和一个执行以下操作的对象: 将数字存储为罗马数字 将数字转换并存储为十进制形式 将数字打印为罗马数字或用户请求的十进制数字 的十进制值罗马数字是:M = 1000 D = 500 C = 100 L = 50 X = 10 V = 5 I = 1
-
r.convertRoman(total);和 r.printDecimal(total);
-
罗马数字是逆累加的。您从 右 端开始,添加值,只要它们的值增加或相等,然后在遇到 较小的数字时从该累积值中减去 i> 比前一个数字。
-
此外,您所描述的症状表明您的代码使用 不同 标头而不是您在此处显示的标头进行编译。可能是旧副本,或者您在编译之前更新文件后没有保存文件。此外,您声明但从未定义
romanType::romanType()构造函数。它在头文件中,但在实现文件中没有。
标签: c++ decimal roman-numerals