Hello, I am currently trying to write a program that will display a chart for the inventory of a car dealer. Here are the major points of the assignment, the ones Im having trouble on:
Write a program to be able to display the instock table as instructed below :
2. Declare an enum type for row index text names
a. Enum Type name: MAKERS
b. Enum members: Ford, BMW, Volvo, Chevy, Cadillac, Hyundai
3. Declare an enum type for column index text names.
a. Enum Type name: COLORS
b. Enum members: Red, Brown, Black, White, Gray
a. Declare a MAKERS enum variable as maker
i. Use maker as row index variable of the array
b. Declare a COLORS enum variable as color
i. Use color as column index variable of the array
c. Write a nested for-loops to display the inventory table as shown above.
d. To be able to convert the enum element names to test, write two conversion functions
i. void convertToMakers(MAKERS m)
1. Displays maker names – use switch function.
ii. void convertToColors (COLORS c)
1. Displays color names – use switch function.
Currently the program displays the header and the array, but Im having a lot of trouble with actually using the enums. I understand how enums are supposed to work in simple code but am having trouble applying it to an array. Any help or suggestions are much appreciated.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const int ROW_MAX = 6;
const int COLUMN_MAX = 5;
void reportHeading ( ostream& outputfile);
void printInventory (ostream& outputfile, int carsInStock[ROW_MAX][COLUMN_MAX]);
int main () {
enum MAKERS {FORD,BMW,VOLVO,CHEVY,CADILLAC,HYUNDAI};
enum COLORS {RED,BROWN,BLACK,WHITE,GREY};
int carsInStock[ROW_MAX][COLUMN_MAX] = {{18,11,15,17,10},
{16,6,13,8,3},
{9,4,7,12,11},
{10,7,12,10,4},
{12,10,9,5,6},
{11,13,7,15,9}};
ofstream outputfile ("PJ712_output.txt");
if (!outputfile)
{
cerr <<"Could not open the output file.\n";
return -2;
}
outputfile <<fixed<<showpoint<<setprecision(2);
reportHeading (outputfile);
printInventory (outputfile, carsInStock );
}
void reportHeading ( ostream& outputfile){
outputfile << "Cars in Stock Inventory" << endl;
outputfile << "By Yelena Sergevnina \n\n" << endl;
}
void printInventory (ostream& outputfile, int carsInStock[ROW_MAX][COLUMN_MAX]){
MAKERS = maker;
COLORS = color;
for( int i = 0; i < ROW_MAX; i++ )
{
for ( int j = 0; j < COLUMN_MAX ; j++ )
{
outputfile << setw(12) << carsInStock[i][j];
}
outputfile << endl;
}
}