Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (christos):

C++, http://screencast.com/t/w4bwKnGYBCCK Do you understand the second half of this exercise ? I am very confused I have to say. that's my code but this is just the first half of the problem: http://pastebin.com/WnqLDsaM

OpenStudy (christos):

@zepdrix

zepdrix (zepdrix):

Hmm I just started taking C++ this semester c: So I'm not sure my understanding of the subject is great just yet. Imma get some food, then I'll stare at the problem for a little bit. :3

OpenStudy (christos):

ok man its np :D

ganeshie8 (ganeshie8):

you must have 26 counters for 26 alphabets, incrementing the counter when that corresponding alphabet is enetered

OpenStudy (christos):

I have to declare 26 counters ??

ganeshie8 (ganeshie8):

its up to you how u implement it

ganeshie8 (ganeshie8):

let me show u an example, input/output

OpenStudy (christos):

ok

ganeshie8 (ganeshie8):

input ``` afjldksjflakjfljasdlfjalkdfjklkasdjflksdjlfjds. ```

ganeshie8 (ganeshie8):

output : ``` alphabet counts : a : 4, s : 5, d : 12, f : 3 g : 1, h : 2, l : 2, k : 2 overall character string : afjldksjflakjfljasdlfjalkdfjklkasdjflksdjlfjds ```

ganeshie8 (ganeshie8):

you're required to output two things :- 1)all NON-ZERO counter values, 2)overall entered string

ganeshie8 (ganeshie8):

once u understand the q exactly, writing code for this program is easy....

OpenStudy (christos):

1)all NON-ZERO counter values, What's a ZERO value ?

ganeshie8 (ganeshie8):

for example, if the user enters below characters :- aaaaaaaaaaaaaaaaaaaaaaaaaaa.

ganeshie8 (ganeshie8):

all counters except a, are ZERO. you should not output their contents

ganeshie8 (ganeshie8):

basically u need to check size of counter, if its 0, dont print it.

OpenStudy (e.mccormick):

I have to say, that is a horribly written question!

OpenStudy (e.mccormick):

@ganeshie8 you do not need the string or to print it out. All you need is the count of characters and each alpha character.

ganeshie8 (ganeshie8):

yup ! make it count, that way it gets simpler and makes more sense

OpenStudy (e.mccormick):

Type in characters. To stop, type in a dot. qwertyuiop[] HahahahaHha. a:5 e:1 h:6 i:1 o:1 p:1 q:1 r:1 t:1 u:1 w:1 y:1 Total Characters: 25 NOTE: Counting H and h are different.

OpenStudy (e.mccormick):

But since they only want 26 counters, you must increment h for both h and H.

OpenStudy (e.mccormick):

One large problem I see with this question is that it requires the use of unbuffered input. Otherwise you can't use a dot (full stop/period) to stop the input stream. If they have not taught you about libraries and cross compiler compatibility, that is a pain in the anatomy! It is a non-portable bit of code in many cases.

OpenStudy (christos):

Can you please help me by telling me if I am going to need to use one of these ? http://screencast.com/t/NOrPthkqRJ3c @e.mccormick

OpenStudy (christos):

http://pastebin.com/1dT5iHne that's my code so far, but I can honestly say that I am really stuck right now, any tips would be appreciated :/

OpenStudy (e.mccormick):

Well, there are three ways you can do the counters for individual letters that I can think of off the top of my head: 1) A bunch of if statments for each A, a, B, b, and so on. 2) A switch/case setup do A, a, B, b, and so on. 3) An understand of how int and char are related, an ascii table, and math.

OpenStudy (christos):

I see

OpenStudy (e.mccormick):

Try the following code to see something interesting. ``` int newline = 0; for (int i = 64; i<127; i++) { cout << i << ":" << (char)i << " " ; newline++; if (newline%10==0) cout << endl; } ```

OpenStudy (e.mccormick):

And here is another, related bit of code: ``` int main() { int newline = 0; char test[]="abcxyzABCXYZ"; for (int i = 0; i < 12; i++) { cout << "i=" << i; cout << " t[" << i << "]=" << test[i]; cout << " (int)t[" << i << "]=" << (int)test[i] << " "; newline++; if (newline%3==0) cout << endl; } return 0; } ```

OpenStudy (e.mccormick):

Those pieces of code show two things. 1) How to use an int as a char or a char as an int because of the relationship between them. 2) How to add a newline after so many outputs. Both could be very helpful in letting you do this project.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!