Advertisement
Sonita

Untitled

Apr 26th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include "stdafx.h"
  4. #include <stdio.h>
  5. #include <conio.h>
  6. #include <string.h>
  7. #include <iostream>
  8. using namespace std;
  9. class Slovo {
  10. private:
  11. char *Name;
  12. int len;
  13. public:
  14. Slovo() {
  15. puts("Конструктор по умолчанию.");
  16. Name = NULL;
  17. len = 0;
  18. }
  19. Slovo(char *aslovo) {
  20. puts("Конструктор инициализирующий с параметрами.");
  21. SetName(aslovo);
  22. }
  23. ~Slovo() {
  24. puts("Деструктор Slovo.");
  25. delete[]Name;
  26. }
  27. void SetName(char *aslovo) {
  28. len = strlen(aslovo);
  29. if (Name != NULL)delete[]Name;
  30. Name = new char[len + 1];
  31. strcpy(Name, aslovo);
  32. }
  33. char *getName() {
  34. return Name;
  35. }
  36. int getLen() {
  37. return len;
  38. }
  39. void Print() {
  40. puts("Сведения об объекте:");
  41. cout << "Слово: " << getName() <<" ."<< endl;
  42. cout << "Длина слова: " << getLen() << " ." << endl;
  43. }
  44. int counter(char c1);
  45. };
  46. int Slovo::counter(char c1) {
  47. int cnt = 0;
  48. for (int i = 0; i < len; i++) {
  49. if (c1 == Name[i])
  50. cnt++;
  51. }
  52. return cnt;
  53. }
  54. void main()
  55. {
  56. char c;
  57. char *st;
  58. int n;
  59. setlocale(0, "russian");
  60. Slovo B;
  61. cout << "Введите слово." << endl;
  62. cin >> st;
  63. B.SetName(st);
  64. cout << "Введённые данные:" << endl;
  65. B.Print();
  66. cout << "Введите букву" << endl;
  67. cin >> c;
  68. cout << "Количество букв " << c << " в слове " << B.getName() << " = " << B.counter(c) << "." << endl;;
  69. cout << "Введите количество слов." << endl;
  70. cin >> n;
  71. Slovo C[30];
  72. for (int j = 1; j < n + 1; j++) {
  73. cout << "Введите " << j << " слово массива и его длину." << endl;
  74. cin >> st;
  75. C[j].SetName(st);
  76. cout << "Введённые данные:" << endl;
  77. C[j].Print();
  78. cout << "Введите букву" << endl;
  79. cin >> c;
  80. cout << "Количество букв " << c << " в слове " << C[j].getName() << " = " << C[j].counter(c) << "." << endl;;
  81. }
  82. _getch();
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement