C++程序-不确定是否,我提供了正确的解决方案
C++ Program- Not sure if, I am providing the right solution
我明天有一个测试,作为"导向器";对于测试,下面有一个问题,我已经写下了我的解决方案,但不确定我是否在做这个问题所问的?谢谢你的帮助!
编写一个交互式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
成员函数 - 咖啡,如果可能的话。你还没有为这次考试做好准备
相关文章:
- 最大的回文产品 - 程序未运行,编写解决方案但无法理解问题
- 如何在程序中实现单词跳过解决方案
- 如何计算该程序的复杂性?是否有任何其他复杂性较低的解决方案
- MPI在某个进程找到解决方案时使用广播结束程序
- 如何将解决方案中的项目从应用程序更改为静态库
- 更新的程序仍然崩溃,似乎找不到解决方案?
- 只有当我一直显示某些内容直到找到解决方案时,程序才能工作
- 商业申请许可问题和LIBPCAP应用程序的解决方案
- 一个解决方案,两个项目:如何从 Windows 应用程序调用控制台项目?C++
- 简单程序没有输出和崩溃.我的解决方案有什么问题
- 在一个应用程序中MPI_Scatter和MPI_Bcast解决方案。如何让分区打印分区大小
- 将类从应用程序解决方案移动到静态库解决方案会产生无法解决的外部符号链接错误
- 找不到 C++ 程序的解决方案
- 为什么通过系统("color YX")更改控制台应用程序中C++颜色不是最佳解决方案?
- 拥有一个包含MFC项目和用于单元测试的控制台应用程序的解决方案
- QLineEdit:是否有一个优雅的解决方案来告诉多个QLineEdit部件分开事件处理程序
- QT是我的跨平台应用程序的正确解决方案吗?
- TeamCity使用c++项目构建VS2012解决方案,其中包含设备驱动程序无法清理目录
- C++程序-不确定是否,我提供了正确的解决方案
- ConsoleApplication4.exe已停止工作.Windows将关闭该程序并通知是否有可用的解决方案