The Spaces Between Us. Existentialism vs. Array Display Manipulations

Get your bodies ready;

this is a seating chart, user chooses how many rows and columns there are, then they are displayed.

Two questions:

1) if you input 10 or more ROWS, you will notice that when it gets to the tenth row, the straight column shifts to the right along with with extra digit in the numbering scheme. i.e.

1
2
3
4
5
6
7
8
...
8  ABCD
9  ABCD
10  ABCD
11  ABCD
12  ABCD

etc..


I want them in a purrrfectly straight line bro. This is an affront to my aesthetic.


SECOND QUESTION:

Along similar lines, I need to institute spaces between the letters (i.e. AB CD or A BCD or ABC D) at user determined interval(s); these are to represent walkways, as a stewardess would traverse on a plane.

I'm sorry to do this to you, but here's the code, if you notice at the bottom, there is a DISPLAY function, wherein I meagerly attempt to right this ship. Heretofore I have failed, much conundrum has befallen I.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  //adsf
#include <iostream>
#include <cctype>
#include <Windows.h>


using namespace std;


struct Seating
{
	int rows;
	int columns;

};

typedef int* IntArrayPtr;
typedef char* CharArrayPtr;
typedef CharArrayPtr* SeatingChartPtr;

Seating user_input();

void Initialize_Seating(SeatingChartPtr seating, int rows, int columns);

void Display_Seating(SeatingChartPtr seating, int rows, int columns);


int main()

{
	Seating cht;	
	int rows=0, columns=0;
	
	cht = user_input();  // cht for charts, i.e. seating chart with rows and columns

	

	SeatingChartPtr seating = new CharArrayPtr[cht.rows];
	int i, j;

	for (i = 0; i < cht.rows; i++)
		seating[i] = new char[cht.columns];

	Initialize_Seating(seating, cht.rows, cht.columns);
	Display_Seating(seating, cht.rows, cht.columns);


		for (i = 0; i < cht.rows; i++)
			delete[] seating[i];
	delete[] seating;

	system("Pause");
	return 0;

	//cout << "Enter" << d1 << "rows of "
		//<< d2 << "seats" << endl;

}	


Seating user_input()
{
	Seating cht;
	
	cout << "**Please Do Not Enter More Than Thirty (30) Rows and Twenty (20) Seats**"
		<< "\n You Have Been Warned!" << endl;
	do {
	cout << "Enter the number of rows for the plane.\n>";
	cin >> cht.rows;
	if (cht.rows > 30)
		cout << "Can you not read?  Try again..." ;

	} while (cht.rows > 30);
	
	do {
	cout << "Enter the number of seats for the plane.\n>";
	cin >> cht.columns;

	for (int i = 0; i < cht.rows; i++)
	if (cht.columns > 20)
		cout << "Seriously? Try again..." ;
	} while (cht.columns > 20);
	
	//cht.columns = columns;
	//cht.rows = rows;

	return cht;
}


void Initialize_Seating(SeatingChartPtr seating, int rows, int columns)
{
	
	for (int i = 0; i < rows; i++)
		for (int j = 0; j < columns; j++)
			seating[i][j] = toupper('A') + j;


}

/// LOOK HERE !!!

void Display_Seating(SeatingChartPtr seating, int rows, int columns)
{
	
	for (int i = 0; i < rows; i++)
	{
                 /// this IF statement does NOT work
		if (rows > 10 )  // it was 5 earller for testing purposes
		cout << i + 1 << "   ";
		else
			cout << i + 1 << " ";
		for (int j = 0; j < columns; j++)
			cout << seating[i][j];
		cout << endl;

	}



}
// 
Last edited on
a)
if (rows > 10 )

should be:

if (i+1 >= 10 )

b)
for (int j = 0; j < columns; j++) {
if (j == 2) cout << " ";
cout << seating[i][j];
}

c) use std::vector instead of pointers or c-style arrays.
GOLD KEVIN GOLD!

I have finally experienced the singularity!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iomanip>

void Display_Seating(SeatingChartPtr seating, int rows, int columns)
{
    const int row_width = 3;
    const int sep_width = 2;

    for (int row = 0; row < rows; ++row)
    {
        std::cout << std::setw(row_width) << row + 1 << std::setw(sep_width) << "";

        for (int col = 0; col < columns; ++col)
            std::cout << seating[row][col];

        std::cout << '\n';
    }
You are welcome!
Topic archived. No new replies allowed.