我明天有測試,作爲測試的「指南」,下面有個問題,我已經寫下了我的解決方案,但不知道我是否在做問題在問什麼?謝謝您的幫助!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