| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1514 人关注过本帖
标题:赶快来看看吧
只看楼主 加入收藏
an163126
Rank: 1
等 级:新手上路
帖 子:95
专家分:0
注 册:2005-3-19
收藏
 问题点数:0 回复次数:13 
赶快来看看吧
编写一个程序,由用户输入一个数n,然后程序依次将n个0~100之间的随机数插入一个ArrayList中。然后计算他们的总和,并 求出它们的平均值(用浮点数表示) (航班订票系统) 一家小型的航空公司新近购买了一台计算机,打算用于自动订票系统。请编写一个程序为改公司唯一一架飞机的每次航班分配座位(该飞机的载客量为10人)。程序显示以下菜单“请按1预定头等仓”“请按2预定经济仓”程序为头等仓分配1~5号,为经济仓分配6~10号。用数组元素为0表示此座尚未预定,1表示已经预定。程序应当具有良好交流界面。
搜索更多相关主题的帖子: 订票 计算机 航班 系统 
2005-04-11 18:33
seiya
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2005-3-24
收藏
得分:0 

我靠着都不会呀!!! 给你一个吧。 using System; using System.Collections ;

class Ping { static void Main() { decimal P=0.00M; decimal M =0.00M; System.Random r=new Random (); ArrayList A=new ArrayList ();

Console.WriteLine ("please input a number:"); decimal a=decimal.Parse (Console.ReadLine ());

for(int i=1;i<=a;i++) { A.Add (r.Next (0,100)); }

// 察看A中的元素 for(int i=0;i<A.Count ;i++) { decimal N=0.00M; Console.WriteLine (A[i].ToString ()); //ArrayList的数据转换 N=decimal.Parse (A[i].ToString ());

// 求这几个数的和 M+= N; } // 求平均数 P=M/a;

Console.WriteLine ("这"+a+"个数的平均数为:"+P);

} }


2005-04-11 19:41
jacky
Rank: 1
等 级:新手上路
帖 子:104
专家分:0
注 册:2004-12-17
收藏
得分:0 

using System; using System.Collections; class Sum_Average { public static void Main() { int sum=0; float average=0.0f; Random r=new Random (); ArrayList myArrayList=new ArrayList (); Console.WriteLine ("你想算几个数的和,并求它的平均值:"); int iMax=int.Parse (Console.ReadLine ()); for(int i=0;i<iMax;i++) { myArrayList.Add (r.Next (0,100)); } Console.WriteLine ("这{0}个数是:",iMax); foreach(int pins in myArrayList) { Console.WriteLine (pins); } for(int j=0;j<iMax;j++) { sum+=(int)myArrayList[j]; } Console.WriteLine ("这{0}个数的和是:{1}",iMax,sum); average = (float)sum / iMax; Console.WriteLine ("这{0}个数的平均值是:{1}",iMax,average);

} } using System; public class book_ticket { public static void Main() { int[] A=new int[10]; int next; Console.WriteLine ("欢迎使用南方航空公司预订票系统:"); Console.WriteLine ("1预订头等仓:"); Console.WriteLine ("2预订经济仓:"); Console.WriteLine ("-1退出:"); do { Console.WriteLine ("请选择:"); next=int.Parse (Console.ReadLine ()); switch(next) { case 1: Console.WriteLine ("请输入座位号:(1-5)"); int next1=int.Parse (Console.ReadLine ()); if(A[next1-1]==1) Console.WriteLine ("抱歉...该座位{0}已被订.",next1); else A[next1-1]=1; Console.WriteLine ("座位{0}预订成功.欢迎下次再来!",next1); break; case 2: Console.WriteLine ("请输入座位号:(6-10)"); int next2=int.Parse (Console.ReadLine ()); if(A[next2-1]==1) Console.WriteLine ("抱歉...该座位{0}已被订.",next2); else A[next2-1]=1; Console.WriteLine ("座位{0}预订成功.欢迎下次再来!",next2); break; case -1: break; default: return; } }while(next!=-1);

} }

2005-04-12 11:49
冰封谷主
Rank: 4
等 级:贵宾
威 望:10
帖 子:226
专家分:20
注 册:2005-1-7
收藏
得分:0 
怎么不写注释呀,,

2005-04-14 08:05
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
三楼的第二个程序要在else后面加个大括号。
因为else后面有两个语句,不加的话第二个语句会被上面的if 语句执行

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-14 08:56
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 
很细心啊

2005-04-14 09:02
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
if(A[next2-1]==1)//这句解释一下
      Console.WriteLine ("抱歉...该座位{0}已被订.",next2);
     else
      A[next2-1]=1;//这句也解释一下
      Console.WriteLine ("座位{0}预订成功.欢迎下次再来!",next2);
谢谢,这样的方法我是想不出来啊

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-14 09:28
冰封谷主
Rank: 4
等 级:贵宾
威 望:10
帖 子:226
专家分:20
注 册:2005-1-7
收藏
得分:0 
if(A[next1-1]==1)
      Console.WriteLine ("抱歉...该座位{0}已被订.",next1);
     else
      A[next1-1]=1;
      Console.WriteLine ("座位{0}预订成功.欢迎下次再来!",next1);
这是什么意思,,,请高人指点

2005-04-14 09:35
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
哈。谷主和我想法相同啊。

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-14 09:37
冰封谷主
Rank: 4
等 级:贵宾
威 望:10
帖 子:226
专家分:20
注 册:2005-1-7
收藏
得分:0 
呀,,,看来我们都是菜鸟呀

2005-04-14 09:39
快速回复:赶快来看看吧
数据加载中...
 
   



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

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