Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. Вариант №1
  2.  
  3.  
  4. Задание №1.
  5. Заменить пробелами все гласные буквы;
  6.  
  7. Код программы:
  8.  
  9. #include <iostream>
  10. #include <fstream>
  11. #include <string>
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16.  
  17. string sym = "AaEeIiOoUuYyaАаЕеИиЁёОоУуЫыЭэЮюЯя", str;
  18. fstream inOut;
  19.  
  20. inOut.open("file.txt", ios::in); // Открываем файл для ввода
  21. if(!(inOut.is_open()))cout<<"File is not found";
  22. else
  23. {
  24. cout << "Enter string in English: ";
  25. getline(cin, str);
  26. string c = str;
  27.  
  28. inOut.close();
  29.  
  30. inOut.open("file.txt", ios::out); // открываем файл для вывода
  31.  
  32. for (int i = 0; i < str.size(); i++)
  33. {
  34. for (int j = 0; j < sym.size(); j++)
  35. {
  36. if (str[i] == sym[j]) str[i] = '_'; // если есть гласные , заменяем их на _
  37. }
  38. }
  39. inOut<<"Original string: "<<c<<endl;
  40. inOut<<"Your string after swap: "<< str ; //выводим слово после замены в файл
  41.  
  42. inOut.close();
  43. }
  44. cin.get();
  45. return 0;
  46.  
  47. }
  48.  
  49.  
  50.  
  51.  
  52. Результат программы :
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. Задание №2.
  82. Для встречающихся в заданном тексте пар рядом расположенных символов указать, сколько раз встречается каждое из таких двухбуквенных сочетаний.
  83.  
  84. Код программы:
  85. #include<stdio.h>
  86. #include<cstring>
  87. #include<conio.h>
  88. #include<iostream>
  89. #include<fstream>
  90. using namespace std;
  91.  
  92. int main()
  93. {
  94. char str[100], tmp[3]={'\0'}, *a=str, *b=str;
  95.  
  96. fstream inOut;
  97. inOut.open("file2.txt", ios::in);
  98. if(!(inOut.is_open()))cout<<"File is not found";
  99. else
  100. {
  101.  
  102. cout<<"Enter string: ";
  103. gets(str);
  104. string z=str;
  105. inOut.close();
  106.  
  107. inOut.open("file2.txt", ios::out);
  108.  
  109. unsigned k=0;
  110. inOut<<"Entered string: "<<z<<endl<<endl;
  111. for(a=str; a[1]; ++a)
  112. {
  113. strncpy(tmp, a, 2);
  114. if(strstr(str, tmp)<a) continue;
  115. for(b=str; b[1]; ++b)
  116. {
  117. if(!strncmp(a, b, 2)) ++k;
  118. }
  119. cout <<"Pair \""<<*a<<a[1]<<"\" encountered \""<<k<<"\" times\n";
  120. inOut <<"Pair \""<<*a<<a[1]<<"\" encountered \""<<k<<"\" times\n";
  121. k=0;
  122. }
  123. inOut.close();
  124. }
  125. return 0;
  126. }
  127.  
  128. Результат программы:
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159. Задание №3
  160. Поменять местами строки, содержащие минимальный и максимальный элементы. Ответ сохранить в тот же файл.
  161.  
  162. #include <iostream>
  163. #include <fstream>
  164. using namespace std;
  165. int main ()
  166. {
  167. int x[6][6],i,j,temp=0,temp1=0,min,max,buff;
  168. string z;
  169. string symb="#### Max and min in the same line ####";
  170. setlocale(LC_ALL,"Russian");
  171. ifstream f ("Text.txt");
  172. if(!(f.is_open()))
  173. cout<<"File is not found";
  174. else
  175. {
  176. //считываем матрицу
  177.  
  178. while (!f.eof())
  179. {
  180. for (i=0;i<6;i++)
  181. for (j=0;j<6;j++)
  182. f >>x[i][j];
  183. }
  184.  
  185. f.close();
  186. min = x[0][0];
  187. max = x[0][0];
  188. for(int i =0 ; i < 6;i++)
  189. {
  190. for(int j =0; j < 6;j++)
  191. {
  192. if(x[i][j] < min) {min=x[i][j];temp=i;}
  193. if(x[i][j] > max) {max=x[i][j];temp1=i;}
  194. }
  195. }
  196.  
  197. //меняем местами строки
  198. if(temp1==temp) z=symb;
  199. else
  200. {
  201. for (j=0;j<6;j++)
  202. {
  203. buff= x[temp][j];
  204. x[temp][j]= x[temp1][j];
  205. x[temp1][j]= buff;
  206. }
  207. }
  208.  
  209. ofstream f1 ("Text.txt",ios::app);
  210. //Запись новой матрицы в файл
  211. f1 << endl<< "New matrix:" << endl;
  212. f1 << endl << z << endl;
  213. for (int i=0;i<6;i++)
  214. {
  215. for (int j=0;j<6;j++)
  216. f1 << " "<<x[i][j];
  217. f1 << endl;
  218. }
  219. cout <<"Open file Text.txt";
  220. f1.close();
  221. }
  222. return 0;
  223.  
  224. }
  225.  
  226.  
  227. Результат программы:
  228.  
  229.  
  230. Результат программы, если мы изменим исходный файл с матрицей . Максимальный элемент находится в 6 строке число «16»
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement