使用类、私有、公共、构造函数、函数、整数和字符串进一步学习程序 在我的C++类中,我们被要求继续将不同的方面构建到这个代码中。我目前有两个错误,我不知道自己做错了什么。该程序将私家车或字符串作为名称和私家整数输入到游戏中,检查3、5和3&5的可除性。我将在类中使用get函数和put函数获取输入值并输出它们。我基本上已经弄明白了这个程序,但它不会编译,我真的不确定为什么。这是我的密码: #include <iostream> #include <iomanip> using namespace std; using std::istream; // declare the max size the username input can be const int MAX = 14; enum FIZZBUZZ { ABORT = 0, FIZZBUZZ, FIZZ, BUZZ }; class CFizzbuzz // Class definition at global scope { // make sure our constructor, destructor, plus member functions are // all public and available from outside of the class. public: CFizzbuzz() {} // Default constructor definition ~CFizzbuzz() {} // Default destructor definition // function members that are public // get the user's name and their value from the console and // store those results into the member variables. void getFizzbuzz() { cout << "Please enter your name: " << endl; cin >> m_myName; cout << "Please enter your number for the FizzBuzz game: " << endl; cin >> m_myNum; } // return the user's number type entered int putFizzBuzz() { return m_myNum; } char* getName() { return m_myName; } // logic to check to see if the user's number is 0, fizz, buzz, or fizzbuz int getRecord(int num) { if (num == 0) { return ABORT; } else if (num % 5 == 0 && num % 3 == 0) // fizzbuzz number { return FIZZBUZZ; } else if (num % 5 == 0) // buzz number { return BUZZ; } else if (num % 3 == 0) // fizz number { return FIZZ; } else return num; } // private data members only available inside the class private: int m_myNum; char m_myName[MAX]; }; int main() { CFizzbuzz myClass; cout << "Welcome to my Fizzbuzz game, you are to guess the location of a " << "number which if is divisible by 5 and 3 you will win with " << "the output of Fizzbuzz. " << endl; cout << "Please enter an integer value between 0 and 3 " << "representing the row location of the number for the game, " << "then press the Enter key: " << endl; for (;;) { myClass.getFizzbuzz(); int num = myClass.putFizzBuzz(); switch (myClass.getRecord(num)) { case ABORT: cout << myClass.getName() << "\nThank you for playing\n"; system("PAUSE"); return 0; // exit program case FIZZ: cout << "Sorry, " << myClass.getName() << ", number is a Fizz, please try again.\n"; break; case BUZZ: cout << "Sorry, " << myClass.getName() << ", number is a Buzz, please try again.\n"; break; case FIZZBUZZ: cout << "You win you got FizzBuzz!!!" << endl; break; default: cout << "Sorry, " << myClass.getName() << ", number is a not a Fizz, Buzz, or Fizzbuzz\nPlease try again.\n"; break; } } } #包括 #包括 使用名称空间std; 使用std::istream; //声明用户名输入的最大大小 常数int MAX=14; 枚举FIZZBUZZ{ABORT=0,FIZZBUZZ,FIZZ,BUZZ}; 类CFizzbuzz//全局范围内的类定义 { //确保我们的构造函数、析构函数和成员函数 //所有课程都是公开的,可以从课外获得。 公众: CFizzbuzz(){}//默认构造函数定义 ~CFizzbuzz(){}//默认析构函数定义 //公开的功能成员 //从控制台获取用户名及其值,然后 //将这些结果存储到成员变量中。 void getFizzbuzz() { 我的名字; 密苏里; } //返回输入的用户号码类型 int putFizzBuzz() { 返回m_myNum; } char*getName() { 返回m_myName; } //检查用户号码是否为0、fizz、buzz或fizzbuz的逻辑 int getRecord(int num) { 如果(num==0) { 返回中止; } else if(num%5==0&&num%3==0)//fizzbuzz number { 返回嘶嘶声; } 如果(num%5==0)//则为else { 返回嗡嗡声; } else如果(num%3==0)//气泡数 { 回音嘶嘶; } 其他的 返回num; } //私有数据成员仅在类内可用 私人: int m_myNum; 字符m_myName[MAX]; }; int main() { CFizzbuzz myClass; 根据您在注释中提到的错误(未解析的外部符号_WinMain@16)我想说,您在Visual Studio中创建了一个Win32项目(GUI项目),但您的代码应该是一个控制台应用程序

