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

  Program to tell you how many months it will take to pay off

write a program to tell you how many months it will take to pay off any loan, as well as the total amount of interest paid over the life of the loan.

  Function that returns the height of a binary tree

Write a function called getHeight() that returns the height of a given binary tree - CptS 122 Write a function called countSmallerThan() that returns the number of nodes whose values are smaller than the supplied input paramter

  Write c program which compute acceleration of jet fighter

Write a C++ program which compute the acceleration (m/s 2) of jet fighter launched from aircraft-carrier based catapult, provided jet's takeoff speed in km/hr

  Change temperature fahrenheit to celsius and kelvin

Write a program in c++ that takes the temperature in Fahrenheit and convert it to Celsius And Kelvin:

  Write a program to convert between rectangular

Write a program to convert between rectangular and cylindrical coordinates, based upon user input. For example, if the user wants to convert cylindrical to rectangular coordinates, the user would input r, ?, z values and the program would output x, y..

  Modify it so it gives the ith largest number

the follow code gives the ith smallest number, how do you modify it so it gives the ith largest number ?

  A linked list of your song structure in cd

The CD object should have a data member that is a linked list of your song structure that you have in CD.  The CD class needs a function that allows it to add a song to the object, that function would then append the song to that instance of the link..

  Programs written with inheritance

Many programs written with inheritance could be written with composition instead, and vice versa. Rewrite the classes Point3D, Sphere and Cylinder using composition rather than inheritance

  Write program to perform add-drop-list and update functions

Write C++ program to do add, drop, list (in last name / first name sorted order or id) and update functions. separate UI from data processing use object programming method multiple files

  Program that will ask for a month

Write a program that will ask for a month (1-12) and a year (yyyy). the program should then produce a calendar showing the month name and year and have all of the days displayed under it.

  Two types of constructors

Explain what constructors do and when they are executed. Explain the two types of constructors. Provide an example class that includes both types of constructor functions and demonstrate how an object would be instantiated using both types of constru..

  Write program which inputs number of winning coupons

Write a program which inputs number of coupons you win and outputs how many candy bars and gumballs you can get if you spend all off your coupons on candy bars first and remaining coupons on gumballs in c++.

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