姓名常用汉字代码查询器

        今天看C++primer的时候看到String读写的时候,突然想到可以将姓名常用汉字代码按一定格式读入到链表节点当中,然后编程实现所有汉字代码的添加和查询,下面附上代码,正在学习中,技术有限哈。

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class node
{
public:
	string name;
	string number;
	node *next;
	node(){name="";number="";next=NULL;}
};
class list
{
	node *head;
	node *last;
public:
	list();
	void add(string &Name,string &Number);
	void select(string &Name);
};
list::list()
{
	head=NULL;
	last=NULL;
}
void list::add(string &Name,string &Number)
{
	if(head==NULL)
	{
		head=new node;
        head->name=Name;
		head->number=Number;
		head->next=NULL;
		last=head;
		last->next=NULL;
	}
	else
	{
		node *P=new node;
		P->name=Name;
		P->number=Number;
		P->next=NULL;
		last->next=P;
		last=P;
	}
}
void list::select(string &Name)
{
	if(head==NULL)
	{
		cout<<"NULL ~!"<<endl;
		return;
	}
	node *P=head;
	while(P!=NULL)
	{
		if(P->name==Name)
		{
			cout<<Name<<"的编码为:"<<P->number<<endl;
			return;
		}
		P=P->next;
	}
	cout<<"系统没有"<<Name<<"这个字,请查证!"<<endl;
	//select(Name);
	system("cls");
}
void main()
{
	
    string str,str2;
	list LIST;
	ifstream in("姓名常用汉字代码.txt");
	ofstream out("姓名汉字代码.txt");
	if(!in.is_open())
	{
		cout<<"打开数据文件失败~!"<<endl;
		exit(0);
	}
	
	cout<<"字库加载中。。。"<<endl;
	while(!in.eof())
	{
		in>>str>>str2;
		// out<<str+str2<<endl;
		// cout<<str+str2<<endl;
        LIST.add(str,str2);
		
	}
	cout<<"字库加载完毕"<<endl;
	while(1)
	{
		cout<<"请输入你想查询的汉字:";
		cin>>str;
		LIST.select(str);
	}
}


 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值