标题:C语言,如何多维数组输出时,无值的地方显示空白?
只看楼主
eileenliai
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2015-10-20
得分:0 
zhe ge ti de  wan zheng ban ben jiu shi zhege!!!!


Task

You have to write a program that will act as a ticket booking system for trains. The user will enter the origin and destination train stations then the system should work out if there is a direct train between the two stations. If there is, it should check to see if there are enough free seats left on that train. If there are, the seats should be reserved for that booking and should display the cost of the tickets. The program can also show the remaining tickets for each available route. The program will be driven by a simple menu system.

The stations and available trains are shown in the following table. The origin station is on the left and the destination station is on the top. If there is a number in a cell, that is the distance in km that the train has to travel. If there is no number then that means there is no train running on that route.

Ningbo    Hangzhou    Suzhou    Changzhou    Shanghai    Taizhou    Wenzhou    Jinhua    Nanjing
Ningbo        155                380            
Hangzhou    155            210    180            180    280
Suzhou                95    90               
Changzhou        210    95                        130
Shanghai        180    90                        
Taizhou    380                        610        
Wenzhou                        610        235   
Jinhua        180                    235        
Nanjing        280        130                    
Stations are numbered, from 1, in the order they appear in the rows of the table.

When the program starts, the user should be shown a menu of the available actions and prompted to enter one:
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option:
      
If the user enters option 1, the program should print a list of all the station numbers and their names, then print a prompt asking the user to enter the origin station number, then a prompt asking the user to enter the destination station number. The station list should have a header with Num and Station column names, separated with a tab. The rows should be the station number and then the full station name, separated with a tab. See the examples below for the exact formatting.

After prompting the user for the origin station, you should check the input is a number that appears in the list. If not, you should print the error message "Invalid station number." and go back to the main menu. The same check should happen after the destination station number has been entered. If there is no train from the origin to the destination then the program should display "No train between X and Y." where X is the origin station name and Y is the destination station name, and return to the main menu.

Next, the program should ask the user for the number of tickets required. You should check the input is greater than zero, otherwise display the error message "Invalid number of tickets." and go back to the main menu. After the required number of tickets has been validated, the program should check if at least that number of tickets is still available for that journey. When the program starts, all train routes have 10 tickets available each (your program should not make any attempt to remember how many tickets are available between runs; always start with 10 when the program runs). If there are not enough tickets left display the error message "Not enough tickets available (X requested, Y reminaing)." where X is the number of tickets the user entered and Y is the number of tickets actually available.

Finally, if there are enough tickets available the program should reduce the number of available tickets by the amount the user requested and print a message containing the cost of the tickets. The cost is calculated in the following manner — the cost of a single ticket is 300 RMB for a journey over 500km, 200 RMB for a journey over 250km, and 100 RMB otherwise; the total cost is the single ticket price multiplied by the number of tickets. The message displayed should be "Tickets booked, total cost is X RMB." where X is the total cost calculated above. After this the program should return to the main menu.

If the user enters option 2 at the main menu then the program should print a table showing the number of tickets remaining for each train route. The table should have the names of the stations along the top row, then each row showing the origin station at the beginning of the row and the appropriate number of remaining tickets of each destination station at each cell across the row. Cells should be tab-separated. If no route exists between two stations then nothing should be shown in the cell. In order to maintain the layout of the table, the station names are limited to 6 characters. If the station name is longer then it should be truncated to 6 characters. See the examples for a demonstration of the exact layout. After the table has been printed the program should return to the main menu.

If the user enters option 3 at the main menu then the program should exit with no further output.

If the user enters a different number at the main menu then the program should print "Invalid option!" and return to the main menu.

See the examples below for the rest of the specification of the required text and layout of the prompts and messages. Your program should look exactly the same as the examples for the values entered in them, including spacing, capitalisation, and punctuation.

Example input/output

Example 1:
[zlizpd3@cs-linux ex2]$ ./trainbooking
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 2
    Ningbo    Hangzh    Suzhou    Changz    Shangh    Taizho    Wenzho    Jinhua    Nanjin   
Ningbo        10                10               
Hangzh    10            10    10            10    10   
Suzhou                10    10                    
Changz        10    10                        10   
Shangh        10    10                           
Taizho    10                        10            
Wenzho                        10        10        
Jinhua        10                    10            
Nanjin        10        10                        
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 1
Num    Station
1    Ningbo
2    Hangzhou
3    Suzhou
4    Changzhou
5    Shanghai
6    Taizhou
7    Wenzhou
8    Jinhua
9    Nanjing
Origin station number: 3
Destination station number: 5
Number of tickets: 4
Tickets booked, total cost is 400 RMB.
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 2
    Ningbo    Hangzh    Suzhou    Changz    Shangh    Taizho    Wenzho    Jinhua    Nanjin   
Ningbo        10                10               
Hangzh    10            10    10            10    10   
Suzhou                10    6                    
Changz        10    10                        10   
Shangh        10    10                           
Taizho    10                        10            
Wenzho                        10        10        
Jinhua        10                    10            
Nanjin        10        10                        
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 3
[zlizpd3@cs-linux ex2]$
Example 2:
[zlizpd3@cs-linux ex2]$ ./trainbooking
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 5
Invalid option!
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 2
    Ningbo    Hangzh    Suzhou    Changz    Shangh    Taizho    Wenzho    Jinhua    Nanjin   
