工大机试第三题

3.      某大桥按不同型号征收车辆过桥费:自行车免费,摩托车2元,小汽车5元,大客车与货车8元,货柜车12元。编写一个程序,按车辆的不同型号计算通过该大桥应征的过桥费。(提示:可以用整数对不同型号的车辆进行编码)

// problem3.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include
#include

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
 int a=0;
  char strcar[20];
 string str;
 cout<<"输入汽车编号或汽车名:";
 cin>>strcar;
 str=strcar;
  // printf("%s",str);
   if("自行车"==str||"0"==str)
   {
    a=0;
   }
     if("摩托车"==str||"1"==str)
   {
    a=1;
   }
   if("小汽车"==str||"2"==str)
   {
    a=2;
   }
    if("大客车"==str||"货车"==str||"3"==str)
   {
    a=3;
   }
     if("货柜车"==str||"4"==str)
   {
    a=4;
   }
  switch(a)
  {
  case 0:
   cout<<"自行车免费"<    break;
   case 1:
   cout<<"摩托车2元"<    break;
   case 2:
   cout<<"小汽车5元"<    break;
   case 3:
   cout<<"大客车和货车8元"<    break;
   case 4:
   cout<<"货柜车12元"<    break;
  }
 return 0;
}

欢迎访问船长旅游网 旅游攻略 旅游资讯 景点介绍 旅游博客  http://www.chuanzhy.com

你可能感兴趣的:(IT源码)