c#部分---结构体再利用;
//定义一个结构体,存放关于车辆的几个信息
//将所有车的信息都放入集合中
//车型号 价格(W) 轴距 (mm) 油耗(L/100km)
//宝马320Li 38 2920 6.9
//宝马520Li 43 3108 7.2
//宝马730Li 89 3210 6.3
//奥迪A4L35TFSI 31 2869 6.2
//奥迪A6L30TFSI 43 3012 7.6
//奥迪A8L45TFSI 89 3122 8.1
//奔驰C200L 35 2920 6.1
//奔驰E260L 48 3014 6.7
//奔驰S320L 93 3165 8
//所有在售车辆中最便宜的
//ArrayList al = new ArrayList(); //pinpai a1 = new pinpai(); a1.name = "宝马320Li"; a1.price = 38; a1.zhouju = 2920; a1.youhao = 6.9; //al.Add(a1); //pinpai a2 = new pinpai(); a2.name = "宝马520Li"; a2.price = 43; a2.zhouju = 3108; a2.youhao = 7.2; //al.Add(a2); //pinpai a3 = new pinpai(); a3.name = "宝马730Li"; a3.price = 89; a3.zhouju = 3210; a3.youhao = 6.3; //al.Add(a3); //pinpai a4 = new pinpai(); a4.name = "奥迪A4L35TFSI"; a4.price = 31; a4.zhouju = 2869; a4.youhao = 6.2; //al.Add(a4); //pinpai a5 = new pinpai(); a5.name = "奥迪A6L35TFSI"; a5.price = 43; a5.zhouju = 3012; a5.youhao = 7.6; //al.Add(a5); //pinpai a6 = new pinpai(); a6.name = "奥迪A8L35TFSI"; a6.price = 89; a6.zhouju = 3122; a6.youhao = 8.1; //al.Add(a6); //pinpai a7 = new pinpai(); a7.name = "奔驰C200L"; a7.price = 35; a7.zhouju = 2920; a7.youhao = 6.1; //al.Add(a7); //pinpai a8 = new pinpai(); a8.name = "奔驰E260L"; a8.price = 48; a8.zhouju = 3014; a8.youhao = 6.7; //al.Add(a8); //pinpai a9 = new pinpai(); a9.name = "奔驰S320L"; a9.price = 93; a9.zhouju = 3165; a9.youhao = 8; //al.Add(a9); //for (int i = 0; i < 8; i++) //{ // for (int j = i + 1; j < 9; j++) // { // pinpai a = (pinpai)al[i]; // pinpai b = (pinpai)al[j]; // if (a.price > b.price) // { // object zhong = al[i]; // al[i] = al[j]; // al[j] = zhong; // } // } //} //pinpai aa = (pinpai)al[0]; //Console.WriteLine("最便宜的是{0},价格{1},轴距{2},油耗{3}。", aa.name, aa.price, aa.zhouju, aa.youhao); //Console.WriteLine("--------------------------------------------------------------------");
//求宝马中最便宜的车型是什么,所有信息列出
//for (int i = 0; i < 9; i++) //{ // pinpai baomacheap = (pinpai)al[i]; // if (baomacheap.name.Contains("宝马")) // { // Console.WriteLine("宝马车中最便宜的是{0},价格{1},轴距{2},油耗{3}。", baomacheap.name, baomacheap.price, baomacheap.zhouju, baomacheap.youhao); // break; // } //}
//选个轴距最长的
//Console.WriteLine("--------------------------------------------------------------------"); //for (int i = 0; i < 8; i++) //{ // for (int j = 1; j < 9; j++) // { // pinpai a = (pinpai)al[i]; // pinpai b = (pinpai)al[j]; // if (a.zhouju < b.zhouju) // { // object zhong = al[i]; // al[i] = al[j]; // al[j] = zhong; // } // } //} //pinpai cc = (pinpai)al[0]; //Console.WriteLine("轴距最长的车是{0},价格{1},轴距{2},油耗{3}。", cc.name, cc.price, cc.zhouju, cc.youhao); //Console.WriteLine("--------------------------------------------------------------------");
//选个轴距最长的,必须是奔驰
//for (int i = 0; i < 9; i++) //{ // pinpai zhouju = (pinpai)al[i]; // if (zhouju.name.Contains("奔驰")) // { // Console.WriteLine("奔驰车中轴距最长的是{0},价格{1},轴距{2},油耗{3}。", zhouju.name, zhouju.price, zhouju.zhouju, zhouju.youhao); // break; // } //} //Console.WriteLine("--------------------------------------------------------------------");
//想要一辆油耗最低的车
//for (int i = 0; i < 8; i++) //{ // for (int j = 1; j < 9; j++) // { // pinpai a = (pinpai)al[i]; // pinpai b = (pinpai)al[j]; // if (a.youhao > b.youhao) // { // object zhong = al[i]; // al[i] = al[j]; // al[j] = zhong; // } // } //} //pinpai ee = (pinpai)al[0]; //Console.WriteLine("油耗最低的车辆是{0},价格{1},轴距{2},油耗{3}。", ee.name, ee.price, ee.zhouju, ee.youhao); //Console.WriteLine("--------------------------------------------------------------------");
//想要一辆油耗最低的奥迪车
//for (int i = 0; i < 9; i++) //{ // pinpai youhao = (pinpai)al[i]; // if (youhao.name.Contains("奥迪")) // { // Console.WriteLine("奥迪车中油耗最低的是{0},价格{1},轴距{2},油耗{3}。", youhao.name, youhao.price, youhao.zhouju, youhao.youhao); // break; // } //} //Console.WriteLine("--------------------------------------------------------------------");
//我只有50万,看看能买什么车
//int biao = 0; //for (int i = 0; i < 9; i++) //{ // pinpai a = (pinpai)al[i]; // if (a.price <= 50) // { // biao++; // Console.WriteLine("第{0}辆:{1},价格{2},轴距{3},油耗{4}。", biao, a.name, a.price, a.zhouju, a.youhao); // } //} //Console.WriteLine("--------------------------------------------------------------------");
//我只需要60万以上的车,列出来所有车型和所有信息
//int biao1 = 0; //for (int i = 0; i < 9; i++) //{ // pinpai a = (pinpai)al[i]; // if (a.price > 60) // { // biao1++; // Console.WriteLine("第{0}辆:{1},价格{2},轴距{3},油耗{4}。", biao1, a.name, a.price, a.zhouju, a.youhao); // } //} //Console.WriteLine("--------------------------------------------------------------------");
//轴距必须超过3m,列列表
//int biao2 = 0; //for (int i = 0; i < 9; i++) //{ // pinpai a = (pinpai)al[i]; // if (a.zhouju > 3000) // { // biao2++; // Console.WriteLine("第{0}辆:{1},价格{2},轴距{3},油耗{4}。", biao2, a.name, a.price, a.zhouju, a.youhao); // } //} //Console.WriteLine("--------------------------------------------------------------------");
//油耗在8.5以下都行,列列表
//int biao3 = 0; //for (int i = 0; i < 9; i++) //{ // pinpai a = (pinpai)al[i]; // if (a.youhao < 8.5) // { // biao3++; // Console.WriteLine("第{0}辆:{1},价格{2},轴距{3},油耗{4}。", biao3, a.name, a.price, a.zhouju, a.youhao); // } //} //Console.WriteLine("--------------------------------------------------------------------");
//我不在乎油耗,要油耗最高的车
//for (int i = 0; i < 8; i++) //{ // for (int j = 0; j < 9; j++) // { // pinpai a = (pinpai)al[i]; // pinpai b = (pinpai)al[j]; // if (a.youhao > b.youhao) // { // object zhong = al[i]; // al[i] = al[j]; // al[j] = zhong; // } // } //} //pinpai xx = (pinpai)al[0]; //Console.WriteLine("油耗最高的车辆是{0},价格{1},轴距{2},油耗{3}。", xx.name, xx.price, xx.zhouju, xx.youhao); //Console.WriteLine("--------------------------------------------------------------------");