Переводчик с английского на русский и обратно - C#

Узнай цену своей работы

Формулировка задачи:

Помогите, пожалуйста. Требуется разработать приложение - переводчик с английского на русский и обратно. Словарь с переводом должен загружаться из файла. У пользователя 2 действия: перевести англ. текст или перевести рус. текст. Все вводится с консоли.
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. namespace Курсовая
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] ruText = new string[File.ReadAllLines("ru.txt").Length];
  14. string[] engText = new string[File.ReadAllLines("eng.txt").Length];
  15. string n = Console.ReadLine();
  16. string[] mas1 = n.Split();
  17. StreamWriter SW= new StreamWriter(new FileStream("VvodRus.txt",FileMode.Create, FileAccess.ReadWrite));
  18. for (int i = 0; i < mas1.Length; i++)
  19. {
  20. SW.WriteLine(mas1[i]);
  21. }
  22. SW.Close();
  23. string[] rus = new string[File.ReadAllLines("VvodRus.txt").Length];
  24. /* for (int i = 0; i < ruText.Length; i++)
  25. {
  26. rus[i] = File.ReadAllLines("VvodRus.txt")[i];
  27. ruText[i] = File.ReadAllLines("ru.txt")[i];
  28. if (rus[i].Equals(StringComparison.CurrentCultureIgnoreCase))
  29. {
  30. Console.WriteLine(ruText[i]);
  31. return;
  32. }
  33. }*/
  34. }
  35. }
  36. }

Решение задачи: «Переводчик с английского на русский и обратно»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace ConsoleApplication4
  9. {
  10.     class Program
  11.     {
  12.        
  13.  
  14.         static void Main(string[] args)
  15.         {
  16.             Translator enru = new Translator(1);
  17.             string text = "I do not understand";
  18.             Console.WriteLine(text);
  19.             Console.WriteLine(enru.Translate(text));
  20.             Console.WriteLine();
  21.             Translator ruen = new Translator(2);
  22.             string text2 = "я делать не понимать";
  23.             Console.WriteLine(text2);
  24.             Console.WriteLine(ruen.Translate(text2));
  25.             Console.ReadKey();
  26.         }
  27.     }
  28.  
  29.     class Translator
  30.     {
  31.         Dictionary<string, string> dict=new Dictionary<string,string>();
  32.         public Translator(int direction) //конструктор, в котором заполняется словарь из файла
  33.         {
  34.             string[] dictionary = File.ReadAllLines(@"d:\Dictionary.txt", Encoding.Default);
  35.             foreach (string line in dictionary)
  36.             {
  37.                 string[] words = line.Split(' ');
  38.                 if (direction==1)
  39.                     dict.Add(words[0], words[1]);
  40.                 else
  41.                     dict.Add(words[1], words[0]);
  42.             }
  43.         }
  44.         public string Translate(string text) //метод перевода
  45.         {
  46.             string[] textArray = text.Split(' ');
  47.             string result = string.Empty;
  48.             foreach (string word in textArray)
  49.             {
  50.                 if (dict.ContainsKey(word))
  51.                     result += dict[word] + " ";
  52.                 else
  53.                     result += "<???> "; //если нет в словаре
  54.             }
  55.             return result;
  56.         }
  57.     }
  58. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 4.25 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы