I have an assignment for class to make a table with the following information. I need to use two one dimensional arrays and one two dimensional array.
Date Covid Hospitalized Death //(this row needs to be one array)//
4/1/20 4089 1157 337
4/2/20 5013 1213 361
4/3/20 4464 1191 362
4/4/20 3026 972 336
4/5/20 2614 819 379
4/6/20 3086 391 327
4/7/20 1378 11 235
- The date column needs to be a one dimensional array.
- the top row needs to be a one dimensional array.
- The numbered data needs to be a two dimensional array.
I can get the two dimensional array set up but i cant figure out how to set up the one dimensional arrays and then how to display them all together to form the table.
enum {date, covid, hosp, death, numcols};
struct c19
{
string headers[numcols];
string dates[numrows];
int data[numrows][numcols]; //its one bigger than it needs to be, lazy me
};
c19 virusdata;
cout << virusdata.dates[thisrow] << virusdata.data[thisrow][covid] << virusdata.data[thisrow][hosp] ....
this idea is called parallel arrays, where array1[0] and array2[0] are 2 pieces of one record, and that record is 'record zero' (the index) to tie them together.
the enum manages your columns rather than [0] and [1] etc you can use good names and it allows you to add more columns easily (insert in enum before numcols and recompile)
this is trying to teach you about parallel arrays and how to do stuff, but the right design here really is to make a 1-d array of a struct that has date,int,int,int,... the struct is your columns and the array is your rows, and keep a string array of headers on the side (so two structs, one with array of string headers and array of inner struct).