views:

71

answers:

2

I would like to make a draw application. I want to enter user names until eg "end" is entered and then the program to split them in groups of two. Can you suggest any examples? I don't know how to start! If possible, I want to be Cross-platform. If it isn't possible I want linux.

+3  A: 

Assuming I'm understanding your question correctly:

Pseudocode:

while the user is entering user names
    store the user name in a list

for half the number of items in the list
    remove a random item from the list
    add that item to a second list

Here's a tutorial on using the STL container classes. You'll probably want to go with the std::list: http://www.yolinux.com/TUTORIALS/LinuxTutorialC++STL.html

Cogwheel - Matthew Orlando
I mean this (e.g.): I enter 4 names: L1, L2, L3, L4. And I want the program to split the users into groups: Group 1: L1, L2 Group 2: L3, L4 or Group 1: L1, L3 Group 2: L2, L4 or Group 1: L1, L4 Group 2: L3, L3etc...
Levo
Then yeah, this pseudocode should do what you want.
Cogwheel - Matthew Orlando
Yes, but I need a tutorial or an example.
Levo
Studying an example of working with a deck of cards could be helpful: http://www.fredosaurus.com/notes-cpp/misc/ex-deal-cards.html
Hostile Fork
Nice example, thanks.
Levo
+2  A: 

The iostream libraries in C++ are for reading and writing lines of text through a command line interface:

http://en.wikipedia.org/wiki/Command_line_interface

On the plus side of these libraries, they are very standardized and every C++ compiler offers them. They work on Windows, Linux, or any other platform.

On the downside of these libraries, you can only read and write lines of text. You cannot draw circles around your names, or position them freely in the window. The only kind of "drawing" you can achieve with them is ASCII art.

This tutorial shows you basic input and output in C++:

http://www.cplusplus.com/doc/tutorial/basic_io/

If you want more freedom in drawing arbitrary graphics, that's not part of the C++ language specification. You'll need a third-party library, which may or may not be provided on multiple platforms.

Some of these libraries have routines for drawing text strings on the display in arbitrary fonts. Others just provide a display area and expect you to do text drawing yourself or with a library like FreeType:

http://stackoverflow.com/questions/52431/how-do-i-draw-text-using-opengl-sdl-and-c

It's probably best to avoid the complexity of graphics if you're just getting started with C++ as a language. Better to follow along with a few more basic tutorials, and you should be able to adapt the pseudocode Cogwheel gave you to get it. (People on StackOverflow don't like to directly write code for simple problems because that often amounts to doing someone else's homework.)

Hostile Fork
OK, I weren't clear. User input is not the problem. That' the easy part. And with the word "draw" I didn't mean to draw lines, but make groups of names given. Like a football/basketball cup.
Levo
FWIW, i think by "draw" he meant "pick from a list" rather than "create a graphic representation". +1 for tutorial links :)
Cogwheel - Matthew Orlando
So if I/O isn't the issue then maybe you need tutorial on containers and random number generators?
Cogwheel - Matthew Orlando
@Levo - Oh, ha! Though English speakers do occasionally use the phrase "draw a name out of a hat", that's something of an idiom. We wouldn't call a Lottery game a "draw application"!!! :)
Hostile Fork
It isn't a lottery game. I'm not an english speaker. The dictionary says that draw means "pick randomly from a list".
Levo
@Levo - That usage of the word "draw" almost always appears in the pattern "draw an XXX out of a YYY". The lone word "draw" is assumed to refer to graphics and illustration, especially in the context of programming. So in this case the best choice is probably to just go ahead and say "I want to pick randomly from a list". :)
Hostile Fork
@Levo - Also: you are an English speaker (or writer, at least...) I meant to say "*native* English speakers"!
Hostile Fork
@Hostile Fork, stick with the programming advice... picking on a user's English skills doesn't help anybody.
Lirik
@Lirik - I'm not picking on him, I'm helping him understand why his question didn't make sense to us. That's how people learn languages, programming or otherwise.
Hostile Fork