我必須用C++編寫一個程序,我之前沒有使用過這個laugauge。讀取文件並以特定格式打印。 C++
我知道如何用Java或C#編寫它,但我應該用C++編寫它!
代碼應該讀取文本文件(I做到這一步),然後使用陣列打印輸出以特定格式(我不現在如何執行此步驟)
例如: 的文件有以下:
Task distribution duration dependence
A Normal 2,10 -
B UNIF 2,7 A
該代碼將打印以下:
任務A是正態分佈,其持續時間是它不依賴於任何任務2和10之間。任務B是互可操作性框架配送等
我想提一提,它不是一個家庭作業或作業提交給老師,但我在一個研究項目工作(額外的東西去學習新的東西之前離開大學),他們要求我們使用我發現很難學習的C++(我有其他的課程,我應該考慮而不是進行研究)。
我在C#中編寫代碼,並且搜索將C#轉換爲C++的實用程序,但它不起作用!
http://www.tangiblesoftwaresolutions.com/Product_Details/Instant_CPlusPlus_CSharp_Edition.html
這是我在C#代碼和它工作正常。
class Program
{
static List<string []> allTasks = new List<string []>();
static List<TaskInfo> Tasks = new List<TaskInfo>();
static void Main(string[] args)
{
string line;
string[] info = null;
StreamReader sr = new StreamReader("C:\\Users\\7bah Jno0ney\\Documents\\Visual Studio 2008\\Projects\\Example1_C++\\Tasks.txt");
string fLine = sr.ReadLine();
while ((line = sr.ReadLine()) != null)
{
line = line.Replace("\r", "");
info = line.Split(' ');
allTasks.Add(info);
}
for (int i = 0; i < allTasks.Count; i++)
{
for (int j = 0; j < allTasks[i].Length; j++)
{
allTasks[i][j] = allTasks[i][j].Replace("\r", "");
allTasks[i][j] = allTasks[i][j].Replace(" ", "");
}
TaskInfo task = new TaskInfo(allTasks[i][0], allTasks[i][1], allTasks[i][2], allTasks[i][3]);
Tasks.Add(task);
}
Console.WriteLine("You have " + Tasks.Count + " Tasks.");
Console.WriteLine();
for (int i = 0; i < Tasks.Count; i++)
{
if (Tasks[i].getTaskDep() == null || Tasks[i].getTaskDep() == "-")
{
Console.WriteLine("The first task in the project is the task " + Tasks[i].getTaskName() +". " +
"The task distribution is " + Tasks[i].getTaskDis() + " and its duration is " + Tasks[i].getTaskDur() + "." + " Finally, it doesn't has any dependence");
Console.WriteLine();
}
else
{
string name = Tasks[i].getTaskName();
string dep = Tasks[i].getTaskDep();
if(dep.Contains(","))
{
string[] depends = dep.Split(',');
Console.Write("Task " + Tasks[i].getTaskName() + " has " + Tasks[i].getTaskDis() +
" distribution and its duration is " + Tasks[i].getTaskDur() + ". ");
Console.Write("This task depends on " + depends.Length + " tasks.");
for (int d = 0; d < depends.Length; d++)
{
int num = d + 1;
Console.Write(" The " + num + " depended task is " + depends[d] + ". ");
}
Console.WriteLine();
Console.WriteLine();
}
else
{
foreach (TaskInfo ti in Tasks)
{
if((ti.getTaskName() == name) && (ti.getTaskDep() == dep)){
Console.WriteLine("This Task is the " + i +
" task and its distribution is " + Tasks[i].getTaskDis() +
". It is duration is " + Tasks[i].getTaskDur() +
" and it depends on the task " + ti.getTaskDep());
Console.WriteLine();
}
}
}
}
}
}
}
什麼是一些實用程序或程序來幫助轉換代碼?
你可以發佈你的C#代碼,然後有人可以幫助你將其轉換爲C++ – 2010-05-14 10:54:52
通過說「我這一步」你的意思是你有代碼寫這樣做?如果是的話,你可以在你的問題中包含該代碼?附:請刪除「特定」標籤,這沒有意義。 – 2010-05-14 11:06:23