我明天有测试,作为测试的“指南”,下面有个问题,我已经写下了我的解决方案,但不知道我是否在做问题在问什么?谢谢您的帮助!C++程序 - 不确定是否我提供了正确的解决方案
收件交互式C++程序,从用户的格式输入一个名字:
last, first middle
然后程序应输出 名称中的格式:
first middle last
程序 将不得不使用字符串操作来从姓氏的末尾 中删除逗号。
这里是我的解决方案:
#include <iostream>
#include <string>
using namespace std;
const string FIRST = "David";
const string LAST = "Moshons";
const string MIDDLE = "Matthew";
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;
}
这是否解决方案完成什么的问题是问?有些人在我的课上遇到麻烦,看起来这个解决方案太简单了?感谢所有的帮助。
它说要从用户输入名称。您已将其硬编码到程序中。 – chris 2013-02-11 00:55:06
而你不是“使用字符串操作来删除逗号”。 – 2013-02-11 00:55:55
不仅输入需要来自用户(大概是单个字符串),在姓氏后面需要逗号。 – chrisaycock 2013-02-11 00:56:09