![]() |
|
#1
|
|||
|
|||
c prog problem. i need help pro's!!!i have a problem with this question,
can anyone offer me a solution for this. a c prog question... im really lost in this field... question : Write a program that will repetitively read and calculate the parking charge to be paid by customers in a day. The program will stop when the users decide not to continue. The charge is based on the following table: Vehicle Rate Car First 1 hour (or part of it) : $2.00 Every subsequent hours (or part of it): $1.00 Bus First 1 hour (or part of it): $3.00 Every subsequent hours (or part of it): $1.50 Please incorporate appropriate input validation in your program |
|||
|
#2
|
||||
|
||||
Re: c prog problem. i need help pro's!!!Quote:
__________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
|
#3
|
|||
|
|||
Re: c prog problem. i need help pro's!!!Quote:
Do you want a C program or a C++ program? Your title says "C," but this is a C++ forum. I just want to make sure of what you're asking. The requirements are unclear to me. It seems to be saying that the program should: continuously loop until the user quits calculate the total parking revenues based on vehicle types and durations parked accept input (read) --assumed that this means accept vehicles for parking Here's what I got from your requirements: CPP / C++ / C Code:
Output: Code:
Note that I basically abort on any undesired input, so you may want to modify some elements of that kind of behavior in your code. Hopefully this will get you started on your own code. Read the blasted guidelines! I know that WaltP must get very tired of telling every newcomer the same thing over and over and over and over and over and over^999. :davis: |
|
#4
|
||||
|
||||
Re: c prog problem. i need help pro's!!!What? A mod is giving someone a full code solution?
|
|
#5
|
||||
|
||||
Re: c prog problem. i need help pro's!!!Quote:
__________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
|
#6
|
|||
|
|||
Re: c prog problem. i need help pro's!!!Hello,
I have written a code in C++ which calculates the parking fee and finds the totally revenue earned on termination of loop. The program works like this: 1) prompts user to enter vehicle type car('c') or bus ('b'). 2) On entering the vehicle type another prompt asks whether vehicle is leaving or entering. 3)If the vehicle is entering the vehicle number gets stored in array along with the time of parking. ex: car[carnum] = carnum; where car[1000] is an array and carnum is the number of car. 4) On choosing exit as an option the user is prompted to enter vehicle number.If the vehicle number exists in the array then the timer difference is calculated and parking fee is calculated. The array is cleared ex: car[carnum] = 0; 5)If the user terminates the loop then total revenue is calculated from total revenues got from car parking and bus parking fees. My code: CPP / C++ / C Code:
The output for this code looks like this: Enter the type of vehicle : 'c' -> CAR 'b' -> BUS c entrance or exit: 'x' -> EXIT 'e' -> ENTRANCE e Enter 'y' to exit the loop or 'n' to continue: n Enter the type of vehicle : 'c' -> CAR 'b' -> BUS c entrance or exit: 'x' -> EXIT 'e' -> ENTRANCE x Enter the car number 1 DAY: 22-Aug-2006 TIME OF EXIT: 15:52:04 The parking Time for car no 1 = 8 seconds arking charge for car no 1 = 2 $ HAVE A NICE DAY!!! The current revenue from car parking fees = 2$ Enter 'y' to exit the loop or 'n' to continue: y DAY: 22-Aug-2006 TIME 15:52:33 Today's total revenue = 2$ On substituting printf (for cout) , scanf( for cin) wherever they are used the program can be converted to c coding as I hav'nt used much of C++ concepts. I am sorry I am unable to align this code.Even after alignment it goes back to same state.Sorry If I am breaking any rules. Thank You, Regards, Rajeev Last edited by LuciWiz : 22-Aug-2006 at 07:32.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#7
|
|||
|
|||
Re: c prog problem. i need help pro's!!!I know I am not a mod but I have to comment: pls use C tags for your code. And for the record: horizontal spacing is good, too much vertical spacing is bad!
CPP / C++ / C Code:
__________________
Michael Dual Opteron 280 (2 x dual core) with 2Gb RAM, 2x36GB system drives, 2T on 3Ware 9500Mi RAID controller. Running Fedora Core 4. Using Anjuta IDE. Developemnt in C++ with MySQL (via mysql++). |
|
#8
|
|||
|
|||
Re: c prog problem. i need help pro's!!!hello,
I have finally formatted code.Hope it is in readable format. My code: Quote:
The output for this code looks like this: Enter the type of vehicle : 'c' -> CAR 'b' -> BUS c entrance or exit: 'x' -> EXIT 'e' -> ENTRANCE e Enter 'y' to exit the loop or 'n' to continue: n Enter the type of vehicle : 'c' -> CAR 'b' -> BUS c entrance or exit: 'x' -> EXIT 'e' -> ENTRANCE x Enter the car number 1 DAY: 22-Aug-2006 TIME OF EXIT: 15:52:04 The parking Time for car no 1 = 8 seconds arking charge for car no 1 = 2 $ HAVE A NICE DAY!!! The current revenue from car parking fees = 2$ Enter 'y' to exit the loop or 'n' to continue: y DAY: 22-Aug-2006 TIME 15:52:33 Today's total revenue = 2$ Thank You, Regards, Rajeev |
|
#9
|
|||
|
|||
Re: c prog problem. i need help pro's!!!If this is some kind of an assignment for a class, it seems strange to me that you would want to actually log the time in and out for each vehicle. Naturally, in a real parking garage that would occurr, but who is going to sit at a student programmer's application for several hours so that the bill can be validated if the vehicle says in more than 1 hour, more than a day?
CPP / C++ / C Code:
I've nested some comments in your code. Basically, you could rewrite the program so that it has functions that take ARGUMENTS so that you don't have so much duplicity in your code. Your use of a fixed sized array and failure to check the bounds of it when you blindly add a new vehicle to the array is commonplace among novice programmers. Your application design says that the parking facility can accept 1000 cars and 1000 buses. You do not allow for 1500 cars and 500 buses, which in real life would suggest the possibility of missed revenue for the "day," which isn't being calculated on a daily basis, though is not necessarily stated in such words in the requirements. Since the size of the parking facility was never limited in the requirements, your bounded arrays unnecessarily limit it. Please do not use non-standard functions and headers in your code. conio.h and clrscr are not part of ANSI or ISO C. We want everyone to learn to C properly You use a number of global variables in your code. Don't, unless you have a really good reason. We don't mix C and C++ headers in the manner that you've chosen. If the file is a C++ file, then we use #include <cstdio> for example and not #include <stdio.h> Your code tends to do too much in each of car and bus functions. This is similar in design to the "main does everything" kind of programming style. However, your code is simply one layer removed from main. Ideally, the code would simply add a vehicle of type bus or car to an appropriate storage type and produce an "entry" timestamp that follows the "vehicle" type. For example: CPP / C++ / C Code:
Now we can happily add as many vehicles of any declared type(s) to an array of VEHICLEs and realloc as necessary to keep from exceeding the bounds of our limiting array dimensions. Also, we can segment the program into some logical functioning blocks that separate "roles and responsibilities" better. On event vehicle entry, we punch in the t_enter timestamp, denote the type and add the structure to an array or linked list. On event vehicle exit, we punch the t_exit timestamp, difference the times and calculate the rate based on our rate rules. By partitioning the application, we gain flexibility in making changes to it and making it easier to read and understand. Also, this piecemeal approach is a divide and conquer method that lets us focus on doing more simple tasks in a small section of code that can easily be independently tested and verified. Large "monolithic" functions tend to be cluttered, confusing and difficult to read, write and test. Changing monoliths are difficult at best, though in your case in this code, it is not terribly severe since the application is trivial at best. However, these lessons are better learned as soon as possible rather than later in life. In other words, do not try to do too much in one function. Let me know if you'd like for me to post a "refactoring" of your code to give you a better idea of what I'm going on about. :davis: |
|
#10
|
|||
|
|||
Re: c prog problem. i need help pro's!!!Hi,
Thank you for the review.I was just giving a rough solution for the problem,so my aim was just to write a code which would calculate the parking charge on a continous basis. Although I do agree with the fact that function for bus and car could combined under one so that length of code could be reduced. But regarding limiting size of storage to 1000,I dont agree.Since whenever a vehicle moves out the value in the array coressponding to that vehicle is cleared back to zero. For ex: every time a car exits car[carnum] = 0 array is cleared. If the number of cars reaches it's maximum limit then the array which gets cleared can be used to store (although I have'nt made it part of the code). This code was just a crude example.I need to make further changes.Please post your version of code so I get a better understanding. Thank You, Regards, Rajeev |
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Graphic problem in Unreal Tournament 2004 | zerox | Computer Software Forum - Games | 10 | 09-Oct-2005 12:31 |
| Runtime Problem involving "printf" in C Program | supamakia | C Programming Language | 2 | 09-Oct-2005 10:09 |
| a significant problem after installing Xp | mohammad | Computer Software Forum - Windows | 10 | 09-Aug-2005 07:03 |
| Another FX 5600 problem (but with details that might shed light on this) | BobDaDuck | Computer Hardware Forum | 2 | 16-Apr-2004 07:53 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The