Three dimensional array representing parking spaces

Assignment Help C/C++ Programming
Reference no: EM13163983

start with code in the file lab.cpp. This program works with a three dimensional array representing parking spaces in a parking garage on several floors. The code is incomplete. The functions "main", "display" and "showSpace" are complete. Your job is to finish function "choose". The idea behind this program is to display a parking garage arrangement of available and occupied car spaces and then allow the user to type in a space that can be made occupied (if available). If the user types in a space that is already occupied, the program is to simply type a message on the screen to say this is not possible since the space is already occupied. If available, the program is to change the space to occupied and then display the parking arrangement again with the change.

 

The function "choose" is bool return because if a change is actually made, this returns true so the main function can display the parking arrangement again (call function "display"). If a change is not made because the user selected a space that is already occupied, no change is made and only an error message is displayed. The error message is displayed by the "choose" function. In this case, the "choose" function returns false.

 

The matrix is composed of bool values (true if occupied and false if available). The showSpace function is responsible for displaying the '-' or 'O' depending on the matrix element value.

 

Remember that in the display, the rows and floor numbers start with 1, but they correspond to index values which start with 0. In the display, the columns are not numbered.

 

 

 

#include <cstdlib>

#include <ctime>

#include <iostream>

#include <iomanip>

using namespace std;

 

const int ROWS = 6;

const int COLUMNS = 12;

const int FLOORS = 3;

 

void display(bool ar[][COLUMNS][FLOORS]);

void showSpace(bool sp);

bool choose(bool ar[][COLUMNS][FLOORS]);

int main()

{

srand((unsigned)time(0));

bool car_sp[ROWS][COLUMNS][FLOORS];

int i, j, k;

// randomly assign car spaces to be occupied

// or not

for (i=0; i<ROWS; i++)

for (j=0; j<COLUMNS; j++)

for (k=0; k<FLOORS; k++)

{

if (rand()%10 > 2)

car_sp[i][j][k] = false;

else

car_sp[i][j][k] = true;

}

cout << "the existing car spaces are shown below\n"

<< "(0) if occupied, and (-) if available\n";

display(car_sp);

if (choose(car_sp))

{

cout << "\nafter the car space you chose is occupied,\n"

<< "the new result is below\n\n";

display(car_sp);

}

return 0;

}

 

void showSpace(bool sp)

{

if (sp)

cout << setw(3) << 'O';

else

cout << setw(3) << '-';

}

 

bool choose(bool ar[][COLUMNS][FLOORS])

{

bool changed = false;

// ask the user to select a space (choose floor,

// row and column).

 

// check whether the space is occupied.

// if occupied, report the error and return false

// if available, change to occupied and return true

 

return changed;

}

 

void display(bool ar[][COLUMNS][FLOORS])

{

for (int fl=0; fl<FLOORS; fl++)

{

cout << "floor number " << fl+1

<< "\nRow\n";

for (int rw=0; rw<ROWS; rw++)

{

cout << rw+1 << " ";

for (int cl=0; cl<COLUMNS; cl++)

showSpace(ar[rw][cl][fl]);

cout << endl;

}

}

}

 

 

Reference no: EM13163983

Questions Cloud

Emulates the behavior of a bus : Write a program that emulates the behavior of a bus. The bus must have a schedule ( a finite number of times for it to stop) and a certain capacity (number of passengers). In this program the bus has two states: stopped and going.
What objectives and political philosophies did he advocate : Who was Eugene V. Debs and what objectives and political philosophies did he advocate? What did he accomplish in 1912?
Method that receives an array and returns with no duplicate : Write a program that contrains a method that receives an array and returns a new array with no duplicates.
The knight''s tour problem : The knight's tour problem is as follows: given an initial position for a single knight on an otherwise empty chessboard, find a sequence of 64 moves that will make the knight visit every square on the board exactly once
Three dimensional array representing parking spaces : start with code in the file lab.cpp. This program works with a three dimensional array representing parking spaces in a parking garage on several floors. The code is incomplete. The functions "main", "display" and "showSpace" are complete. Your job i..
What factors contribute with the recent economic recession : Topic what factors contribute with the recent economic recession
Write the formulas for the compounds of these ions : although not a transition element, lead can form two cations: Pb2+ and Pb4+. write the formulas for the compounds of these ions with the chloride ion.
Give a polynomial time reduction : Give a polynomial time reduction from the 3-Color (coloring a graph so that no vertices adjacent to each other have the same color using 3 colors) problem to 3-CNF SAT.
Why do we create a web site plan : Why do we create a web site plan?2. What are the several types of objectives?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd