C++程序-不确定是否,我提供了正确的解决方案

C++ Program- Not sure if, I am providing the right solution

本文关键字:解决方案 程序 不确定 是否 C++      更新时间:2023-10-16

我明天有一个测试,作为"导向器";对于测试,下面有一个问题,我已经写下了我的解决方案,但不确定我是否在做这个问题所问的?谢谢你的帮助!

编写一个交互式C++程序,以格式输入用户的名称

last, first middle

然后程序应输出名称格式为:

first middle last   

程序将不得不使用字符串操作从末尾删除逗号的姓氏。

这是我的解决方案:

#include <iostream>
#include <string> 

using namespace std;
const string FIRST = "Firstname";
const string LAST = "Middlename";
const string  MIDDLE = "Lastname";
int main()
{
string firstLast;
string lastFirst;
firstLast = LAST + ", " + FIRST + " " + MIDDLE;
cout << "Name in first-last format is " << firstLast << endl;
lastFirst = FIRST + " " + MIDDLE + " " + LAST;
cout << " Name is last-First format is " << lastFirst << endl;

system("PAUSE");
return 0;

 }

这个解决方案是否完成了问题的要求?有些人在我的课堂上遇到了麻烦,这个解决方案似乎太容易了?谢谢你的帮助。

这个解决方案是否完成了问题的要求?

没有。

正在分部分检查试题。。。

编写一个交互式C++程序

您的程序不是交互式的。没有与用户的交互。它立即运行到完成。

last, first middle 格式从用户输入名称

你的程序不能做到这一点。它应该允许用户键入last, first middle或该格式的任何名称。

然后程序应在格式:

first middle last

你的程序不能做到这一点。

或者,更准确地说,它输出18个单词而不是3个,但其中3个是程序应该输出的3个单词

程序将不得不使用字符串操作来删除姓氏末尾的逗号。

你的程序不能做到这一点。没有任何代码可以从任何位置删除逗号。

我推荐:

  • 阅读std::cin
  • 阅读std::string成员函数
  • 咖啡,如果可能的话。你还没有为这次考试做好准备
相关文章: