Write a computer program that could be used to track, by lab, which user is logged into which computer: Lab Number Computer Station Numbers 1 1-5 2 1-6 3 1-4 4 1-3 ➢ You run four computer labs. Each lab contains computer stations that are numbered as the above table. ➢ Each user has a unique ID number. The ID starting with three characters (for example, SWE or DMT), and followed by three digits (like, 001). ➢ Whenever a user logs in, the user’s ID, lab number, and the computer station number are transmitted to your system. For example, if user SWE001 logs into station 2 in lab 3, then your system receives (SWE001, 2, 3) as input data. Similarly, when a user SWE001 logs off a station, then your system receives the user id SWE001. ➢ If a user who is already logged into a computer attempts to log into a second computer, display "invalid login". If a user attempts to log into a computer which is already occupied, display "invalid login". If a user who is not included in the database attempts to log out, display "invalid logoff". 输入格式 If user SWE001 is logged into station 2 in lab 3 and user DMT001 is logged into station 1 of lab 4, use + for logging in, - for logging off, and = for end of input: + SWE001 2 3 + DMT001 1 4 《面向对象程序设计 C++》 2022-2023 春季学期 2 / 4 - SWE001 = 输出格式 The status of all labs (who is logged into which computer). Otherwise, display invalid login or invalid logoff. You need to display the status of all labs even when the input is invalid.

时间: 2024-02-25 22:57:27 浏览: 35
以下是一个简单的 C++ 程序,用于跟踪用户登录的情况: ``` #include <iostream> #include <map> #include <vector> using namespace std; class Lab { public: Lab(int num, int start, int end) : lab_num(num), start_station(start), end_station(end) {} int lab_num; int start_station; int end_station; map<int, string> stations; }; class User { public: User(string id) : user_id(id) {} string user_id; int lab_num; int station_num; }; int main() { vector<Lab> labs = {Lab(1, 1, 5), Lab(2, 1, 6), Lab(3, 1, 4), Lab(4, 1, 3)}; map<string, User> users; string input; while (getline(cin, input)) { if (input == "=") break; char op = input[0]; string id = input.substr(2, 6); int lab_num = stoi(input.substr(9, 1)); int station_num = stoi(input.substr(11)); if (op == '+') { if (users.count(id)) { cout << "invalid login" << endl; } else { bool valid = true; for (auto& x : users) { User& u = x.second; if (u.lab_num == lab_num && u.station_num == station_num) { valid = false; cout << "invalid login" << endl; break; } } if (valid) { User u(id); u.lab_num = lab_num; u.station_num = station_num; users[id] = u; labs[lab_num-1].stations[station_num] = id; } } } else if (op == '-') { if (!users.count(id)) { cout << "invalid logoff" << endl; } else { User u = users[id]; labs[u.lab_num-1].stations.erase(u.station_num); users.erase(id); } } } for (auto& lab : labs) { cout << "Lab " << lab.lab_num << ":" << endl; for (int i = lab.start_station; i <= lab.end_station; i++) { cout << "Station " << i << ": "; if (lab.stations.count(i)) { cout << lab.stations[i] << endl; } else { cout << "empty" << endl; } } } return 0; } ``` 该程序使用了面向对象的编程思想,定义了 Lab 和 User 两个类,分别表示实验室和用户。Lab 类包含了实验室的编号、起始和结束的电脑编号,以及一个 map,用于存储每个电脑当前登录的用户。User 类包含了用户的 ID,以及所在实验室和电脑的编号。 程序的主要逻辑在 while 循环中,根据输入的操作类型进行相应的处理。如果是登录操作,首先判断该用户是否已经登录,如果已经登录则输出 "invalid login";否则遍历已经登录的用户,判断当前实验室和电脑是否已经被占用,如果被占用则输出 "invalid login",否则将该用户添加到 users 和对应的实验室的 stations 中。如果是登出操作,首先判断该用户是否已经登录,如果没有登录则输出 "invalid logoff",否则将该用户从 users 和对应的实验室的 stations 中删除。 最后,程序遍历所有实验室和电脑,输出当前登录的用户或者 "empty"。如果输入数据不合法,则会输出相应的错误信息,但仍然会输出所有实验室的状态。

相关推荐

