2D array with linked lists.

I need to create a 2d array with linked lists. I need to use the command line input to do the following.

Commandline> Final.exe 3 4

and then it would produce a 3 by 4 2d array. It's basically supposed to behave like a spreadsheet then I'm going to have to create functions to add delete and sum up cells.

Right now I'm stuck with creating the empty cells and having them print. The program shuts down so I'm unable to figure out what's the error. I just want to create and print out the empty cell list so that I can get moving on the other parts of the project but im completely stuck.

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
#include "List.h"
#include "Class.h"
#include<iostream>
#include<string>
#include<cstdlib>
#include<sstream>
//should i include algorithm?


using namespace std;

//string line; 

int main(int argc, char** argv) {
	//First check user arguments. We require ints for width and a height
	if (argc < 3){
		cout << "You need at least two arguments to account for width and height." << endl;
		return 0;
	}

	//Get the width and height
	int width = stoi(string(argv[1])); /* fill in code to read the width */
	int height = stoi(string(argv[2])); /* fill in code to read the height */

	/*if either argument is not a positive number, then the program prints an
	error message and quits with a return value of 1.*/
	if (width <= 0 || height <= 0){
		cout << "Error! Width and height must be an integer greater than zero." << endl;
		return 1;
	}


	//check
	LList<LList<Cell*>> rows;
	//The height is the number of rows
	for (int i = 0; i < height; ++i) {
		LList<Cell*> empty;
		rows.push_back(empty);
		//Make a new empty cell in this row for every column
		for (int j = 0; j < width; ++j) {
			//The back() operator returns a reference to the last element in the list
			rows.back().push_back(new Cell());
		}
	}

	/*for (LList<LList<Cell*>>::iterator I = rows.begin(); I != rows.end(); ++I) {
		cout << &I << ' ';
	}*/

	system("pause");



}
Topic archived. No new replies allowed.