Printing text side by side

This is a discussion on Printing text side by side within the C++ Programming forums, part of the General Programming Boards category; I'm pretty sure this isn't going to work without seriously changing my code, but I'll ask it anyways! I'm writing ...

  1. #1
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728

    Printing text side by side

    I'm pretty sure this isn't going to work without seriously changing my code, but I'll ask it anyways! I'm writing a sports program running in the DOS console that contains an object called a division that contains a list of pointers to Team objects. Now I've overloaded the ostream<< operator so when you type cout<<division it prints out like so:
    Code:
    AFC West
    Denver Broncos        12-4
    Kansas City Chiefs    10-6
    San Diego Chargers     8-8
    Oakland Raiders        4-12
    Now this works fine and dandy, but the more and more I run the program the more I notice that it when printing out a list of divisions it'll look much nicer if I could print divisions side by side like so:
    Code:
    AFC West                               NFC West
    Denver Broncos        12-4             San Francisco 49ers   11-5        
    Kansas City Chiefs    10-6             St Louis Rams         10-6
    San Diego Chargers     8-8             Arizona Cardinals      7-9
    Oakland Raiders        4-12            Seattle Seahawks       6-10
    Now I could write a function that prints each team out one by one from left to right, but this'll really mess up my design since the teams and the records etc aren't accessible from outside the division. Does anyone know if something like this might be possible with cursor placements or other means when printing an object using an overloaded <<?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    <conio.h> contains the gotoxy() function that will allow you to place your output where you'd like it on the screen.

    Problem: <conio.h> is non-standard and would require some trial-and-error to accomplish what you want.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    I've never used the gotoxy function before and can't practice with it until this weekend due to school and work But my guess is that it wouldn't work very well with outputting an object that takes up several lines and that only uses one overloaded "cout<<"... or is that assumption wrong?
    Last edited by PJYelton; 10-14-2002 at 10:50 AM.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Something like this might work:


    Code:
    void ToSideBySide(Team * team, int num_teams, int max) {
    for(k = 0; k < num_teams; k += max) {
     
      if( (k + max) > num_teams)
       max = num_teams - k;
      
      for(i = k; i < (k+max), i++){
       cout << team[i]->name;
       }
      for(i = k; i < (k+max), i++){
       cout << team[i]->scores;
       }   
      
      getch(); 
     }
    }
    
    
    
    
    #define COUNT 11
    
    int main() {
    
    Team NFL[COUNT];
    
    //...fill in data...
    
    ToSideBySide(NFL, COUNT, 3);
    
    return 0;
    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    gotoxy() takes two arguments, an 'x' value and a 'y' value (screen coordinates). This positions the cursor on the screen at a specific location and displays your information there.

    Once you've determined where you want to display your division info (the trial-and-error part), it would only require a simple loop to increment the 'y' coordinate, leaving the 'x' value "as is".

    Now, without seeing your code, I don't know how much re-working you'd be getting yourself into here. I would assume that you want all of your divisions displayed on one screen, which may, in fact, make this an easier proposition than it seems.

    Wish I knew of a better alternative for you, but this is where my thinking takes me.

    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  6. #6
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Hmmmm... I see what you're getting at. I guess that would entail me writing a new member function that displays the division using x and y coordinates, instead of just "cout"ing the division with the overloaded ostream<<. Not as elegant as how I had it before, but hey, sounds like it'll work! Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Replies: 3
    Last Post: 05-25-2005, 01:50 PM
  3. Read word from text file (It is an essay)
    By forfor in forum C Programming
    Replies: 7
    Last Post: 05-08-2003, 11:45 AM
  4. mygets
    By Dave_Sinkula in forum C Programming
    Replies: 6
    Last Post: 03-23-2003, 06:23 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21