Write a computer program that could be used to track users' activities. Lab Number Computer Station Numbers 1 1-3 2 1-4 3 1-5 4 1-6  You run four computer labs. Each lab contains computer stations that are numbered as the above table.  There are two types of users: student and staff. Each user has a unique ID number. The student ID starts with three characters (for example, SWE or DMT), and is followed by three digits (like, 001). The staff ID only contains digits (for example: 2023007).  Whenever a user logs in, the user’s ID, lab number, the computer station number and login date are transmitted to your system. For example, if user SWE001 logs into station 2 in lab 3 in 01 Dec, 2022, then your system receives (+ SWE001 2 3 1/12/2022) as input data. Similarly, when a user SWE001 logs off in 01 Jan, 2023, then your system receives receives (- SWE001 1/1/ 2023). Please use = for end of input.  When a user logs in or logs off successfully, then display the status of stations in labs. When a user logs off a station successfully, display student id of the user, and the number of days he/she logged into the station.  When a user logs off, we calculate the price for PC use. For student, we charge 0 RMB if the number of days is not greater than 14, and 1 RMB per day for the part over 14 days. For staff, we charge 2 RMB per day if the number of days is not greater than 30, and 4 RMB per day for the part over 30 days.  If a user who is already logged into a computer attempts to log into a second computer, display "invalid login". If a user attempts to log into a computer which is already occupied, display "invalid login". If a user who is not included in the database attempts to log off, display "invalid logoff".

使用面向对象的方法编写代码,求解下列问题:You run four computer labs. Each lab contains computer stations that are numbered as the above table. ➢ Each user has a unique ID number. The ID starting with three characters (for example, SWE or DMT), and followed by three digits (like, 001). ➢ Whenever a user logs in, the user’s ID, lab number, and the computer station number are transmitted to your system. For example, if user SWE001 logs into lab 2 station 3, then your system receives (SWE001, 2, 3) as input data. Similarly, when a user SWE001 logs off a station, then your system receives the user id SWE001. ➢ If a user who is already logged into a computer attempts to log into a second computer, display “invalid login”. If a user attempts to log into a computer which is already occupied, display “invalid login”. If a user who is not included in the database attempts to log out, display "invalid logoff代码需要符合以下要求: ✓ VS 项目包含至少三个文件 ComputerLab.h、ComputerLab.cpp、main.cpp, ComputerLab.h中写类的定义,ComputerLab.cpp中写类的成员函数实现, main.cpp 中写主函数; ✓ 代码中应有两个类ComputerLab和User,且类中所有数据成员都为私有; ✓ ComputerLab 类是 User 类的友元,可访问 User 类中私有数据成员; ✓ 给 ComputerLab 类重载操作符+和-,分别实现用户登录和退出功能实现下列格式的输入输出If user SWE001 is logged into lab 2 station 3 and user DMT001 is logged into lab 1 station 4, use + for logging in, for logging off, and = for end of input: SWE001 2 3 DMT001 1 4 SWE001 输出格式 The status of all labs (who is logged into which computer). Otherwise, display invalid login or invalid logoff. You need to display the status of all labs even when the input is invalid.

用C++编写程序,实现以下问题2、题目ID Codes(POJ1146) Time Limit: 1000MS Memory Limit: 10000K 描述: It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In order to exercise greater control over its citizens and thereby to counter a chronic breakdown in law and order, the Government decides on a radical measure--all citizens are to have a tiny microcomputer surgically implanted in their left wrists. This computer will contains all sorts of personal information as well as a transmitter which will allow people's movements to be logged and monitored by a central computer. (A desirable side effect of this process is that it will shorten the dole queue for plastic surgeons.) An essential component of each computer will be a unique identification code, consisting of up to 50 characters drawn from the 26 lower case letters. The set of characters for any given code is chosen somewhat haphazardly. The complicated way in which the code is imprinted into the chip makes it much easier for the manufacturer to produce codes which are rearrangements of other codes than to produce new codes with a different selection of letters. Thus, once a set of letters has been chosen all possible codes derivable from it are used before changing the set. For example, suppose it is decided that a code will contain exactly 3 occurrences of a', 2 of b' and 1 of c', then three of the allowable 60 codes under these conditions are: abaabc abaacb ababac These three codes are listed from top to bottom in alphabetic order. Among all codes generated with this set of characters, these codes appear consecutively in this order. Write a program to assist in the issuing of these identification codes. Your program will accept a sequence of no more than 50 lower case letters (which may contain repeated characters) and print the successor code if one exists or the message No Successor' if the given code is the last in the sequence for that set of characters. 输入: Input will consist of a series of lines each containing a string representing a code. The entire file will be terminated by a line consisting of a single #. 输出: Output will consist of one line for each code read containing the successor code or the words 'No Successor'. 样例输入 abaacb cbbaa # 样例输出 ababac No Successor

