地铁售票系统 计应192西—第一组—贾特

计应192西—第一组—贾特

题目描述:
地铁是当今城市较为流行的一种铁路运输的形式,地铁能避免城市地面拥挤,充分利用空间,具有运量大、准时、正点率较其他公交高、速度快等优点。请设计一个简易的、带菜单的地铁自动售票机系统。

需求分析:
(1)设计一个地铁路线类Router,包含路线编号,途中的各个站点。

(2)设计一个地图类Map,可以显示所有可以乘坐的地铁站名,以及线路信息。

(3)根据用户输入的起点和终点和人次信息,可以自动计算应付金额;根据用户输入的金额,计算找零信息。

程序设计:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
menu();
return 0;

Console.ReadKey();

}
}
class Router
{
string []port;//经过站点

private int id;//路线编号
private int count = 0;//站点数目
public void setId(int i)
{
id = i;
}
public void addPort(string name)
{
port[count] = name;
count++;
}
public void getPort()
{
int i = 0;
for ( i = 0; i < count; i++)
{
Console.WriteLine("第"+i+1+"站");
Console.WriteLine(port[i]);

}
}
int check(string u, string v)
{
int d = 0;
for (int i = 0; i < count; i++)
{
if (port[i] == u)
{
for (int j = 0; j < count; j++)
{
if (port[j] == v)
{
// u v
return ((i - j) >= 0) ?
(i - j) : (j - i);
}
}
}
}
return 0;
}
}
class Map
{
private vector<Router> r;//路线图
public double charge = 2;//每站价格

public void setCharge(double ch)
{
charge = ch;
}
void init()
{

Router temp1;
temp1.setId(1);
temp1.addPort("west");
temp1.addPort("mid1");
temp1.addPort("south");
r.push_back(temp1);

Router temp2;
temp2.setId(2);
temp2.addPort("south");
temp2.addPort("mid2");
temp2.addPort("east");
r.push_back(temp2);

Router temp3;
temp3.setId(3);
temp3.addPort("east");
temp3.addPort("mid3");
temp3.addPort("north");
r.push_back(temp3);

Router temp4;
temp4.setId(4);
temp4.addPort("north");
temp4.addPort("mid4");
temp4.addPort("west");
r.push_back(temp4);
}

int buy(string start, string end)
{
int count = r.size();
int d = 0;
for (int i = 0; i < count; i++)
{
Router temp = r[i];
d = temp.check(start, end);
if (d > 0)
{
Console.WriteLine("您需要乘坐" + i + 1 + "号线");
return d;
}
}
return 0;
}

void show()
{
int count = r.size();
Console.WriteLine("本市地铁线路图如下:");
for (int i = 0; i < count; i++)
{
Console.WriteLine(i + 1 +"号线:");
Router temp = r[i];
temp.getPort();
}
}
};


public void menu()
{
int m;
Map map;
map.init();
while (1)
{
Console.WriteLine("----------欢迎来到地铁售票系统-----------");
Console.WriteLine("----------1、路线查询-----------");
Console.WriteLine("----------2、购票-----------");
Console.WriteLine(m);
if (m == 1)
{
map.show();
}
else if (m == 2)
{
Console.WriteLine("请输入起点:");
string s;
Console.WriteLine("请输入终点:");
string e;
Console.WriteLine("请输入人数:");
int c;
int d = map.buy(s, e);
if (d > 0)
{
double rs = (double)c * (double)d * map.charge;
Console.WriteLine("您需要支付的费用为:");
Console.WriteLine(rs);
Console.WriteLine("请输入您支付的金额:");
double in= 0;
if (in>= rs) {
Console.WriteLine("购票成功!");
Console.WriteLine("找零:" +in-rs + "元");
} else
{
Console.WriteLine("金额不足,购票失败!");
}
}
else
{
Console.WriteLine("抱歉,请选择其他交通!");
}
}
}
}

 

}
}

代码复审:室友和我来检查代码,没什么问题。

测试结果:

 

报告
测试报告:三条线,设置的站数并不多,但基本运行流程没问题
计算工作量:一百多行的代码,虽然可以复制自己的一站一站的代码。但仍有问题被困,好在问过同学解决,也是花费了一定时间完成。

事后总结:代码完成度不高,有些简陋,期间也遇到很多问题,来求助同学来完成。仍需多加观看以及练习掌握知识!

PSP阶段

posted @ 2021-04-11 15:37  计应192西一组  阅读(118)  评论(0)    收藏  举报