Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I am taking a C++ program class and do not understand what I am doing and my instructor is no help so that is why I am here. I just can't seem to grasp any concepts and I don't know why. Can someone please help me with this:

Bluebird Airlines has flights from Phoenix to six other cities in Arizona. The
cities are referred to by number,1 to 6.The price for a round-trip ticket to each of
the cities is shown here.

City 1 2 3 4 5 6

Price 56.79 105.69 93.49 155.99 87.49 73.99

Write a program that computes the total price of tickets that a customer orders.
The program should prompt the user for the number of the destination city and
the number of tickets desired.If the user enters an invalid city number,the pro-
gram should display an error message and terminate.The program should display
the total price of the ticket order.Use an array to store the ticket price table.

Any help would be greatly appreciated.

Thanks,

Mary :)
Posted
Updated 21-Feb-14 15:36pm
v2
Comments
[no name] 21-Feb-14 22:05pm    
Do you have a plan or are you just going to dump it in someone else's lap? Have you compiled and run a "Hello world" program?

First of all you need to understand the task at hand.

  1. write the use cases in your own words, e.g.

    Normal Use Case

    • start the program on the command prompt (this is not a program that shows a graphical user interface but only asks some user input from the command prompt), e.g.
      Please enter a city code in the range 1 to 6: _

    • enter a number between 1 and 6 (representing one of the available cities), e.g.
      Please enter a city code in the range 1 to 6: 3
      Please enter the number of tickets in the range 1 to 20: _
    • enter a number between 1 and say 20 (representing the number of tickets to buy)
    • the program calculates the total price of the tickets to the selected city, e.g. double total = getTicketPrice(cityId) * numberOfTickets
    • the program displays the result, e.g.
      Please enter a city code in the range 1 to 6: 3
      Please enter the number of tickets in the range 1 to 20: 2
      
      The total price of the 2 tickets to 'city 3' is 2 x 93.49 = 186.98




    Error Use Case

    • start the program on the command prompt, e.g.
      Please enter a city code in the range 1 to 6: _

    • enter a number that is out of range, e.g. 0 (or -3, or 7, or 100)
      Please enter a city code in the range 1 to 6: 0
    • the program reports an error and terminates, e.g.
      Please enter a city code in the range 1 to 6: 0
      
      Error: You entered a city code that is out of range. Please enter a code in the range 1 to 6.


  2. Translate the use cases into some pseudo-code (some data structures and control flow that mimics the use cases), e.g.
    ticketPrice is array with values 56.79 105.69 93.49 155.99 87.49 73.99, each position represents one city: first = ticket price for city 1, second = ticket price for city 2, etc.
    
    set maxCityCode to the number of elements in the array
    
    write to the console: Please enter a city code in the range 1 to maxCityCode: 
    
    read some number from the console and store in cityCode
    
    check if the entered code is in the range 1 to maxCityCode and if out of range, write the above mentioned error message to the console and exit the program with error code
    
    write to the console: Please enter the number of tickets in the range 1 to maxTickets: 
    
    read some number from the console and store in tickets
    
    optional: check if the entered number is in the range 1 to maxTickets and if out of range, write some error message analogous to the one above and exit the program with error code
    
    calculate: price = the ticketPrice entry for cityCode
    
    calculate: totalPrice = tickets times price
    
    write to console: The total price of the tickets tickets to 'city cityCode' is tickets x price = totalPrice
    
    exit the program with success code
  3. translate this into C++ (read any basic tutorial on Hello World C++ programs - they contain all you need to know about C++ for this homework assignment)
  4. test and fix and test...


Have fun!
Cheers
Andi
 
Share this answer
 
v3
Comments
mjlohr0033 21-Feb-14 23:45pm    
Thanks for your help, Andi. I hope I get on to this soon. I guess maybe you have to have an inborn talent for programming or something. :)

Mary
Andreas Gieriet 22-Feb-14 4:04am    
There is nothing magic about it. If you really want to learn any profession or craft, you have to go through an education and practice, practice, practice. If you want to get to higher proficiency level, you need to learn, practice, practice, practice. It helps very much if you have a minimal level of enthusiasm and curiosity to try new things out. You see, software development (which is much more than the mere writing of code in some computer language) consists of several aspects that you need to master to reach excellence. Eveyone starts with a first step. Have the courage to make your own first steps! Learn to first understand the problems and only then start to "carve" a solution for it. Only when you have outlined that solution, start to think about coding it in some computer language. Document your findings. Make your hands dirty with testing. Be persistent: take the mantra "what you didn't test doesn't work" ;-)
Have fun!
Cheers
Andi
SoMad 22-Feb-14 1:11am    
I think that is very helpful. :thumbsup:

Soren Madsen
Andreas Gieriet 22-Feb-14 4:08am    
Thanks!
Cheers
Andi
Usman Hunjra 22-Feb-14 11:26am    
+5 .. :)
Quote:
I just can't seem to grasp any concepts and I don't know why.
Then how could we know?

Here we answer specific questions which members face during programming.
If you face any difficulty while coding, feel free to come back here and ask another question with specific issue describing the scenario.

Members will be happy to help you then. :)
 
Share this answer
 
Comments
mjlohr0033 22-Feb-14 7:52am    
Thanks everyone for your input and help. Every comment has some very valuable points. I really do appreciate your input and will apply each and every one of them.

Thanks again!!

Mary ;)
Most welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900