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 打印成字符串

    评论

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退