-
March 25th, 2012, 07:57 AM
#1
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!
-
March 25th, 2012, 08:13 AM
#2
Re: Beginner needing help with program
What have you done so far?
-
March 25th, 2012, 08:27 AM
#3
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?
-
March 25th, 2012, 04:55 PM
#4
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
-
March 25th, 2012, 05:10 PM
#5
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.
-
March 25th, 2012, 08:16 PM
#6
Re: Beginner needing help with program
Originally Posted by Rigsby
Code:
while(num[i]<=tens){cout << “*”;}
I wouldn't bet on that this loop ever terminates...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
March 26th, 2012, 01:37 PM
#7
Re: Beginner needing help with program
Originally Posted by Eri523
I wouldn't bet on that this loop ever terminates...
LOL Oh dear….. You’re right, but he would have learned a very important lesson!
It was pseudo-code typed without testing!
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!
-
March 26th, 2012, 02:48 PM
#8
Re: Beginner needing help with program
-
March 26th, 2012, 03:12 PM
#9
Re: Beginner needing help with program
Stummschaltung! Dachte ich mir!
-
March 26th, 2012, 03:19 PM
#10
Re: Beginner needing help with program
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.
-
March 26th, 2012, 03:27 PM
#11
Re: Beginner needing help with program
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!
-
March 26th, 2012, 03:35 PM
#12
Re: Beginner needing help with program
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.
-
March 26th, 2012, 03:54 PM
#13
Re: Beginner needing help with program
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….
-
March 26th, 2012, 03:16 PM
#14
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?
-
March 26th, 2012, 03:21 PM
#15
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?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|