-
Beginner needing help with program
Hi there,
I'm trying to write a console app in visual studio 2010 that will read a set of numbers and construct a histogram that shows how many numbers are between each two numbers...if that makes sense. To clear it up, i'm looking for an output like:
0 - 10 ***
11 - 20 ****
21 - 30 **
So in that example, 3 numbers (*) have been found in the read file between 0 and 10. 4 numbers (*) have been found in the read file between 11 and 20 and so on.
The read file looks like this:
1 2 24 13 11 9 20 28 16
So it's just a pretty basic txt file.
Any help on how to code this?
Thanks!
-
Re: Beginner needing help with program
What have you done so far?
-
Re: Beginner needing help with program
Nothing so far unfortunately :/
I'm not sure how I'd load the file but am I right in thinking that an if statement would be used for displaying that stars?
-
Re: Beginner needing help with program
Will your file be a continuous file with no returns or double spaces? Can you guarantee that? So just one continuous stream of “number space number space number space number” and so on?
If you can’t read a simple file into c++ the whole thing is a bit ambitious.
But what I would do is simply push each number into a vector as in: “vector <int> num;” and then iterate through num using 2 int variables:
Code:
void printNumHist(vector <int> num){
unsignedint strt=1, tens=10;
for (unsignedint i=0; i<num.size(); i++){
cout << "\n";
cout << strt" - "tens" = ";
while(num[i]<=tens){cout << “*”;}
tens=tens+10;
strt=tens-9;
}
}
This is non-tested pseudo code just typed into the box here…. Also, in order to create the vector I would need to have the answers to my first questions regarding the file format.
The vector also needs to be sorted….
Rigsby
-
Re: Beginner needing help with program
once I have your file format, I will explain how to read it into the vector and sort the vector. ;)
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
Code:
while(num[i]<=tens){cout << “*”;}
I wouldn't bet on that this loop ever terminates... ;)
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Eri523
I wouldn't bet on that this loop ever terminates... ;)
LOL :eek: Oh dear….. You’re right, but he would have learned a very important lesson!
It was pseudo-code typed without testing!:D
Sorry dahrull! I have added the variable maxT as a quick and dirty solution, though I would probably look at another option to break;
Code:
void printNumHist(vector <int> num){
unsignedint strt=1, tens=10, maxT=num[num.size()-1];
for (unsignedint i=0; i<num.size(); i++){
cout << "\n";
cout << strt" - "tens" = ";
while(num[i]<=tens){cout << “*”;}
tens=tens+10;
strt=tens-9;
if(i>maxT){break;}
}
}
Well spotted Eri523! And thanks for letting me correct this myself! :thumb:
-
Re: Beginner needing help with program
Why are you doing this guy's homework for him?
-
Re: Beginner needing help with program
Quote:
Originally Posted by
GCDEF
Why are you doing this guy's homework for him?
Oh GCDEF…. Seriously! Is this homework? Do you know that? This guy said he was a newbie! We all start somewhere! And I didn’t tell him how to read the file, which I suspect he was actually looking for ;-))
Also, a vector for this problem will work, but is a totally top-heavy solution for what he wants that any good teacher will jump on immediately, thus teaching him a further lesson! But if he is a genuine “newbie” the vector solution will serve him well, and teach him his first step into STL – so a win-win, don’t you think!
Why are you policing these threads?
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
Oh GCDEF…. Seriously! Is this homework? Do you know that? This guy said he was a newbie! We all start somewhere! And I didn’t tell him how to read the file, which I suspect he was actually looking for ;-))
Also, a vector for this problem will work, but is a totally top-heavy solution for what he wants that any good teacher will jump on immediately, thus teaching him a further lesson! But if he is a genuine “newbie” the vector solution will serve him well, and teach him his first step into STL – so a win-win, don’t you think!
Why are you policing these threads?
With 45 posts in 6 years, you're probably not familiar with how this forum works. We don't do homework for people, and that's very obviously homework.
And no, I don't think doing somebody's work for them is win/win.
I would advise you to come up with a consistent and meaningful style of indentation and alignment though.
-
Re: Beginner needing help with program
Quote:
Originally Posted by
GCDEF
With 45 posts in 6 years, you're probably not familiar with how this forum works. We don't do homework for people, and that's very obviously homework.
And no, I don't think doing somebody's work for them is win/win.
I would advise you to come up with a consistent and meaningful style of indentation and alignment though.
Why are you policing these threads?
-
Re: Beginner needing help with program
Quote:
Originally Posted by
GCDEF
With 45 posts in 6 years, you're probably not familiar with how this forum works. We don't do homework for people, and that's very obviously homework.
And no, I don't think doing somebody's work for them is win/win.
I would advise you to come up with a consistent and meaningful style of indentation and alignment though.
Why are you getting angry? And why are you „giving advice” on things other than code?
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
Why are you policing these threads?
I'm not going to engage in a pissing match with you. I'm just pointing out how the forum works. If I hadn't, somebody else would have.
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
Why are you policing these threads?
Don't do other peoples homework for them. That helps no-one.
-
Re: Beginner needing help with program
Quote:
Originally Posted by
GCDEF
I'm not going to engage in a pissing match with you. I'm just pointing out how the forum works. If I hadn't, somebody else would have.
I’m sorry, but I seriously do not understand what in God’s name you have for a bee in your bonnet about! If I do anything untoward then admin here will tell me and not you! And, words like p***ing are not very nice!
I am sorry if I embarrassed you over the int char thing! But that is not any reason to stalk my threads and hit me on “indentation” – I am on a Galaxy SII phone for Pete’s sake! Try indenting code on this thing. :D
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Martin O
Don't do other peoples homework for them. That helps no-one.
Does it harm you?
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
I am sorry if I embarrassed you over the int char thing! But that is not any reason to stalk my threads and hit me on “indentation” – I am on a Galaxy SII phone for Pete’s sake! Try indenting code on this thing. :D
You were wrong about that, but even if you were right, it wouldn't embarrass me. I'm not stalking you. Until this thread, I had no idea who you were.
-
Re: Beginner needing help with program
-
Re: Beginner needing help with program
Quote:
Originally Posted by
GCDEF
You were wrong about that, but even if you were right, it wouldn't embarrass me. I'm not stalking you. Until this thread, I had no idea who you were.
you read my profile! ;-) so there was some interest!
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
you read my profile! ;-) so there was some interest!
Trying to find the thread you're talking about. If I said something wrong, I'd want to know about it, but in this case I don't believe I did.
-
Re: Beginner needing help with program
Quote:
Originally Posted by
GCDEF
Trying to find the thread you're talking about. If I said something wrong, I'd want to know about it, but in this case I don't believe I did.
;-) course you were.... However, you are “trying to find the thread” so you have no idea of what I am talking about, but write: “you were wrong about that”…. Well, that sounds like a very good piece of (logic) code!
Well either you are policing threads here or this was aimed at me…. So I am just guessing at what contact we have had so far, which was your suggestion to “switch case” on a char rather than an int! I suggested this would bring overhead!
But I take it back and say sorry, I guess I was wrong and it’s not personal; you are simply a self-appointed homework detective!
But I will help who I want here unless the Forum admin tells me I am doing something wrong! And you can post with your holier-than-thou homework detective work as long as you want! But I am here to give and receive help, and have met some really nice people here.
And no-one is “no one”… without the hyphen! Just like no two people! So I am guessing you are British!
Have a nice day making friends,
Rigsby
:D
-
Re: Beginner needing help with program
Stummschaltung! Dachte ich mir!
-
Re: Beginner needing help with program
Did you read what I posted Rigsby? It's not that no help is offered for homework issues. We're just trying to avoid posting a full solution since that doesn't really help a beginner. If this was a math board you wouldn't post a full solution would you?
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
Stummschaltung! Dachte ich mir!
Just don't see the point in talking to you any more. That's not what this forum is about. I'm not really sure why you would choose not to abide by its policies, but thankfully you don't post much. With a little luck, you'll go dormant again.
-
Re: Beginner needing help with program
Of course I read what you posted! Anything else would be ignorant.
I did not post a solution! I posted a trap that any IT teacher would immediately recognize as “from the web” so thus gave the person either a solution to a problem (if not homework) or reason to think about how to solve it themselves if homework when the teacher challenges them on it.
People, the natural solution to the problem was NOT a vector; why is that so difficult for you to understand?
-
Re: Beginner needing help with program
Quote:
Originally Posted by
GCDEF
Just don't see the point in talking to you any more. That's not what this forum is about. I'm not really sure why you would choose not to abide by its policies, but thankfully you don't post much. With a little luck, you'll go dormant again.
GCDEF you are so hurtful and personal! I guess you were just made that way! I do not hope that you go away…. If you thought the “point” in talking to me was to somehow “win” than you are right… just leave it; however, should you actually be interested in an exchange of intellectual perspectives on this or any other subject, then I always welcome the opportunity of discussion!
-
Re: Beginner needing help with program
You know the forum rules can also be discussed, tested, and perhaps changed! They are not the 10 commandments!
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
GCDEF you are so hurtful and personal! I guess you were just made that way! I do not hope that you go away…. If you thought the “point” in talking to me was to somehow “win” than you are right… just leave it; however, should you actually be interested in an exchange of intellectual perspectives on this or any other subject, then I always welcome the opportunity of discussion!
Then I suggest you go the the discussion forum where it would be on topic. However, I'm not really interested in exchanging "intellectual perspectives" with you here or anywhere else. If you don't like the forum rules, I suggest you take them up with the moderator.
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
Does it harm you?
It may harm the original poster.
Many teachers search the Internet for plagiarism. If they see that their question was asked here, and then you give the student the answer or close to the answer, that student could get in a lot of trouble, possibly fail, and in some cases suspended or expelled.
If the poster never asked for you to give code, then don't do it -- even if they demand an answer, don't give them one (except for belligerent posters, where there is a house trick that I've done a few times).
It may not hurt you, and it may not hurt GCDEF or any of us, but it sure could hurt that unfortunate student who never asked you to post lengthy answers for him/her, and then they get in trouble at school. There have been posters pleading that certain "helpers" remove the answers from this board because of the fear of being found out and accused of plagiarism.
Regards,
Paul McKenzie
-
Re: Beginner needing help with program
Quote:
Originally Posted by
GCDEF
Then I suggest you go the the discussion forum where it would be on topic. However, I'm not really interested in exchanging "intellectual perspectives" with you here or anywhere else. If you don't like the forum rules, I suggest you take them up with the moderator.
Well, there you go again with your suggestions and advice…. I would like to remind you that no one (without a hyphen) asked you to comment here! I seem to remember that I was in the process of helping with (not doing) some kid’s homework, when Mr. Homework-detective (that’s a compound so we use a hyphen) butted in and got all aggressive… and used offensive words (pi***ng)….
So if you are not “really interested” in exchanging with me, get the hell out of my discussion with this poster…. You butted in, not I… I will then help here as I see fit…. If you don’t like it, then you will have to converse with me you arrogant, aggressive, angry, not very articulate, person – or stay out of it! You do not make the rules in my discussion….
And I just said all of that without a single swear word!
Like I said, go make some friends….
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Paul McKenzie
It may harm the original poster.
Many teachers search the Internet for plagiarism. If they see that their question was asked here, and then you give the student the answer or close to the answer, that student could get in a lot of trouble, possibly fail, and in some cases suspended or expelled.
If the poster never asked for you to give code, then don't do it -- even if they demand an answer, don't give them one (except for belligerent posters, where there is a house trick that I've done a few times).
It may not hurt you, and it may not hurt GCDEF or any of us, but it sure could hurt that unfortunate student who never asked you to post lengthy answers for him/her. There have been posters pleading that certain "helpers" remove their answers from this board because of the fear of being accused of plagiarism.
Regards,
Paul McKenzie
I posted pseudo code….. Get real! We are not here to police the school system….. If a kid trys to trick code from us here then he/she deserves everything they get!
-
Re: Beginner needing help with program
Sorry! I know that sounds hard!
-
Re: Beginner needing help with program
But I need and want to offer help here and not involve myself in policing America’s IT students…. The teachers need to make students aware of the consequences of doing what 99% of programmers do: looking for code on the web! Not we!
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
If a kid trys to trick code from us here then he/she deserves everything they get!
I am not talking about the ones that are trying to trick code from us. I'm referring to the posters who are attempting to get advice and who have not asked for code to be given. They are not here to trick anyone.
Regards,
Paul McKenzie
-
Re: Beginner needing help with program
Paul, I understand…. But that is not the case in this post! I thought this was simply a newbie! And not a student! Read the post…..
Best regards,
Rigsby
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
Paul, I understand…. But that is not the case in this post! I thought this was simply a newbie! And not a student! Read the post…..
Best regards,
Rigsby
Well, to be on the safe side, post code that only a professional C++ programmer would have or could have written. For example, using very advanced templates, maybe a template meta-program, something from boost, etc.
Now what if an answer is demanded? If the scenario was that the student poster demanded we give them an answer, what would you do then? Hopefully you won't give in that easily.
We've fleshed out a few of those posters also, and there are ways to deal with them and give the answers (see above). The extreme would be to obfuscate the code.
Regards,
Paul McKenzie
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Paul McKenzie
Well, to be on the safe side, post code that only a professional C++ programmer would have or could have written. For example, using very advanced templates, maybe a template meta-program, something from boost, etc.
Now what if an answer is demanded? If the scenario was that the student poster demanded we give them an answer, what would you do then? Hopefully you won't give in that easily.
We've fleshed out a few of those posters also, and there are ways to deal with them and give the answers (see above). The extreme would be to obfuscate the code.
Regards,
Paul McKenzie
But you are missing the point… I am not a professional C++ programmer…. I am a very talented newbie…… Perhaps….. But I cannot police this forum! I can/will help where I can but I am (to tell the truth) here to ask for help…… And, I still don’t understand why posters are policing the forum! Surely if I do something wrong, a moderator (Admin) has the job of telling me that!
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Rigsby
[SIZE=3][FONT=Calibri]But you are missing the point… I am not a professional C++ programmer…. I am a very talented newbie…… Perhaps….. But I cannot police this forum! I can/will help where I can but I am (to tell the truth) here to ask for help……
The ones who have been here the longest, posted the most, and have helped the most are the ones advising you against posting homework answers. There has to be some wisdom in what they're saying, wouldn't you think so?
Also, maybe because you're a new programmer or not a professional is a reason why you don't see things the same way GCDEF, myself, and others see it. You could say there is a "code of ethics" amongst programmers.
And it isn't just this board:
http://www.parashift.com/c++-faq/how...t.html#faq-5.2
http://www.parashift.com/c++-faq/how...t.html#faq-5.3
Regards,
Paul McKenzie
-
Re: Beginner needing help with program
Quote:
Originally Posted by
Paul McKenzie
The ones who have been here the longest, posted the most, and have helped the most are the ones advising you against posting homework answers. There has to be some wisdom in what they're saying, wouldn't you think so?
Also, maybe because you're a new programmer or not a professional is a reason why you don't see things the same way GCDEF, myself, and others see it. You could say there is a "code of ethics" amongst programmers.
And it isn't just this board:
http://www.parashift.com/c++-faq/how...t.html#faq-5.2
http://www.parashift.com/c++-faq/how...t.html#faq-5.3
Regards,
Paul McKenzie
No… sorry! But old and long does not mean right! I will not argue this with you out of respect for you, but old and tested is religion, terrorism; it has always been that way……. We must be allowed to question and argue or there is no freedom!
And…. I did not post a Homework answer… That is the main point!
-
Re: Beginner needing help with program
dahrull, if you still need help with this I suggest you start a new thread.
-
Re: Beginner needing help with program
I think I'll ask moderators to close this thread.
OK?