LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-02-2013, 09:35 AM   #1
Thilinamc
LQ Newbie
 
Registered: Jun 2013
Posts: 2

Rep: Reputation: Disabled
Question Python Programme


Hello,

I'm a new member to this forum... So I'm gonna post my first post here...

I have to write a program according to the below description...

"The laughs parking garage contains a single lane that hold up to ten cars. Cars arrive at the south end of the garage and leave from the north end. If a customer arrives to pick up a car that is not northernmost, all the cars to the north of his car are moved out, his car is driven out, and the others cars are restored in the same order that they were in originally. Whenever a car leaves, all the cars to the south are moved forward. So that at all the times all the empty spaces are in the south part of the garage.

Write a python program to reads a group of input lines. Each line contains an a arrival or a d departure and a license plate number. Cars are assumed to arrive and depart in the order specified by the input. The program should print a message each time that a car arrives or departs. When a car arrives, the massage should specify whether or not there is room for the car in garage. If there is no room for a car, the car waits until there is room or until a departure line is read for the car. When room becomes available, another massage should be printed. When a car departs, the massage should include the number of times the car was moved within the garage (including the departure itself but not the arrival), this number is 0 if the car departs from the waiting line. "

Can anybody please tell me where to start with......It should be done using stacks and queues. If you can submit a code that would be even great
 
Old 06-02-2013, 10:11 AM   #2
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
Please read the forum rules.
We are happy to help you if you get stuck, but we're not going to do your homework for you.

Cheers.
 
Old 06-02-2013, 10:51 AM   #3
Thilinamc
LQ Newbie
 
Registered: Jun 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Cool

Quote:
Originally Posted by gdejonge View Post
Please read the forum rules.
We are happy to help you if you get stuck, but we're not going to do your homework for you.

Cheers.
Hey,

I'm not asking anyone to do any homework for me.... I'm just asking where to begin with , in coding this in to a program... Hope you understand what I'm trying to do here..

Cheers mate....
 
Old 06-02-2013, 03:01 PM   #4
archShade
Member
 
Registered: Mar 2006
Location: Delft NL
Distribution: Debian; Slackware; windows 7
Posts: 218

Rep: Reputation: 53
This really sounds like you are asking the LQ community to do your homework. You have already worked out that you need to use queues and stacks. A quick google gets you here.

http://docs.python.org/2/tutorial/datastructures.html

You may want to implement a class car with fields UID, arrive, and depart

Also it's worth having a better name, I imagine there 100's of threads in LQ about python.


PS: Don't take this a criticism but there are some quite major English mistakes in your post:
  • It's a computer program (regardless of British or US English).
  • It's message not massage (unless the program is meant to rub your skin to tell you the output).
Like I said not wanting to complain about your English, if you go though my posting history you will probably find much worse. I would not mention it is I had not made earlier points.
 
Old 06-02-2013, 03:20 PM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by Thilinamc View Post
Can anybody please tell me where to start with......It should be done using stacks and queues. If you can submit a code that would be even great
1) "Where to start": Same as any program:
a) Make sure you understand exactly what the program is supposed to do, including obscure case (see below).
b) Figure out how to divide the big project you have into smaller projects.

2) "It should be done using stacks and queues": The data structure needs in your problem are pretty trivial. I don't happen to know the exact definition or capabilities of available Python data structures, but almost any list-like structure should get the job done (since the scale is too small to care about efficiency).
But why did you say "stacks". A stack is fundamentally LIFO (if you don't know that, look up stacks and LIFO and learn it). If you did know that, what part of the problem looks LIFO to you?

3) "If you can submit a code that would be even great": LQ rules and culture discourage us from doing that for homework and even more so discourage you from asking. Please don't ask that again.

Question about the intended behavior of the program:
With the 10 slots filled and 3 more waiting, a car with 3 in front of it is removed. Does that mean
a) The 3 cars in front cycle around to the 7'th, 8'th and 9'th positions, while one of the 3 waiting fills in as 10'th
or
b) The 3 cars waiting get into 7'th, 8'th and 9'th position, while the previous 1st becomes 10'th and the previously 2'nd and 3'rd are now waiting outside.

I think the problem statement implies (a) not (b) but I'm not sure. I always try to spot and decide the obscure cases before I start to design my data structures. Obscure cases often have a big influence on the correctness of the data structure design.

Quote:
Originally Posted by Thilinamc View Post
the massage should include the number of times the car was moved within the garage
If I understand the problem correctly, every time any car departs every car in the garage moves. So the number of moves would be equal to the number of departures after that car first entered the garage, up to and including the time it was the one departing. That feels like a strange request. Strange requests always make me think the person specifying the problem has not communicated what he meant. Probably that is over thinking it. But in the classroom and even more so in real software engineering, the person creating the specification has usually made mistakes. If you have an opportunity to keep the other guy's mistakes from becoming your fault, do so. Sometimes all that takes is asking him a question.

Last edited by johnsfine; 06-02-2013 at 03:30 PM.
 
Old 06-02-2013, 03:36 PM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636
Quote:
Originally Posted by Thilinamc View Post
Hey,
I'm not asking anyone to do any homework for me.... I'm just asking where to begin with , in coding this in to a program... Hope you understand what I'm trying to do here..
Cheers mate....
Well given the problem description, asking for the code in this phase is more or less like looking at a pile of wood and asking for a saw while you have no idea what you are building.

First step is to analyze the problem. And I mean really drawing a parking space and car on a piece of paper and analyze all possible movements of cars arriving, departing and parking.

Then the next step is to how you want to keep track of positions and movement. What kind of data structures you will be using. How to access that data in case you need to know which cars are waiting, parked or departed. What data will you store? License plate, number of movements, time stamps?

Next, what operation will you do on which data? What happens when a car arrives? Which data will be altered? What happens if a car is moved from the waiting queue to the parking lot? Will data be moved? Will data be flagged? You have to make decisions here whether your setup will be procedure oriented or object oriented.

Only after you have analyzed the problem, defined the data structures, the operations on the data structures and objects if applicable, you are able to look into a programming language and coding.

Immediately after this, or even before, you have to design your test vectors. A certain number of test cases where you go thru the process while you know exactly the each step and state of your process.

Only then you can code and test.

I wonder if they don't teach such an approach anymore.

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 09:30 PM
best programme new.. elamina Linux - Software 1 05-14-2009 11:04 AM


All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration