第十章 汽車租賃系統

2022-08-17 21:36:13 字數 2854 閱讀 9191

本次綜合練習的任務是開發」汽車租賃系統「,汽車租賃系統包括以下功能

1.租車

顯示系統中所有可出租的汽車,選中要出租的汽車,輸入租用人以出租汽車,如圖所示

2.還車

在還車列表中選擇汽車資訊,輸入出租天數,計算租金,如圖所示

3.新車入庫

需要錄入汽車的車牌號,車型,顏色,使用時間,和每日租金,如果是卡車還要錄入卡車的載重,如圖所示

具體實現過程:

1.搭建系統

按照類圖建立類,體會vehicle,trech和car三個類之間的關係

car類:

namespace _09汽車租賃系統

public override double calcprice()

else

return totalprice;}}

}vehicle類

namespace _09汽車租賃系統

public vehicle(string licenseno,string name,string color,int yearofservice,double dailyrent)

//租用日期

private int rentdate;

public int rentdate

set

}//租用者

private string rentuser;

public string rentuser

set

}//日租金

private double dailyrent;

public double dailyrent

set

}//使用時間

private int yearofservice;

public int yearofservice

set

}//顏色

private string color;

public string color

set

}//車名

private string name;

public string name

set

}//車牌號

private string licenseno;

public string licenseno

set

}//計算**的方法

public abstract double calcprice();}}

trech類:

namespace _09汽車租賃系統

public truck(string licenseno, string name, string color, int yearsofservice, double dailyrent, int load)

: base(licenseno, name, color, yearsofservice, dailyrent)

//載重量

private int load;

public int load

set

}//卡車費用計算方法

// 30天以內(含30)按日租金計算

// 30天以上超出部分:每天,每噸(載重量)增加日租金10%

public override double calcprice()

else

return totalprice;}}

}//儲存可租用車的集合(車輛名稱,車輛物件)

dictionarynotrent;

//儲存已租用車輛的集合。

dictionaryalreadyrent;

2.實現汽車出租

if (txtrenter.text=="")

//從可租車輛集合中移除車輛a

//將a新增到已租車輛集合中

if (lvrent.selecteditems.count>0)

//01.將車a從已租集合中移除 //02,將車a加入到可租車輛中

string number=lvreturn.selecteditems[0].text;

vehicle ve = alreadyrent[number];

alreadyrent.remove(number);

myrefresh(alreadyrent, lvreturn);

notrent.add(number, ve);

ve.rentdate = convert.toint32(txtrentdate.text);

double money=0;

money = ve.calcprice();

messagebox.show("您需要支付"+money+"元");

4.實現新車入庫

string lincesn0=txtautonum.text;

string name=txtname.text;

string color=cobcolor.text;

int time=convert.toint32(txtyears.text);

double dailyrent=convert.toint32(txtletting.text);

if (rdocar.checked)

if (rdotruck.checked)

messagebox.show("新增成功!");

C 第十章 汽車租賃系統

namespace 第十章 汽車租賃系統 車名 public string name 顏色 public string color 使用時間 public int shijian 日租金 public double dailyrent 卡車載重 public string zaizhong publ...

第十章 函式

使用def關鍵字 定義個數可變的位置形參 定義個數可變的關鍵字形參 定義預設值引數 定義個數可變的位置形參 deffun1 args 結果為乙個元組 print args fun1 10,20,30 10,20,30 定義個數可變的關鍵字形參 deffun2 args 結果為乙個字典 print a...

第十章 屬性

z屬性 本章也比較簡單稍作介紹 無參屬性就是我們常見的屬性 可以封裝屬性 以執行緒安全方式訪問 有參屬性就是c 中的所引器 匿名型別 如圖遇到如下 具體點就是 上面的注釋也已經講清楚了,定義的型別之後,構造例項,然後初始化屬性。現在詳細說下 編譯器接收到 上圖 先用var 定義乙個型別,但是不具體指...