I am new here and this is my first post so I'm sorry if anything in this post is done incorrectly. I have taken a C++ class but did not get into any object oriented parts of it (all linear). Now I am in an object oriented class which is focused through C++ and everything seems totally different and I am lost. I need to do an assignment where a string posts and each letter is counted and put into an array as pairs (char, # of occurrence). Then print the array to show how many times each letter was used. I am so lost I do not have any code yet. I have some starter code the professor gave us. Can anyone help me? It will be greatly appreciated.
//cis 326 (OOP I) - Week 2 Programming Assignment Starter Code
#include <iostream>
#include <iomanip>
using namespace std;
// an object to count occurance of a given character
class char_count
{
public:
char_count(char val):char_2count(tolower(val)), count(0){}; //ctor
void add_ifMatch(char c)
{
if (tolower(c) == char_2count ) count ++;
};
void print_count()
{
cout << "chars '" << char_2count << "|" << (char)toupper(char_2count)
<< "' occured " << std::setw(4) << count << " times.\n";
};
private:
int count;
char char_2count;
};
// "Classes have the property of information hiding. This means that although class objects may know how to communicate with one another across well-defined interfaces, classes normally are not allowed to know how other classes is implemented-implementation details are hidden within the classes themselves. Surely it is possible to drive a car effectively without knowing the details of how engines, transmissions and exhaust systems work internally. We will see why information hiding is so crucial to good software engineering."
int main()
{
char_count c_cnt( 'a' );
char c; // loop until user types end-of-file key sequence
while ( ( c = cin.get() ) != EOF )
c_cnt.add_ifMatch(c);
c_cnt.print_count();
system("pause");
return 0;
}