最新推荐

recommend-type

setuptools-33.1.1-py2.py3-none-any.whl

Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

解释minorization-maximization (MM) algorithm,并给出matlab代码编写的例子

Minorization-maximization (MM) algorithm是一种常用的优化算法,用于求解非凸问题或含有约束的优化问题。该算法的基本思想是通过构造一个凸下界函数来逼近原问题,然后通过求解凸下界函数的最优解来逼近原问题的最优解。具体步骤如下: 1. 初始化参数 $\theta_0$,设 $k=0$; 2. 构造一个凸下界函数 $Q(\theta|\theta_k)$,使其满足 $Q(\theta_k|\theta_k)=f(\theta_k)$; 3. 求解 $Q(\theta|\theta_k)$ 的最优值 $\theta_{k+1}=\arg\min_\theta Q(
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这
recommend-type

帮我实现在Androidstudio调用chapgpt并提供源码

首先,你需要运行一个ChitGPT的服务器,然后通过Android应用程序与该服务器进行通信。以下是一个简单的Android应用程序示例,可以与ChitGPT进行通信: 1. 首先,在Android Studio中创建一个新的项目,并添加以下依赖项: ``` implementation 'com.squareup.okhttp3:okhttp:4.9.0' implementation 'com.google.code.gson:gson:2.8.6' ``` 2. 创建一个新的Java类,用于与ChitGPT服务器通信。以下是一个简单的实现: ```java import com.
recommend-type

c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf

校园超市商品信息管理系统课程设计旨在帮助学生深入理解程序设计的基础知识,同时锻炼他们的实际操作能力。通过设计和实现一个校园超市商品信息管理系统,学生掌握了如何利用计算机科学与技术知识解决实际问题的能力。在课程设计过程中,学生需要对超市商品和销售员的关系进行有效管理,使系统功能更全面、实用,从而提高用户体验和便利性。 学生在课程设计过程中展现了积极的学习态度和纪律,没有缺勤情况,演示过程流畅且作品具有很强的使用价值。设计报告完整详细,展现了对问题的深入思考和解决能力。在答辩环节中,学生能够自信地回答问题,展示出扎实的专业知识和逻辑思维能力。教师对学生的表现予以肯定,认为学生在课程设计中表现出色,值得称赞。 整个课程设计过程包括平时成绩、报告成绩和演示与答辩成绩三个部分,其中平时表现占比20%,报告成绩占比40%,演示与答辩成绩占比40%。通过这三个部分的综合评定,最终为学生总成绩提供参考。总评分以百分制计算,全面评估学生在课程设计中的各项表现,最终为学生提供综合评价和反馈意见。 通过校园超市商品信息管理系统课程设计,学生不仅提升了对程序设计基础知识的理解与应用能力,同时也增强了团队协作和沟通能力。这一过程旨在培养学生综合运用技术解决问题的能力,为其未来的专业发展打下坚实基础。学生在进行校园超市商品信息管理系统课程设计过程中,不仅获得了理论知识的提升,同时也锻炼了实践能力和创新思维,为其未来的职业发展奠定了坚实基础。 校园超市商品信息管理系统课程设计的目的在于促进学生对程序设计基础知识的深入理解与掌握,同时培养学生解决实际问题的能力。通过对系统功能和用户需求的全面考量,学生设计了一个实用、高效的校园超市商品信息管理系统,为用户提供了更便捷、更高效的管理和使用体验。 综上所述,校园超市商品信息管理系统课程设计是一项旨在提升学生综合能力和实践技能的重要教学活动。通过此次设计,学生不仅深化了对程序设计基础知识的理解,还培养了解决实际问题的能力和团队合作精神。这一过程将为学生未来的专业发展提供坚实基础,使其在实际工作中能够胜任更多挑战。