repl.it
@SharkFin/

Spreadsheet

C++11

No description

fork
loading
Files
  • main.cpp
main.cpp
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
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>
#include <string>
#include <vector>

int main() {
	const int minWidth = 5;

	const int gridXSize = 5;
	const int gridYSize = 5;
	
	int widths[gridXSize];

	std::string cells[gridXSize][gridYSize];
	cells[1][1] = "hello this works";
	
	cells[0][0] = "ID";
	cells[1][0] = "First";
	cells[2][0] = "Last";
	cells[3][0] = "Wage";
	cells[4][0] = "Job";

	// First
	cells[1][1] = "Billy";
	cells[1][2] = "Joe";
	cells[1][3] = "Marianne";
	cells[1][4] = "Johnathan";

	// Last
	cells[2][1] = "Barker";
	cells[2][2] = "Colate";
	cells[2][3] = "Astrench";
	cells[2][4] = "Johnson";

	// Wage
	cells[3][1] = "54,000";
	cells[3][2] = "84,100";
	cells[3][3] = "25,000";
	cells[3][4] = "120,000";

	// Job
	cells[4][1] = "Stocking Head";
	cells[4][2] = "Manager";
	cells[4][3] = "Cashier";
	cells[4][4] = "Project Lead";

	// ID
	for(int i=1;i<gridYSize;i++) {
		cells[0][i] = std::to_string(i);
	}

	for(int i=0;i<gridXSize;i++) {
		widths[i] = minWidth;
		for(int l=0;l<gridYSize;l++) {
			if (widths[i] < cells[i][l].length()) {
				widths[i] = cells[i][l].length();
			} 
		}
	}

	for(int i=0;i<gridYSize;i++) {
		std::string rows[2] = {"", ""};
		if (i == 0) {
			std::cout <<  "┏";
			for(int x=0;x<gridXSize;x++) {
				int rowWidth = widths[x];
				if (cells[x][0].length() > minWidth) {
					rowWidth = cells[x][0].length();
				}

				for(int l=0;l<rowWidth;l++) {
					std::cout <<  "━";
				}
				std::cout << (x < gridXSize-1 ? "┳" : "┓");
			}
			std::cout << std::endl;
		}

		for(int x=0;x<gridXSize;x++) {
			std::string thisStr = cells[x][i];
			int size = thisStr.length();
			for(int l=0;l<widths[x] - size;l++) {
				thisStr += " ";
			}

			std::cout << "┃" + thisStr + (x < gridXSize-1 ? "": "┃");
		}
		std::cout << std::endl;

		if (i < gridYSize-1) {
			for(int x=0;x<gridXSize;x++) {
				std::string thisStr = cells[x][i];
				int size = thisStr.length();
				if (size < widths[x]) size = widths[x];
				thisStr = "";
				for(int l=0;l<size;l++) {
					thisStr += "━";
				}

				std::cout << (x == 0 ? "┣" : "╋") + thisStr + (x < gridXSize-1 ? "": "┫");
			}
			std::cout << std::endl;
		}
		
	}

	std::cout << "┗";
	for(int x=0;x<gridXSize;x++) {
		int rowWidth = widths[x];
		if (cells[x][0].length() > minWidth) {
			rowWidth = cells[x][0].length();
		}

		for(int l=0;l<rowWidth;l++) {
			std::cout << "━";
		}
		std::cout << (x < gridXSize-1 ? "┻" : "┛");
	}

	std::cout << std::endl << "Which cell would you like to change? ";
	int yPos;
	std::string xPos;
	std::cin >> yPos >> xPos;

	std::cout << yPos << " " << xPos << std::endl;
	return 0;
}

/*
┏━┳━┓
┃  ┃  ┃
┣━╋━┫
┃  ┃  ┃
┗━┻━┛
*/
?