使用类、私有、公共、构造函数、函数、整数和字符串进一步学习程序 在我的C++类中,我们被要求继续将不同的方面构建到这个代码中。我目前有两个错误,我不知道自己做错了什么。该程序将私家车或字符串作为名称和私家整数输入到游戏中,检查3、5和3&5的可除性。我将在类中使用get函数和put函数获取输入值并输出它们。我基本上已经弄明白了这个程序,但它不会编译,我真的不确定为什么。这是我的密码: #include <iostream> #include <iomanip> using namespace std; using std::istream; // declare the max size the username input can be const int MAX = 14; enum FIZZBUZZ { ABORT = 0, FIZZBUZZ, FIZZ, BUZZ }; class CFizzbuzz // Class definition at global scope { // make sure our constructor, destructor, plus member functions are // all public and available from outside of the class. public: CFizzbuzz() {} // Default constructor definition ~CFizzbuzz() {} // Default destructor definition // function members that are public // get the user's name and their value from the console and // store those results into the member variables. void getFizzbuzz() { cout << "Please enter your name: " << endl; cin >> m_myName; cout << "Please enter your number for the FizzBuzz game: " << endl; cin >> m_myNum; } // return the user's number type entered int putFizzBuzz() { return m_myNum; } char* getName() { return m_myName; } // logic to check to see if the user's number is 0, fizz, buzz, or fizzbuz int getRecord(int num) { if (num == 0) { return ABORT; } else if (num % 5 == 0 && num % 3 == 0) // fizzbuzz number { return FIZZBUZZ; } else if (num % 5 == 0) // buzz number { return BUZZ; } else if (num % 3 == 0) // fizz number { return FIZZ; } else return num; } // private data members only available inside the class private: int m_myNum; char m_myName[MAX]; }; int main() { CFizzbuzz myClass; cout << "Welcome to my Fizzbuzz game, you are to guess the location of a " << "number which if is divisible by 5 and 3 you will win with " << "the output of Fizzbuzz. " << endl; cout << "Please enter an integer value between 0 and 3 " << "representing the row location of the number for the game, " << "then press the Enter key: " << endl; for (;;) { myClass.getFizzbuzz(); int num = myClass.putFizzBuzz(); switch (myClass.getRecord(num)) { case ABORT: cout << myClass.getName() << "\nThank you for playing\n"; system("PAUSE"); return 0; // exit program case FIZZ: cout << "Sorry, " << myClass.getName() << ", number is a Fizz, please try again.\n"; break; case BUZZ: cout << "Sorry, " << myClass.getName() << ", number is a Buzz, please try again.\n"; break; case FIZZBUZZ: cout << "You win you got FizzBuzz!!!" << endl; break; default: cout << "Sorry, " << myClass.getName() << ", number is a not a Fizz, Buzz, or Fizzbuzz\nPlease try again.\n"; break; } } } #包括 #包括 使用名称空间std; 使用std::istream; //声明用户名输入的最大大小 常数int MAX=14; 枚举FIZZBUZZ{ABORT=0,FIZZBUZZ,FIZZ,BUZZ}; 类CFizzbuzz//全局范围内的类定义 { //确保我们的构造函数、析构函数和成员函数 //所有课程都是公开的,可以从课外获得。 公众: CFizzbuzz(){}//默认构造函数定义 ~CFizzbuzz(){}//默认析构函数定义 //公开的功能成员 //从控制台获取用户名及其值,然后 //将这些结果存储到成员变量中。 void getFizzbuzz() { 我的名字; 密苏里; } //返回输入的用户号码类型 int putFizzBuzz() { 返回m_myNum; } char*getName() { 返回m_myName; } //检查用户号码是否为0、fizz、buzz或fizzbuz的逻辑 int getRecord(int num) { 如果(num==0) { 返回中止; } else if(num%5==0&&num%3==0)//fizzbuzz number { 返回嘶嘶声; } 如果(num%5==0)//则为else { 返回嗡嗡声; } else如果(num%3==0)//气泡数 { 回音嘶嘶; } 其他的 返回num; } //私有数据成员仅在类内可用 私人: int m_myNum; 字符m_myName[MAX]; }; int main() { CFizzbuzz myClass; 根据您在注释中提到的错误(未解析的外部符号_WinMain@16)我想说,您在Visual Studio中创建了一个Win32项目(GUI项目),但您的代码应该是一个控制台应用程序,c++,function,class,enums,private-members,C++,Function,Class,Enums,Private Members,您需要通过重新创建或在项目设置中将子系统从Windows更改为控制台,将项目类型从Win32应用程序更改为控制台应用程序。有关后者的详细信息,请参阅以下链接: 基于您在注释中提到的错误(未解析的外部符号_WinMain@16)我想说,您在Visual Studio中创建了一个Win32项目(GUI项目),但您的代码应该是一个控制台应用程序 您需要通过重新创建或在项目设置中将子系统从Windows更改为控制台,将项目类型从Win32应用程序更改为控制台应用程序。有关后者的详细信息,请参阅以下链接:

