【id:74】【20分】E. 新旧身份证(继承)

该博客主要介绍了如何设计和实现一个身份证验证系统,包括15位旧身份证到18位新身份证的转换规则,以及身份证号码的校验码计算方法。通过创建CDate类、COldId类和CNewId类,定义了身份证的属性和验证规则。程序检查身份证号码的合法性,包括校验码验证、出生日期合法性、身份证长度和字符有效性,并考虑了有效期。博客提供了示例输入和输出,展示如何验证不同身份证的有效性。
摘要由CSDN通过智能技术生成

时间限制3s

内存限制128MB

题目描述

按下述方式定义一个日期类CDate和描述15位身份证号的旧身份证类COldId:

class CDate
{

private:
	int year, month, day;
public:
	CDate(int, int, int);
	bool check(); //检验日期是否合法
	bool isLeap();
	void print();
};

class COldId
{
protected:
	char* pId15, * pName; //15位身份证号码,姓名
	CDate birthday; //出生日期
public:
	COldId(char* pIdVal, char* pNameVal, CDate& day);
	bool check(); //验证15位身份证是否合法
	void print();
	~COldId();
};

然后以COldId为基类派生18位身份证号的新身份证类CNewId,并增加3个数据成员:pId18(18位号码)、issueDay(签发日期)和validYear(有效期,年数),并重新定义check()和print()。

15位身份证号扩展为18位身份证号的规则为:前6位号码保持一致,年份由2位变为4位(在前面加上19,例如88变为1988),剩余号码都保持一致,再加上第18位校验码。

身份证第18位校验码的生成方法:

1、将身份证号码前17位数分别乘以7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2。然后将其相加。

2、将17位数字与系数乘加的和除以11,得到余数。

3、余数与校验码的对应关系为1,0,X,9,8,7,6,5,4,3,2。也即:如果余数是3,身份证第18位就是9。如果余数是2,身份证的最后一位号码就是X。

主函数定义一个派生类对象,并用派生类对象调用check(),若返回false则输出“illegal id”否则调用print()输出身份证信息。check()对身份证合法性进行验证的规则:

1. 确认18位号码是从15位号码扩展的,且第18位校验码正确.

2. 身份证中的出生日期合法.

3. 身份证号码中不含非法字符.

4. 身份证号码的长度正确.

5. 身份证目前处于有效期内,假设当前日期为2021年11月9日。

输入

测试数据的组数 t

第一个人姓名、出生日期年月日、15位身份证号码、18位身份证号码、签发日期年月日、有效期(100年按长期处理)

第二个人姓名、出生日期年月日、15位身份证号码、18位身份证

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
pyqt5怎么显示class QueryThread(QThread): query_result = pyqtSignal(object) def __init__(self, id): super().__init__() self.id = id def run(self): conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset') cursor = conn.cursor() cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % self.id) result = cursor.fetchone() conn.close() self.query_result.emit(result) # 发送查询结果信号 class MainWindow(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.query_thread = None # 查询线程 def read_data(self): data = self.ser.readline() if data: id = data.decode().strip() if not self.query_thread: # 如果查询线程不存在,则创建并启动 self.query_thread = QueryThread(id) self.query_thread.query_result.connect(self.update_ui) self.query_thread.start() else: self.query_thread.id = id # 如果查询线程已存在,则更查询ID QTimer.singleShot(100, self.read_data) def update_ui(self, result): if result: self.id_label.setText("员工ID:" + result[0]) self.name_label.setText("姓名:" + str(result[1])) self.six_label.setText("性别:" + result[2]) self.sfz_label.setText("身份证:" + str(result[3])) self.tel_label.setText("电话:" + result[4]) else: self.id_label.setText("员工ID:") self.name_label.setText("姓名:") self.six_label.setText("性别:") self.sfz_label.setText("身份证:") self.tel_label.setText("电话:") def closeEvent(self, event): self.ser.close() if self.query_thread: self.query_thread.quit() self.query_thread.wait()
05-27
要在 PyQt5 中显示这段代码,可以使用 QTextEdit 或者 QPlainTextEdit 组件。首先,需要在程序中导入相关的模块: ```python from PyQt5.QtWidgets import QApplication, QMainWindow, QTextEdit ``` 然后,创建一个 QTextEdit 组件,并将代码添加到其中: ```python class MainWindow(QMainWindow): def __init__(self): super().__init__() self.code_edit = QTextEdit(self) self.code_edit.setReadOnly(True) self.setCentralWidget(self.code_edit) self.code_edit.setPlainText(''' class QueryThread(QThread): query_result = pyqtSignal(object) def __init__(self, id): super().__init__() self.id = id def run(self): conn = pymysql.connect(host='39.99.214.172', user='root', password='Solotion.123', database='jj_tset') cursor = conn.cursor() cursor.execute("SELECT * FROM employee_table WHERE user_id='%s'" % self.id) result = cursor.fetchone() conn.close() self.query_result.emit(result) # 发送查询结果信号 class MainWindow(QMainWindow): def __init__(self): super().__init__() self.query_thread = None # 查询线程 def read_data(self): data = self.ser.readline() if data: id = data.decode().strip() if not self.query_thread: # 如果查询线程不存在,则创建并启动 self.query_thread = QueryThread(id) self.query_thread.query_result.connect(self.update_ui) self.query_thread.start() else: self.query_thread.id = id # 如果查询线程已存在,则更查询ID QTimer.singleShot(100, self.read_data) def update_ui(self, result): if result: self.id_label.setText("员工ID:" + result[0]) self.name_label.setText("姓名:" + str(result[1])) self.six_label.setText("性别:" + result[2]) self.sfz_label.setText("身份证:" + str(result[3])) self.tel_label.setText("电话:" + result[4]) else: self.id_label.setText("员工ID:") self.name_label.setText("姓名:") self.six_label.setText("性别:") self.sfz_label.setText("身份证:") self.tel_label.setText("电话:") def closeEvent(self, event): self.ser.close() if self.query_thread: self.query_thread.quit() self.query_thread.wait() ''') ``` 这样就可以将代码显示在程序的主窗口中了。需要注意的是,这段代码中的 self.ser 没有定义,如果没有在程序中定义,会导致程序出错。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

发愤图强想做全栈的小陈

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

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

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

打赏作者

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

抵扣说明:

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

余额充值