Ningbo        10                10               
Hangzh    10            10    10            10    10   
Suzhou                10    10                    
Changz        10    10                        10   
Shangh        10    10                           
Taizho    10                        10            
Wenzho                        10        10        
Jinhua        10                    10            
Nanjin        10        10                        
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 1
Num    Station
1    Ningbo
2    Hangzhou
3    Suzhou
4    Changzhou
5    Shanghai
6    Taizhou
7    Wenzhou
8    Jinhua
9    Nanjing
Origin station number: 1
Destination station number: 1
No train between Ningbo and Ningbo.
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 1
Num    Station
1    Ningbo
2    Hangzhou
3    Suzhou
4    Changzhou
5    Shanghai
6    Taizhou
7    Wenzhou
8    Jinhua
9    Nanjing
Origin station number: 1
Destination station number: 2
Number of tickets: 12
Not enough tickets available (12 requested, 10 remaining).
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 1
Num    Station
1    Ningbo
2    Hangzhou
3    Suzhou
4    Changzhou
5    Shanghai
6    Taizhou
7    Wenzhou
8    Jinhua
9    Nanjing
Origin station number: 1
Destination station number: 2
Number of tickets: 4
Tickets booked, total cost is 400 RMB.
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 2
    Ningbo    Hangzh    Suzhou    Changz    Shangh    Taizho    Wenzho    Jinhua    Nanjin   
Ningbo        6                10               
Hangzh    10            10    10            10    10   
Suzhou                10    10                    
Changz        10    10                        10   
Shangh        10    10                           
Taizho    10                        10            
Wenzho                        10        10        
Jinhua        10                    10            
Nanjin        10        10                        
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 1
Num    Station
1    Ningbo
2    Hangzhou
3    Suzhou
4    Changzhou
5    Shanghai
6    Taizhou
7    Wenzhou
8    Jinhua
9    Nanjing
Origin station number: 5
Destination station number: 3
Number of tickets: 1
Tickets booked, total cost is 100 RMB.
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 2
    Ningbo    Hangzh    Suzhou    Changz    Shangh    Taizho    Wenzho    Jinhua    Nanjin   
Ningbo        6                10               
Hangzh    10            10    10            10    10   
Suzhou                10    10                    
Changz        10    10                        10   
Shangh        10    9                           
Taizho    10                        10            
Wenzho                        10        10        
Jinhua        10                    10            
Nanjin        10        10                        
1) Book ticket(s)
2) List available tickets
3) Quit
Enter option: 3
[zlizpd3@cs-linux ex2]$
2015-10-20 21:40
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
得分:0 
1.你剛學一星期多,是不可能完成這個作業的。
2.你設計的這個方案,簡單粗暴,初學者想出來,還算可行,不過不是正解,將來要大改。
3.這個代碼,肯定很多錯誤,一眼掃下去就知道編譯都成問題,前面還說有些部分做好了。

授人以渔,不授人以鱼。
2015-10-20 21:41
eileenliai
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2015-10-20
得分:0 
回复 13楼 TonyDeng
wo我明天要交作业le,,,,,zhe ge shi 我 men de 作业, 虽然 新的学期 has been started for a quite long time, but i was one of them who transferred out major(转换专业) in to computer science
2015-10-20 21:48
eileenliai
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2015-10-20
得分:0 
回复 13楼 TonyDeng
这是我们的作业,da shen!!!看在我  所有的chinese都来自  百度翻译 的份上,please help me
2015-10-20 21:51
eileenliai
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2015-10-20
得分:0 
回复 13楼 TonyDeng
我不期望它可以现在很完美的,我只是希望它  的错误   能解决  可以编译成功,,我可以知道how,以及为什么我犯了错误..
2015-10-20 21:56
eileenliai
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2015-10-20
得分:0 
回复 17楼 边小白
but c is very fundamental , so we have to learn this.
2015-10-20 21:57
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
得分:0 
你不到交作業前一刻,都不來求助,現在怎麽幫?真以爲“大神”都是曹子建,七步成詩啊?何況我用的Windows+vs,你用Linux+gcc,幫不了你,因爲我寫了你也改不到你那裏去。

授人以渔,不授人以鱼。
2015-10-20 21:58
eileenliai
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2015-10-20
得分:0 
回复 20楼 TonyDeng
不到交作业前那一刻是没到这里来求助,不会的也问了人了,自己试了很多,但是知识有限无法解决,最后才会找到这里来问。

并不是拖到最后一刻什么都不做,叫您大神是因为觉得你知道的很多掌握的知识很多觉得尊敬佩服才那么叫的。

而且也是觉得你很厉害才想向你求助的。

你如果觉得我是不值得帮的人就罢了,为什么要这么说呢。
2015-10-21 01:53
eileenliai
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2015-10-20
得分:0 
回复 20楼 TonyDeng
您如果能帮我看看问题我从linux里是可以通过邮件转到windows里的。

不管怎么样还是谢谢你的回复了。
2015-10-21 01:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-458356-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.831066 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved