我该怎么做这个程序? [英] How do I do this program?

查看:80
本文介绍了我该怎么做这个程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在上一个C ++程序课,不明白我在做什么,我的导师没有帮助,所以这就是我在这里的原因。我似乎无法掌握任何概念,我不知道为什么。有人可以帮我这个:



蓝鸟航空有从凤凰城到亚利桑那州其他六个城市的航班。

城市的编号是1到6.这里显示了每个城市的往返机票的价格。



City 1 2 3 4 5 6



价格56.79 105.69 93.49 155.99 87.49 73.99



编写一个程序,计算客户订购的门票总价。

该程序应提示用户输入目的地城市的号码和

所需的门票数量。如果用户输入无效的城市号码,pro-

克应显示错误信息并终止。该程序应显示

门票订单的总价。使用数组存储门票价格表。



任何帮助将不胜感激。



谢谢,



玛丽:)

解决方案

首先你需要理解手头的任务。



  1. 在你的用例中写下用例自己的话,例如


    普通用例



    • 启动程序在命令提示符下(这不是一个显示图形用户界面的程序,只是从命令提示符中询问某些用户输入),例如

      请输入城市代码范围1到6:_ 



    • 输入1到6之间的数字(代表其中一个可用城市),例如

      请输入1到6范围内的城市代码:3 
      请输入1到20范围内的门票数量:_

    • 输入介于1和20之间的数字(表示要购买的门票数量)
    • 该程序计算所选城市门票的总价,例如 double total = getTicketPrice(cityId)* numberOfTickets
    • 程序显示结果,例如

      请输入1到6之间的城市代码:3 
      请输入1至20范围内的门票数量:2

      '城市2张门票的总价3'是2 x 93.49 = 186.98








    错误用例



    • 在命令提示符下启动程序,例如

      请输入1到6范围内的城市代码:_ 



    • 输入超出范围的数字,例如0(或-3,或7,或100)

      请输入1到6:0范围内的城市代码

    • 程序报告错误并终止,例如

      请输入1到6范围内的城市代码:0 

      错误:您输入的城市代码超出范围。请输入1到6之间的代码。





  2. 翻译将用例转换为一些伪代码(模拟用例的一些数据结构和控制流),例如

      ticketPrice 是值为 56.79 105.69 93.49 155.99的数组87.49 73.99 ,每个位置代表一个城市:第一个=城市1的门票价格,第二个=城市2的门票价格等等。

    maxCityCode 设置为数组中元素的数量

    写入控制台:请输入1到 maxCityCode 范围内的城市代码:

    从控制台读取一些数字并存储在 cityCode

    中检查输入的代码是否在1到 maxCityCode 的范围内,如果输出范围,将上述错误消息写入控制台并退出程序,错误代码

    写入控制台:请输入1到 maxTickets范围内的票数

    读取一些数字来自控制台和商店的票据

    可选:检查输入的数字是否在1到 maxTickets 的范围内,如果超出范围,写一些类似于上面的错误消息并退出程序,错误代码为$ i

    计算:price = cityCode ticketPrice 条目

    计算:totalPrice = 门票价格

    写入控制台: 门票的总价'city cityCode '的门票是门票 x 价格 = totalPrice

    使用成功代码退出程序

  3. 将其转换为C ++(阅读有关Hello World C ++程序的任何基础教程 - 它们包含您需要了解的有关C ++的所有内容这个家庭作业)
  4. 测试和修复并测试......





玩得开心!

干杯

Andi


引用:

我可以似乎没有掌握任何概念我不知道为什么。

那我们怎么知道?



这里我们回答成员在编程时遇到的具体问题。

如果您在编码时遇到任何困难,请随时回到这里,并针对描述该场景的特定问题提出另一个问题。



各位会员很乐意为您提供帮助。 :)


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 :)

解决方案

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


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. :)


这篇关于我该怎么做这个程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