Help with class!

This assignment I'm working on is to make a histogram that finds how many times each letter is displayed.
This is my homework assignment so I am not looking for answers! I just needed help on how I can make my class read the "cin >> s;" in the driver.

Histogram h;

string s;
cout << "Enter Data:"
cin >> s; /*How would I make the string s go to h.acceptString?*/

h.acceptString( );

cout << h << endl;

h.reset( );

char * cstr = "Hello";

h.acceptCString( cstr );

cout << h << endl;


for example, what would I put for my h.acceptString(); function that I have in the histogram class
Last edited on
Hello. Please use code tags for all your code - http://www.cplusplus.com/articles/jEywvCM9/

You would pass it, that's how functions work.

1
2
3
4
5
string s;
cout << "Enter Data:"
cin >> s; 

h.acceptString(s);


Your acceptString function would have to adapt so it takes a string. And depending on what you want to do with the string, like for example change it and return back a string, you make the function a string function.

1
2
3
4
5
6
string acceptString(string s) // takes a string called s as parameter
{
    // do shit with the string

   return s; // return it.
}


If you then want it back in main, you could for example do.

string comeBack = h.acceptString(s);

You can find tons of videos and info on the googles about functions and classes. Here is two playlists -

https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83
https://www.youtube.com/playlist?list=PL2DD6A625AD033D36
Topic archived. No new replies allowed.