公路收费系统(控制台c++)

fee.h

#ifndef MY_H
#define MY_H

class Fee
{
private:
    long int car;
    long int car_fee;
    long int truck;
    long int truck_fee;
    long int bus;
    long int bus_fee;

 


public:

    Fee(long int car,  long int car_fee,long int truck,long int truck_fee,long int bus,long int bus_fee);
    void cars(long int car);
    void trucks(long int truck);
    void buses(long int bus);
    void process();
    void display();
    void correct();
    void caculate();

    static long int car_sum;
    static long int car_money;
    static long int truck_sum;
    static long int truck_money;
    static long int bus_sum;
    static long int bus_money;
    static bool isAlive;/*for convenience*/

 

/* setter and getter  */
    void setCar(int car) ;
    int getCar() ;

    void setCar_fee(int car_fee) ;
 int getCar_fee();

    void setTruck(int truck) ;
 int getTruck() ;

    void setTruck_fee(int truck_fee);
    int getTruck_fee() ;

 void setBus(int bus) ;
    int getBus();

    void setBus_fee(int bus_fee);
    int getBus_fee();

};
#endif

 

 

fee.cpp

#include "fee.h"
#include <iostream>

using namespace std;


Fee::Fee(long int car,long int car_fee,long int truck,
         long int truck_fee,long int bus,long int bus_fee){

        this->car = car;
        this->car_fee = car_fee;
        this->truck = truck;
        this->truck_fee = truck_fee;
        this->bus= bus;
        this->bus_fee = bus_fee;

}

/*static member init*/
  long int Fee:: car_sum=0;
  long int Fee:: car_money=0;
  long int Fee:: truck_sum=0;
  long int Fee:: truck_money=0;
  long int Fee:: bus_sum=0;
  long int Fee:: bus_money=0;
  bool Fee:: isAlive=true;/*for convenience*/

void Fee:: cars(long int car){
    this->car+=car;
    car_sum=this->car;
    car_money+=car*this->car_fee;

}
void Fee:: trucks(long int truck){

    this->truck+=truck;
    truck_sum=this->truck;
    truck_money+=truck*this->truck_fee;
}
void Fee:: buses(long int bus){

    this->bus+=bus;
    bus_sum=this->bus;
    bus_money+=bus*this->bus_fee;
}
void Fee:: process(){/*fee process*/

     cout<<"********************Welcome to You******************************"<<endl;
     cout<<"*Input vector's informateion..................................1*"<<endl;
     cout<<"*Display the vector's informateion ...........................2*"<<endl;
     cout<<"*Set fee standard information ................................3*"<<endl;
     cout<<"*Exit the car fee system......................................0*"<<endl;
     cout<<"*********************Welcome to You*****************************"<<endl;
     cout<<"Please input which item you want to choose:"<<endl;
     int choice;
     cin>>choice;

     switch(choice){
        case 1:
          caculate();
          break;

        case 2:
          display();
          break;
        case 3:
          correct();
          break;
        case 0:
          isAlive=false;
          break;

        }


}
void Fee:: display(){/*diaplay*/
    cout<<"The current situation of vector fee process:"<<endl;
    cout<<"---------------------------------------"<<endl ;
    cout<<"total cars : "<<this->car<<" total fee: "<<car_money<<endl;
    cout<<"total truck: "<<this->truck<<" total fee: "<<truck_money<<endl;
    cout<<"total buses: "<<this->bus<<" total fee: "<<bus_money<<endl;
    cout<<"All Fee : "<<car_money+truck_money+bus_money<<endl;
    cout<<"---------------------------------------"<<endl;

}


void Fee::correct(){
    cout<<"----------------------------------------"<<endl;
    cout<<"Car settings............................1"<<endl;
    cout<<"Truck settings..........................2"<<endl;
    cout<<"Bus settings............................3"<<endl;
    cout<<"----------------------------------------"<<endl;
    cout<<"Please input the kind you want to set:"<<endl;
    int kind;
    cin>>kind;
    switch(kind){
      case 1:
        cout<<"input car_fee:"<<endl;
        long int cfee;
        cin>>cfee;
        this->setCar_fee(cfee);
        cout<<"reset success!!!"<<endl;
        break;
      case 2:
        cout<<"input truck_fee:"<<endl;
        long int tfee;
        cin>>tfee;
        this->setTruck_fee(tfee);
        cout<<"reset success!!!"<<endl;
        break;
      case 3:
        cout<<"input bus_fee:"<<endl;
        long int bfee;
        cin>>bfee;
        this->setBus_fee(bfee);
        cout<<"reset success!!!"<<endl;
        break;


    }

}

void Fee::caculate(){

    cout<<"----------------------------------------"<<endl;
    cout<<"Caculate the fee:"<<endl;
    cout<<"Car fee............................1"<<endl;
    cout<<"Truck fee..........................2"<<endl;
    cout<<"Bus fee............................3"<<endl;
    cout<<"----------------------------------------"<<endl;
    cout<<"Please input the kind you want to input:"<<endl;
    int kind;
    cin>>kind;
    switch(kind){

        case 1:
         cout<<"Please input the number of Car:"<<endl;
         int cnt1;
         cin>>cnt1;
         cars(cnt1);
          break;
        case 2:
         cout<<"Please input the number of Truck:"<<endl;
         int cnt2;
         cin>>cnt2;
         cars(cnt2);
          break;
        case 3:
         cout<<"Please input the number of Bus:"<<endl;
         int cnt3;
         cin>>cnt3;
         cars(cnt3);
          break;

 

    }
    cout<<"Caculate Success!!!!!"<<endl;

}

/*setter and getter */

void Fee:: setCar(int car) {
   this->car = car;
  }
int  Fee:: getCar() {
   return car;
  }
void Fee:: setCar_fee(int car_fee) {
   this->car_fee = car_fee;
  }
int  Fee:: getCar_fee() {
   return car_fee;
  }
void Fee:: setTruck(int truck) {
   this->truck = truck;
  }
int  Fee:: getTruck() {
   return truck;
  }
void Fee:: setTruck_fee(int truck_fee) {
   this->truck_fee = truck_fee;
  }
int  Fee:: getTruck_fee() {
   return truck_fee;
  }
void Fee:: setBus(int bus) {
   this->bus = bus;
  }
int  Fee:: getBus() {
   return bus;
  }
void Fee:: setBus_fee(int bus_fee) {
   this->bus_fee = bus_fee;
  }
int  Fee:: getBus_fee() {
   return bus_fee;
  }

 

main.cpp

 

#include <iostream>
#include <fstream>
#include "fee.h"
using namespace std;

int main()
{

    ofstream fout ("Feedata.dat");
    Fee fee(0,10,0,50,0,100);
    do{

        fee.process();
        fout<<fee.car_sum<<" "<<fee.bus_sum<<" "<<fee.truck_sum<<endl;

    }while(fee.isAlive);

    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值