【id:59】【20分】D. 旅馆顾客统计(静态成员)

时间限制
1s
内存限制
128MB

题目描述
编写程序,统计某旅馆住宿客人的总数和收入总额。要求输入客人的姓名,输出客人编号(2015+顺序号,顺序号4位,如第1位为0001,第2位为0002,依此类推)、姓名、总人数以及收入总额。总人数和收入总额用静态成员,其他属性采用普通的数据成员。旅馆类声明如下:

class Hotel
{
private:
static int totalCustNum; // 顾客总人数
static float totalEarning; // 旅店总收入
static float rent; // 每个顾客的房租
char customerName; // 顾客姓名
int customerId; // 顾客编号
public:
// totalCustNum++,customerId按照totalCustNum生成
Hotel(char
customer);
~Hotel(); //记得delete customerName
void Display(); //相应输出顾客姓名、顾客编号、总人数、总收入
};

输入
第1行:输入旅馆单个顾客房租

第2行开始,依次输入顾客姓名,0表示输入结束, 姓名的最大字符长度为20

输出
每行依次输出顾客信息和当前旅馆信息。包括顾客姓名,顾客编号,旅馆当前总人数,旅馆当前总收入。

样例查看模式
正常显示
查看格式
输入样例1 <-复制

输出样例1

#define _CRT_SECURE_NO_WARNINGS 
#include<bits/stdc++.h>
using namespace std;
class Hotel
{
private:
    static int totalCustNum; // 顾客总人数
    static float totalEarning; // 旅店总收入
    static float rent; // 每个顾客的房租
    char* customerName; // 顾客姓名
    int customerId=20150000; // 顾客编号
public:
    // totalCustNum++,customerId按照totalCustNum生成
    Hotel(char* customer) {
        customerName = new char[strlen(customer) + 1];
        strcpy(customerName, customer);
        totalCustNum++;
        customerId+= totalCustNum;
    }
    ~Hotel() {
        delete[] customerName;
    }//记得delete customerName
    void Display() {

        cout << customerName << " "<< customerId <<" ";
        cout <<  totalCustNum<< " ";
        
        cout << totalCustNum * rent << endl;
    }
    static void getrent(float rent1) {
        /*totalCustNum = 0;
        totalEarning =0;*/
        rent = rent1;
    }//相应输出顾客姓名、顾客编号、总人数、总收入
};
int Hotel::totalCustNum = 0;
float Hotel::totalEarning = 0;
float Hotel::rent = 0;
int main() {

    float rent;
    char customer[10];
    cin >> rent;
    Hotel::getrent(rent);
    while (1) {
        cin >> customer;
        if (*customer == '0')
            break;
        Hotel h(customer);
        h.Display();
    }

    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>发现香港</title> <style> /* 网页样式 */ body { font-family: Arial, Helvetica, sans-serif; margin: 0; padding: 0; } header { background-color: #fdd6a3; padding: 10px; text-align: center; font-size: 30px; font-weight: bold; color: #ffffff; } nav { background-color: #fde9c0; padding: 10px; text-align: center; font-size: 20px; font-weight: bold; color: #404040; } nav a { color: #404040; text-decoration: none; padding: 10px; border-radius: 10px; background-color: #ffffff; } nav a:hover { background-color: #ffb347; color: #ffffff; } section { margin: 0; padding: 0; } section img { width: 100%; height: auto; } section h2 { font-size: 24px; font-weight: bold; color: #404040; padding: 10px; } section p { font-size: 16px; line-height: 1.5; color: #404040; padding: 10px; } footer { background-color: #fdd6a3; padding: 10px; text-align: center; color: #404040; font-size: 14px; } /* 响应式布局 */ @media only screen and (max-width: 768px) { header { font-size: 24px; } nav { font-size: 16px; } nav a { padding: 8px; } section h2 { font-size: 20px; } section p { font-size: 14px; padding: 5px; } footer { font-size: 12px; } } </style> </head> <body> <header>发现香港</header> <nav> <a href="#">餐饮美食</a> <a href="#">购物娱乐</a> <a href="#">景点推荐</a> <a href="#">酒店住宿</a> <a href="#">交通指南</a> <a href="#">联系我们</a> </nav> <section> <img src="https://www.discoverhongkong.cn/resources/images/homepage/homepage-hero-main.jpg" alt="香港海港城"> <h2>餐饮美食</h2> <p>香港拥有丰富的美食文化,融合了中式、西式、港式、日式等不同的菜系,每个人都能找到自己喜欢的口味。从大牌餐厅到街头小吃,香港的美食汇聚了世界各地的精华,让你的味蕾一次过瘾。</p> <img src="https://www.discoverhongkong.cn/resources/images/homepage/homepage-hero-main.jpg" alt="香港购物"> <h2>购物娱乐</h2> <p>香港被誉为亚洲的购物天堂,这里有各种国际奢侈品牌的专卖店和超大型购物中心,也有小清新的文艺小店和传统的市井小贩。此外,香港的娱乐场所也是繁华不已,夜生活丰富多彩,漂亮的夜景更是让人流连忘返。</p> <img src="https://www.discoverhongkong.cn/resources/images/homepage/homepage-hero-main.jpg" alt="香港景点"> <h2>景点推荐</h2> <p>香港拥有众多的景点,包括名胜古迹、公园花园、主题乐园、博物馆等各种不同类型,每个景点都有自己独特的魅力。观赏香港夜景、游览历史文化古迹、去浪漫的海边看日出,这里一定不会让你失望。</p> <img src="https://www.discoverhongkong.cn/resources/images/homepage/homepage-hero-main.jpg" alt="香港酒店"> <h2>酒店住宿</h2> <p>香港的酒店林立,从星级酒店到背包客旅馆,都有不同档次的住宿选择。无论你是来旅游还是商务,都能找到适合自己的住宿环境。此外,香港的民宿也越来越受欢迎,提供更加贴心的入住体验。</p> <img src="https://www.discoverhongkong.cn/resources/images/homepage/homepage-hero-main.jpg" alt="香港交通"> <h2>交通指南</h2> <p>香港拥有发达的交通体系,包括地铁、公交、巴士、渡轮等各种交通方式。无论你要去哪里,都能找到方便快捷的交通工具。此外,香港的出租车和网约车也可以提供更为舒适便捷的出行体验。</p> </section> <footer> ©2021 香港旅游发展局版权所有 </footer> </body> </html>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谁的BUG最难改

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值