20.3.21

Spring 2021 c++: hw-5

Create a OOP that counts the number of times a particular letter shows up in the word search. Count how many times it came in the string. Use Inheritance.

Examples

letterCounter([
  ["D", "E", "Y", "H", "A", "D"],
  ["C", "B", "Z", "Y", "J", "K"],
  ["D", "B", "C", "A", "M", "N"],
  ["F", "G", "G", "R", "S", "R"],
  ["V", "X", "H", "A", "S", "S"]
], "D") ➞ 3

// "D" shows up 3 times: twice in the first row, once in the third row.

letterCounter([
  ["D", "E", "Y", "H", "A", "D"],
  ["C", "B", "Z", "Y", "J", "K"],
  ["D", "B", "C", "A", "M", "N"],
  ["F", "G", "G", "R", "S", "R"],
  ["V", "X", "H", "A", "S", "S"]
], "H") ➞ 2

5 comments:

  1. #include
    using namespace std;
    class B
    {
    public:
    void check()
    {
    char searching = '\0';
    string sentence = " ";
    int counter = 1;
    cout<<"Enter a sentence: "<>searching;
    }
    };
    class B1: public B
    {
    public:
    int i;
    char searching = '\0';
    int counter = 1;
    string sentence = " ";
    int res()
    {
    for(i=0; i<=sentence.length();i++)
    {
    if(sentence[i]==searching)
    counter++;
    }
    cout<< " The letter " <<searching<< " appears " <<counter<< " times ";
    return 0;
    }

    };
    int main()
    {
    B1 obj;
    obj.check();
    obj.res();
    }

    ReplyDelete
  2. //Faizah Akter
    //202010061
    #include
    using namespace std;
    class B
    {
    public:
    void check()
    {
    char searching = '\0';
    string sentence = " ";
    int counter = 1;
    cout<<"Enter a sentence: "<>searching;
    }
    };
    class B1: public B
    {
    public:
    int i;
    char searching = '\0';
    int counter = 1;
    string sentence = " ";
    int res()
    {
    for(i=0; i<=sentence.length();i++)
    {
    if(sentence[i]==searching)
    counter++;
    }
    cout<< " The letter " <<searching<< " appears " <<counter<< " times ";
    return 0;
    }

    };
    int main()
    {
    B1 obj;
    obj.check();
    obj.res();
    }

    ReplyDelete
  3. Mahbubur rahman Limon
    id: 202030070

    #include
    using namespace std;
    class B
    {




    public:
    void check()
    {
    char searching = '\0';
    string sentence = " ";
    int counter = 1;
    cout<<"Enter a sentence: "<>searching;
    }
    };
    class B1: public B
    {
    public:
    int i;
    char searching = '\0';
    int counter = 1;
    string sentence = " ";
    int res()
    {
    for(i=0; i<=sentence.length();i++)
    {
    if(sentence[i]==searching)
    counter++;
    }
    cout<< " The letter " <<searching<< " appears " <<counter<< " times ";
    return 0;
    }

    };
    int main()
    {
    B1 obj;
    obj.check();
    obj.res();
    }

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Fariha sultana eity
    Id: 202010172

    #include
    using namespace std;
    class B
    {
    public:
    void check()
    {
    char searching = '\0';
    string sentence = " ";
    int counter = 1;
    cout<<"Enter a sentence: "<<searching;
    }
    };
    class B1: public B
    {
    public:
    int i;
    char searching = '\0';
    int counter = 1;
    string sentence = " ";
    int res()
    {
    for(i=0; i<=sentence.length();i++)
    {
    if(sentence[i]==searching)
    counter++;
    }
    cout<< " The letter " <<searching<< " appears " <<counter<< " times ";
    return 0;
    }

    };
    int main()
    {
    B1 obj;
    obj.check();
    obj.res();
    }

    ReplyDelete

Comment Here