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

  Write a program which accepts the total of food and drink

Write a program which accepts the total of food and drink purchased for a restaurant bill as input. The output should be adjusted bill with a sales tax of six percent 6% and a tip (gratuity) of 15%.

  C programme to find the minimum and maximum value

write a c programme to find the minimum and maximum value each elements in each row ,to create table b,having 5 rows and 2 coloums,the first coloum of table b is the maximumvalue and thye second coloum is the maximum value in each row.

  Implement the delivery company

Implement the delivery company using the classes given in the class diagram above.

  Draws a single level for a "rogue­like" computer game

You will write a program that draws a single level for a "Rogue­like" computer game. The program will parse a line of input text from an input file (room.txt), use the parsed text to determine the shape of the room and its contents and then draw the ..

  Draws a pyramid consisting of bricks

Write a C program that draws a pyramid consisting of bricks arranged in horizontal rows, so that the number of bricks in each row decreases by one as you move up the pyramid.

  Write a program that skip s leading whitespace character

a) Write a program that skip s leading whitespace character s in each line of the pro vided data file CPPHumor .txt . Save the results in a new file

  Write a program that reads numbers

Write a C++ program that reads N positive numbers from the keyboard, calculates and shows the smallest number of all numbers

  Write a program to read only one integer number

Write a program to read ONLY one integer number (your input must be one 3 digit number from 100 to 999), and to think of a number as being ABC (where A, B, and C are the 3 digits of a number)

  Write a program that computes the cost of long distance call

Write a program that computes the cost of a long distance call. The cost of the call is determined according to the following rate schedules.

  Computer programming using c language lab

Computer programming using c language lab

  Prepare a program that uses at least two functions

Prepare a program that uses at least two functions that can be called from your main.

  Implement database having array of pointers

One way to implement this database is to have an array of pointers pointing to Employee objects. You will obviously require a function named Calculate_salary() which will be different for each employee class. Write code 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