Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "stdafx.h"
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <iostream>
- using namespace std;
- class Slovo {
- private:
- char *Name;
- int len;
- public:
- Slovo() {
- puts("Конструктор по умолчанию.");
- Name = NULL;
- len = 0;
- }
- Slovo(char *aslovo) {
- puts("Конструктор инициализирующий с параметрами.");
- SetName(aslovo);
- }
- ~Slovo() {
- puts("Деструктор Slovo.");
- delete[]Name;
- }
- void SetName(char *aslovo) {
- len = strlen(aslovo);
- if (Name != NULL)delete[]Name;
- Name = new char[len + 1];
- strcpy(Name, aslovo);
- }
- char *getName() {
- return Name;
- }
- int getLen() {
- return len;
- }
- void Print() {
- puts("Сведения об объекте:");
- cout << "Слово: " << getName() <<" ."<< endl;
- cout << "Длина слова: " << getLen() << " ." << endl;
- }
- int counter(char c1);
- };
- int Slovo::counter(char c1) {
- int cnt = 0;
- for (int i = 0; i < len; i++) {
- if (c1 == Name[i])
- cnt++;
- }
- return cnt;
- }
- void main()
- {
- char c;
- char *st;
- int n;
- setlocale(0, "russian");
- Slovo B;
- cout << "Введите слово." << endl;
- cin >> st;
- B.SetName(st);
- cout << "Введённые данные:" << endl;
- B.Print();
- cout << "Введите букву" << endl;
- cin >> c;
- cout << "Количество букв " << c << " в слове " << B.getName() << " = " << B.counter(c) << "." << endl;;
- cout << "Введите количество слов." << endl;
- cin >> n;
- Slovo C[30];
- for (int j = 1; j < n + 1; j++) {
- cout << "Введите " << j << " слово массива и его длину." << endl;
- cin >> st;
- C[j].SetName(st);
- cout << "Введённые данные:" << endl;
- C[j].Print();
- cout << "Введите букву" << endl;
- cin >> c;
- cout << "Количество букв " << c << " в слове " << C[j].getName() << " = " << C[j].counter(c) << "." << endl;;
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement