![]() |
| ||
| airplane seating prices hi, I'm working on a project and I'm almost done. However, I'm having a few problems with the prices. this is the guide for the project: Airplane Seat Allocation System Write a C++ program for the following task using modular approach. a) 48 seats in 12 rows with a Aisle in the center. Seats at end of each row is a “Window Seat�. The middle two seats in a row are “Aisle� seats and 4 Seats in row one are “Leg Room� Seats. b) The program should display the seat plan. c) Display a welcome greeting , d) Menu driven program to allow request for, ‘Window’, ‘Aisle’ and ‘Leg Room’ Seats, display seat # and block (if available). If the seats are not available in existing category, display a sorry message. e) Provide a ‘Quit’ facility to exit from the program. AND THIS IS MY CODE SO FAR:
I tried to set different prices for the seats but I don't know how to work around the array problem. what I mean is that, how can I put these different prices in dirrent arrays and have them added up and stored inthe totalsales function? I also don't know how to separate the column so that it would have an aisle down the middle. Can you please help? Thanks in advance, Karen |
| ||
| Re: airplane seating prices For displaying the aisle, you can either write a string with spaces in it, " " or a tab character, "\t" in your seat display couts. Edit: I'll be back later. Gotta catch a bus. |
| ||
| Re: airplane seating prices Quote:
|
| ||
| Re: airplane seating prices hi, just in case I didn't sound very clear with the original post, I'd like different prices for different types of seatings (i.e aisle seats would cost $5, window seats $10) I only did the row prices because I don't know how to do the types prices......I'm rambling... Ok what I WANT is that I want each type of seating has its own price. Also the prices can't be preset, the program has to asks the user to enter their prices. So, instead of asking the user to "enter the price for Row 1 (or 2, 3....12), it would ask the user to "enter the price for <W>indow seats, <A>isle seats.... that's why I'm thinking that I have to save this in an array or a function so that the total can be calculated. And This PART I don't know how to do, because it links with other functions. Did I make myself clear to you? Sorry, I'm not very well with words. Can you please help? Thanks, Karen |
| ||
| Re: airplane seating prices something like.... #include <iostream> |
| ||
| Re: airplane seating prices Quote:
your code looks really complicated to me. I didn't learn about #include <limits> yet, nor cerr, nor...this "cin.ignore(numeric_limits<streamsize>::max(),'\n');" do you know a less-advanced way of doing this? sorry, karen |
| ||
| Re: airplane seating prices OK, I'll explain it a little. GetInput takes a string to print to the console and returns an int that was entered. If there is a bad input then an error message is printed and the garbage removed from the stream so we can try recieve input again. When for instance cin is expecting an int but gets a char it goes into a failed state. All operations on a failed stream are null and void so first we must clear the error flags. This is what the cin.clear does. After that we can proceed to remove any garbage entered. The cin.ignore line basically says ignore as many chars as you can from the stream or up to the next newline char.This lets us proceed to getting an int from the user. Back in main we declare an int and initialise it with the return value of GetInput. Need any further elaboration? |
| ||
| Re: airplane seating prices Hi, while waiting for help, I help myself a bit (LOL that sounds so akward). ANYWAY. Instead of the original code, which is to ask for the price of 12 rows: //initialize seat prices for each of the 12 rows for (int i = 0; i < 12; i++) { cout << "\nPlease enter ticket price for Row " << i + 1 << ": "; cin >> ticketPrice [i]; } I changed it to this:
and now I have to find a new way to display this in the DisplayPrices () function, and I don't think I did it right. void DisplayPrices(float seatprices[], float seattypes[]) can you tell me what I did wrong in the code above? Karen |
| ||
| Re: airplane seating prices Quote:
anyway, I just posted my new code. Can you check that out and give me suggestions? |
| ||
| Re: airplane seating prices btw. add #include<string> to top of that code. Forgot that. Your code is incomplete. If you post a complete example I can look over in my compiler then i'll take a look. I would urge you to at least check out the string type rather than use char arrays. Always remember main never returns void. It always returns int.Your loops look messy.Stick to the KISS principle and you wont go far wrong. |
| ||
| Re: airplane seating prices Hi, This is my complete code: //Airplanes Seating Allocation System yeah, I'm aware that's it's a bit (ok, a lot) messy. But since I'm a beginner, I don't know how to take any other shortcuts. Can you take a look at the DisplayPrices() and the PurchaseTickets() functions? I post my questions there as well. thanks a lot, Karen |
| ||
| Re: airplane seating prices I looked at your code. It really could benefit from a rewrite. I got this far then had to go out so rest left as exercise for you. see how you do. Post later what you come up with and ill look it over. // You have shown enough effort for me to help you rewrite thisYou will still need to write the bits I left as an exercise and also add any more functions you deem necessary. Its reasonably simple stuff but some of it you may not have come across yet. Try follow whats been done so far. It should be reasonably easy for you to finish it off. |
| ||
| Re: airplane seating prices OMG! You're asking me to rewrite my code, which I've spent days (over a week already) doing. Please don't be that cruel. i'm only a beginner and I've slaved over this project so much I can't bear to start over again. I looked over the code that you're written so far...and to be honest...I can follow it but I can't do that on my own...I have no idea what to do next! Can you please just help me with my code? with the parts where I got stuck on? Please? Right now, I've rewritten parts of it. and there is one mistake that I should mention. There are only 3 types of seats: leg room, Window, and aisle seats. There are no "regular seats" because airplanes have windows on both sides *duh*. My modification: the DisplaySeats() and the DisplayPrices() functions. My Problem: the PurchaseTicket() and the DisplaySales() functions. Since each type of seat has different prices, I've trying to ask for the user to enter the seattype and then the row and the seat numbers. I'm only able to code the program to ask for the row and seat numbers. Can you tell me what's wrong with my DisplayPrices() function? Why doesn't display anything when I tested it?
I'm so sorry I'm not any brighter at this. It's really hard to learn this stuff. Karen |
| ||
| Re: airplane seating prices You should really try to finish my code. I can help you so dont panic. There was too many errors in your original code to make it worthwhile to fix rather than rewrite. Also your design doesn't lend to code brevity. Notice in mine all the data you need to do any calculations is all stored in an array of structs. I gave in the comments a little info on structs, certainly enough for you to be able to grasp what i had written. Notice how it makes things easy and cuts down in general on the amount of loops you need to write.It enhances code readability and therefore makes it easier for you to understand.If there is any part of my code you dont understand just point it out and ill help. Try first to write the AllocSeat function. You ask for wanted seattype. You can then iterate the array for the first of that seattype whose taken member is also false. Set taken to true or call Sorry() and that ones done. There is a few examples of iterating that array of structs already in the code so that shouldn't phase you. There are also examples of comparing strings and assigning struct members. Most of the code is already written for you. Theres only a few funcs to add and maybe one or two to add a line to. Dont put yourself down for not being bright. I know quite a few people who describe themselves in that manner and some of those are very good coders. Slow and steady is better than fast and falling flat on your face. C++ is hard to learn, I wont lie to you but its not impossible to grasp the simple constructs I have shown you here. std::strings are a much easier type to work with than char array strings and should be taught before the latter. There is enough information in the code to allow you to use the struct array confidently. loops ifs and function calls are about all you need. If you can follow what I have written then you can finish it. I'll be around for about 4 hrs from time of this post. |
| ||
| Re: airplane seating prices OK, I took your advice and gave it a try. void AllocSeat(string type) This is my best (miserable) attempt. |
| ||
| Re: airplane seating prices now compare yours with mine. Ive changed a couple of things, displaying now displays row and seatnumbers. Sorry has gone. There are 2 overloads of AllocSeat. one lets you pick a specific seat and another a type of seat. Have you covered overloading of functions yet? Starting to see how this is coming together? // You have shown enough effort for me to help you rewrite this |
| ||
| Re: airplane seating prices Ok, I've compared yours with mine and they're not EVEN close to being similar to each other. I don't understand why you have 2 AlloSeat() functions, are you allowed to do that? How do we know which function to use in the main function? And no, I've learned about overloading functions yet. |
| ||
| Re: airplane seating prices OMG! My final (for another class) is in 30 min! I have to go to that class! When will you be gone? This airplane project is due tomorrow, cause tomorrow is my final in this C++ class! |
| ||
| Re: airplane seating prices yes you are allowed to do that its called function overloading. If we called it like this... string s="legroom"; AllocSeat(s); then the one that takes a string will be called. This will automatically search for the first available seat of that type and allocate it. I should have added a message telling you seatnumber and row, you can do that i am sure. Alternatively if we call it like so int row,seatnum; cout<<"enter row and seatnumber separated by a space"<<endl; cin>>row>>seatnum; AllocSeat(row,seatnum); then that overload will try to take the specific seat pointed at by row/seatnum. So you should now be able to write a function that asks user whether he would like to pick a seat or auto get one and call the correct overload of AllocSeat. Again dont panic, I know this is due soon but we will get it done and my hope is I teach you a little something on the way too. |
| ||
| Re: airplane seating prices maybe 2.5 hrs more. then 8 hrs sleep then on for a bit before work over brekkies. |
| ||
| Re: airplane seating prices 'K I'll try to have everything done (hopefully not too many misktakes) tonight. When can you check it tomorrow? karen |
| ||
| Re: airplane seating prices here I cleaned it up a bit and added some while smoking a joint. Theres not much left for you to do now. Make sure you understand everything. If you are not sure then ask. // You have shown enough effort for me to help you rewrite this |
| ||
| Re: airplane seating prices gotta go work now so heres how mine looks finished. // You have shown enough effort for me to help you rewrite thisDid you manage to make those changes on your own? Anything you didn't understand? |
| ||
| Re: airplane seating prices Hi, Stone_Coder; thank you so much for helping me out. I don't know if this is hard work for you or not (prob not), but it was certainly was for me. And I'm glad that you help me through it. Now I'm not going to lie and say I understood your code. I said I can follow it, not nessarily understood everything. Now that the class is over and it's not rushed, I'm going to go through your code slowly. And it might take me a bit of time to digest everything. So if I'm not posting my questions right away yet, please don't think I'm abandoning it because the project's over and done with (plus I don't think you'd appreciate it if I post everything question I have, 'cause it's quite a lot). When you said "hopefully" you'd teach me something along the way, you don't know how right you are! I certainly learn a lot from doing this, both from my own experience and from your help. Oh, I forgot. My PurchaseTicket() function, again, did not look like yours at all. I keep having problems with the structure data thing. And I couldn't get it linked to the DisplaySales() functions. But I understand what I did wrong now...I think. ;) So I know I said it alot already, but Thanks again! Karen |
| ||
| Re: airplane seating prices And for those who weren't aware of the cross-posting, there's this: http://www.gidforums.com/t-6485.html Where else this may be I don't know. But it is always nice for the OP to tell others that the question may already be answered elsewhere. |
| ||
| Re: airplane seating prices yeah, I was about to do that tonight. I just got it done today. but thanks for the reminder though. |
| All times are GMT -4. The time now is 11:44 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC