停车场付费设计

该程序使用C++编写,用于计算一个停车场的收费。对于在场内停车的顾客,程序会根据停车时长计算费用,初始$2.00的最低费用适用于前三小时,超出部分按每小时$0.50加收。每天最高费用上限为$10.00。程序接收三个顾客的停车小时数输入,输出每个顾客的费用以及昨日总收款。
摘要由CSDN通过智能技术生成

A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday’s receipts. The program should use the function calculateCharges to determine the charge for each customer. Your outputs should appear in the following format

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
float charge(float h){
    float dF;
    int iH,i;
    if(h>=0 &&h<=3) dF=2;
    else if(h>3){
        iH=h;
        i=(h-iH)*10;
        if(i>0) iH++;
            dF=2+(iH -3)*0.5;
    }
    if(dF>10) dF=10;
    return dF;
}
int main(){
    const int N=3;
    int i;
    string Lbl[N];
    float fTF,prk[N][2];
    fTF=0;
    for(i=0;i<N;i++){
        cout<<"Car Label\n";
        cin>> Lbl[i];
        cout<<"Parking hours\n";
        cin>> prk[i][0];
        prk[i][1]=charge(prk[i][0]);
    }
    for(i=0;i<N;i++) fTF=fTF+prk[i][1];
    cout<<"Car\tHours\tCharge\n";
    cout<<setiosflags(ios::fixed)<<setiosflags(ios::right); //<<setw(10)
    for(i=0;i<N;i++){
        cout<<Lbl[i]<<'\t';
        cout<<setprecision(1);
        cout<<prk[i][0]<<'\t';
        cout<<setprecision(2);
        cout<<prk[i][1]<<'\n';
    }
    cout<<"\t\t"<<fTF;
    return 0;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值