/***************************************************************
* Name: Rafael Orta
* Course: Computer Science & Programming
* Class: CS04103 Section: 2
* Assignment Date: 09/05/18
* File Name: MultiDimension.cpp
*****************************************************************
* Purpose: This program passes a multidimensional array of structs to
* a function
*****************************************************************/
#include <stdio.h>
#include <iostream>
#include <iomanip>
using namespace std;
// Declaring my struct
struct table
{
string name;
int tnum;
};
void disTable(struct table rtable[5][4]);
void clean(struct table rtable[5][4]);
int main()
{
// Creating an array of structs
struct table rtable[5][4];
// Empty the array
clean(rtable);
// Adding some values to my array of structs, you are expected to have some data as well.
rtable[1][1].name = "Rafael Orta";
rtable[1][1].tnum = 6;
rtable[4][3].name = "Kristina Orta ";
rtable[4][3].tnum = 20;
// Calling a function to display the information inside the array of structs
disTable(rtable);
return 0;
}
void disTable(struct table rtable[5][4])
{
cout << " ********************************************************************************************************************************************";
for (int row=0 ; row<5 ; row++)
{
cout << endl;
for (int col=0 ; col<4 ; col++)
{
cout << left << setw(2) << " |Table No: " << setw(2) << rtable[row][col].tnum << setw(2) << " Name: " << setw(14) << rtable[row][col].name;
}
cout << "|";
}
cout << "\n ********************************************************************************************************************************************" << endl;
}
void clean(struct table rtable[5][4])
{
int t = 0;
for (int row=0 ; row<5 ; row++)
{
for (int col=0 ; col<4 ; col++)
{
t++;
rtable[row][col].name = "Available";
rtable[row][col].tnum = t;
}
}
}