/***************************************************************************/
/* Rhombus.cpp  -  Display a rhombus (diamond) on the screen               */
/*                 Show how to count up-down-up...                         */
/*                 Show how to center & space-right by a computed amount   */
/***************************************************************************/

#include <iostream.h>
#include <string.h>
#include <math.h>

void DisplayRhombus (char sTitle [], int nMaxNRows, char cSymbol, int nOffset);

/***************************************************************************/

int main (void)
{
    DisplayRhombus ("A Rhombus", 12, '*', 4);
    DisplayRhombus ("Another Rhombus", 16, 'X', 20);
    DisplayRhombus ("The Very Last Rhombus", 20, 'Z', 40);

    return 0;
}    // end main

/***************************************************************************/

void DisplayRhombus (char sTitle [], int nMaxNRows, char cSymbol, int nOffset)
{
    const  int  nMaxNStars = nMaxNRows / 2;

    cout.width (nOffset + nMaxNStars/2 - strlen (sTitle) / 2);
    cout << " " << sTitle << endl;

    for (int nRow = -nMaxNStars; nRow <= nMaxNStars; nRow += 2)
    {
        cout.width (nOffset + abs (nRow) / 2);
        cout << " ";
        for (int nCol = 0; nCol < nMaxNStars - abs (nRow) + 1; nCol++)
            cout << cSymbol;
        cout << endl;
    }
}    // end DisplayRhombus

/***************************************************************************

   A Rhombus
       *
      ***
     *****
    *******
     *****
      ***
       *
                 Another Rhombus
                        X
                       XXX
                      XXXXX
                     XXXXXXX
                    XXXXXXXXX
                     XXXXXXX
                      XXXXX
                       XXX
                        X
                                   The Very Last Rhombus
                                             Z
                                            ZZZ
                                           ZZZZZ
                                          ZZZZZZZ
                                         ZZZZZZZZZ
                                        ZZZZZZZZZZZ
                                         ZZZZZZZZZ
                                          ZZZZZZZ
                                           ZZZZZ
                                            ZZZ
                                             Z
..... */
