0

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.

2 Answers2

3

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
  • 22,781
  • 4
  • 49
  • 67
  • 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, L3 etc... –  Jun 11 '10 at 18:36
  • Yes, but I need a tutorial or an example. –  Jun 11 '10 at 19:01
  • 1
    Studying an example of working with a deck of cards could be helpful: http://www.fredosaurus.com/notes-cpp/misc/ex-deal-cards.html – HostileFork says dont trust SE Jun 11 '10 at 19:37
2

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:

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.)

Community
  • 1
  • 1
  • 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. –  Jun 11 '10 at 19:03
  • 1
    FWIW, i think by "draw" he meant "pick from a list" rather than "create a graphic representation". +1 for tutorial links :) – Cogwheel Jun 11 '10 at 19:03
  • So if I/O isn't the issue then maybe you need tutorial on containers and random number generators? – Cogwheel Jun 11 '10 at 19:04
  • @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"!!! :) – HostileFork says dont trust SE Jun 11 '10 at 19:17
  • It isn't a lottery game. I'm not an english speaker. The dictionary says that draw means "pick randomly from a list". –  Jun 11 '10 at 19:26
  • @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". :) – HostileFork says dont trust SE Jun 11 '10 at 19:32
  • @Levo - Also: you are an English speaker (or writer, at least...) I meant to say "*native* English speakers"! – HostileFork says dont trust SE Jun 11 '10 at 19:47
  • @Hostile Fork, stick with the programming advice... picking on a user's English skills doesn't help anybody. – Kiril Jun 11 '10 at 21:54
  • 1
    @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. – HostileFork says dont trust SE Jun 12 '10 at 03:43