Emery_fly 2017-03-30 06:24 采纳率: 50%
浏览 1024

代码如下,修改代码使每个结点的“电话号码”转换为字符串,提取后四位显示。怎么做啊??

无符号长整型转换为字符串不会啊!!!
#include
#include
#include
using namespace std;
typedef struct
{
string namePY;
string nameHZ;
unsigned long long tel;
string position;
string addr;
}record,*precord;
typedef struct node
{
record data;
node* next;
}NODE,*pNODE;
pNODE initlist(void)
{
NODE head=new NODE;
if(head==NULL)
{cout<<"内存不足,退出...";exit(0);}
head->next=NULL;
return head;
}
pNODE makelist(int n,ifstream&in)
{
pNODE head=initlist();
pNODE tail=head;
pNODE node;
record data;
for(int i=0;i {
in>>data.namePY;
string firstname;
in>>firstname;
data.namePY+=firstname;
in>>data.nameHZ;
in>>data.tel;
in>>data.position;
in>>data.addr;
node=new NODE;
node->data=data;
tail->next=node;
tail=node;
}
tail->next=NULL;
return head;
}
void showone(pNODE node,unsigned long long tel)
{
cout<data.namePY<<" ";
cout<data.nameHZ<<" ";
char buffer[1240];
sprintf(buffer,"%d",tel);
cout< coutdata.position<<" ";
cout<data.addr<<"\n";
}
int travellist(pNODE head,void(*DO)(pNODE node,unsigned long long tel))
{
int count=0;
if(head==NULL)return 0;
pNODE p=head->next;
while(p!=NULL)
{
count++;
(*DO)(p,p->data.tel);
p=p->next;
}
return count;
}
pNODE list_locate(pNODE head,string nameHZ)
{
pNODE p=head->next;
while(p!=NULL&&p->data.nameHZ!=nameHZ)
p=p->next;
if(p==NULL) return NULL;
return p;
}
pNODE list_prior(pNODE head,string nameHZ)
{
pNODE p=head;
while(p->next!=NULL&&p->next->data.nameHZ!=nameHZ)
p=p->next;
if(p->next==NULL)return NULL;
return p;
}
void list_del(pNODE head,string nameHZ)
{
pNODE pri=list_prior(head,nameHZ);
pNODE del=pri->next;
pri->next=del->next;
delete del;
}
/*void list_insert(pNODE head,string nameHZ,NODE*New)
{
pNODE the=list_locate(head,nameHZ);
pNODE temp=the->next;
the->next=New;
New->next=temp;
}
/
pNODE list_tellocate(pNODE head,unsigned long long tel)
{
pNODE p=head->next;
while(p!=NULL&&p->data.tel!=tel)
p=p->next;
if(p==NULL) return NULL;
return p;
}
void list_insert(pNODE head,unsigned long long tel,NODE*New)
{
pNODE the=list_tellocate(head,tel);
pNODE p=head;
while(p->next!=the)
{
p=p->next;
}
pNODE temp=p->next;
p->next=New;
New->next=temp;
}
void list_delall(pNODE&head)
{
pNODE p;
while(head)
{
p=head;
head=head->next;
delete p;
}
}
int main()
{
int num;
ifstream infile("电话号码簿.txt");
char*temp=new char[1024];
infile>>temp;
infile>>num;
infile.getline(temp,1024,'\n');
infile.getline(temp,1024,'\n');
delete[]temp;
pNODE head=makelist(num,infile);
infile.close();
int n=travellist(head,showone);
cout<<"结点个数:"< cout pNODE node=list_locate(head,"张语");
coutdata.nameHZ<<" "<data.tel< cout list_del(head,"臧誉");
list_del(head,"臧愈");
n=travellist(head,showone);
cout cout record one={"zangyu","臧誉",18583777077,"主策划","广州"};
pNODE newnode=new NODE;
newnode->data=one;
newnode->next=NULL;
list_insert(head,18202895898,newnode);
n=travellist(head,showone);
cout<<"结点个数:"<<n<<endl;
cout<<"----删除整个链表---------"<<endl;
list_delall(head);
cout<<"表头结点地址:"<<head<<endl;
system("pause"); return 0;
}

  • 写回答

2条回答 默认 最新

  • kidknight 2017-03-30 08:56
    关注

    模10000取后四位,%04d 打印成字符串

    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境