Hi All, Please help with the below Valet Parking Problem. Let me know if you need more info.

The valet parking problem:

Some fancy restaurants (i.e. ones without a drive-through window) offer a
valet parking service with which one of the restaurant's employees will
park your car for you as you arrive at the restaurant, and then retrieve
your car when you're ready to leave (expecting a generous tip at both ends
of the evening!)
A frequently seen problem is that restaurants have insufficient onsite
parking for all of the cars requiring the valet service, and so cars are
tightly packed into the available bays, and even the "roads" connecting
the bays. Invariably, my little yellow car is always parked at the rear of
the car park, and often blocked by many other cars. Fortunately my car is
always parked east-west and opposite the exit, which is always on the east
or west side of the carpark. Of course the restaurant employees have the
keys to all cars, and so they can shuffle them around to get my car to the
exit.
The goal of this project is to help the employees bring my yellow car to
the exit by accepting and verifying a sequence of commands, and then
moving the cars until the yellow car is brought to the exit.

The initial configuration of the carpark is read from a simple text file,
the carpark file, such as:
EXIT: 1 9
...b...c..
##.b...c..
..aaa.d...
geee..d.ff
g.....d...

where the lowercase letters denote the location (and length) of each car,
a fullstop denotes an empty square, and the '#' character denotes my poor
blocked car. The first line of the file provides the location of the
carpark's exit, which will always be on the east or west edge of the
carpark. The parking bay in the top-lefthand corner (the northwest corner)
has the location (0,0). Having read and verified the details from the
carpark file, the program reads a sequence of commands from its standard
input. Commands are of the form:
c S 3
# E 1
e E 2

where each line requests a single move. Each line provides (in order) the
car to move, the compass direction in which to move it (N, S, E, or W),
and the number of squares (parking bays) to attempt to move it.
Comments in the provided source code files define how the program should
perform if the carpark file or any of the movement requests are invalid.
The program terminates when any part of my yellow car is brought to the
exit.

Recommended Answers

All 7 Replies

That was not my home work or assignment, i read that in a book and worked on it. I just want some logic or help that could tell me the best way to solve it.

i read that in a book and worked on it. .

Problem is that you didn't ask any specific question or posted code that proves you've actually put some effort in it.
So what do you want to know, what have you done already and where are you stuck?

That was not my home work or assignment, i read that in a book and worked on it. I just want some logic or help that could tell me the best way to solve it.

Problem is that you didn't ask any specific question or posted code that proves you've actually put some effort in it.
So what do you want to know, what have you done already and where are you stuck?

I tried to make some methods, and wrote the main method. Can i use 2D array for this or how to proceed i want to learn C programming, the basic from books doesnot give u more knowledge. So trying to solve some complex programs to learn more. Please help me.

int main(int argc, char *argv[])
{
    /* Exit with an error if the the number of arguments (including
       the program's name) is not 2 */
    if(argc != 2)
    {
        fprintf(stderr, "Usage: %s carpark-file\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    else
    {
        // Read the initial configuration of the carpark from file
        readCarparkFile(argv[1]);

        // Print the contents of the carpark
        printf("The initial carpark from '%s' is:\n", argv[1]);
        printCarpark();

        /* Process user-provided moves, updating the carpark
           after each valid move */
        processMoves();

        // Print the contents of the final carpark
        printf("The final carpark is:\n");
        printCarpark();


    }


    return 0;
}

This assignment isn't really 'beginner' to be honest, but if you're willing to put a (quite) bit of time in it, it can be done.

The first step would be to create a 2d-array of characters ( as you expected) and populate it with the contents of the file.

So read the file one char at a time and load it into the array. You should check if the file isn't to big for the array, or else you'll get some horrible memory-errors :)

So leave the ProcessMoves() etc for the time being and concentrate on reading the file and (next step) displaying it. 'Big' projects like this should be solved 1 step at a time.

Also. When posting code here on daniweb, please use code-tags. It makes your code readable.

This assignment isn't really 'beginner' to be honest, but if you're willing to put a (quite) bit of time in it, it can be done.

The first step would be to create a 2d-array of characters ( as you expected) and populate it with the contents of the file.

So read the file one char at a time and load it into the array. You should check if the file isn't to big for the array, or else you'll get some horrible memory-errors :)

So leave the ProcessMoves() etc for the time being and concentrate on reading the file and (next step) displaying it. 'Big' projects like this should be solved 1 step at a time.

Also. When posting code here on daniweb, please use code-tags. It makes your code readable.

Thanks for the info, i will try to read the file and the print the array as u say then come for Process Moves.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.