您需要通过重新创建或在项目设置中将子系统从Windows更改为控制台,将项目类型从Win32应用程序更改为控制台应用程序。有关后者的详细信息,请参阅以下链接:


基于您在注释中提到的错误(
未解析的外部符号_WinMain@16
)我想说,您在Visual Studio中创建了一个Win32项目(GUI项目),但您的代码应该是一个控制台应用程序

您需要通过重新创建或在项目设置中将子系统从Windows更改为控制台,将项目类型从Win32应用程序更改为控制台应用程序。有关后者的详细信息,请参阅以下链接:


我会怀疑else return num。当您输入1或2时会发生什么?显然,模数不提供嘶嘶声或嗡嗡声,但根据您的枚举值,函数getRecord()会返回它所提供的值。我会将NONE enum值设置为-1,以指示它既不是嘶嘶声也不是嗡嗡声

要记住的是,枚举值在编译时解析为一个实际的数字。因此,当您输入1,并且模数不能证明是fizz、buzz或fizzbuzz,而您返回1时,switch case语句将解析为fizzbuzz,即使情况并非如此(双关语)


如果您评论它没有按预期工作,请输入更多详细信息。

我会怀疑else return num。当您输入1或2时会发生什么情况?显然,模数没有发出嘶嘶声或嗡嗡声,但基于您的枚举值,函数getRecord()会出现这种情况返回它的值。我会将NONE枚举值设置为-1,以指示它既不是嘶嘶声也不是嗡嗡声

要记住的是,枚举值在编译时解析为一个实际的数字。因此,当您输入1,并且模数不能证明是fizz、buzz或fizzbuzz,而您返回1时,switch case语句将解析为fizzbuzz,即使情况并非如此(双关语)


如果您评论它没有按预期工作,请输入更多详细信息。

您能提供更具体的错误吗?请提供描述您的错误的行,而不是LNK2019和LNK1120。您还说您有9个错误。如果是这样,那么您的其他7个错误是什么?只有两个错误。我之前有9个错误错误读取:未解析的外部符号_WinMain@16在函数“int_cdecl invoke_main(void)”中引用(?invoke_main@@YAHXZ)第二个错误是1个未解决的外部错误。这应该可以解决你的问题。你能提供更具体的错误吗?提供描述你的错误的行,而不是LNK2019和LNK1120。你还说你有9个错误。如果是这样,那么你的其他7个错误是什么?只有两个错误。我以前有9个错误。错误是d:未解析的外部符号_WinMain@16在函数“int_cdecl invoke_main(void)”中引用(?invoke_main@@YAHXZ)第二个错误是1个未解决的外部问题。这应该可以解决您的问题。这解决了问题。它似乎永远不想结束,并不断重复修复它。它似乎永远不想结束,但却不断重复