error C2440: 'initializing' : cannot convert from 'struct people *' to 'int'
#include<iostream.h>#include"string.h"structpeople{intphone,classnum;charname[20],adr...
#include<iostream.h>
#include "string.h"
struct people
{
int phone,classnum;
char name[20],adress[50];
};
void input(people s[],int p)//输入模块
{
for(int i=0;i<p;i++)
{
cout<<"请输入第"<<i+1<<"联系人信息"<<endl;
cout<<"输入名字:";
cin>>s[i].name;
cout<<"输入学号:";
cin>>s[i].classnum;
cout<<"输入电话号码:";
cin>>s[i].phone;
cout<<"输入地址:";
cin>>s[i].adress;
}
cout<<"共输入"<<i<<"名联系人信息"<<endl;
}
people * erfenfa(people s[],int n,int x)//学生个人信息按学号搜索模块
{
int i,j;//学生学号按小到大排序
people t;
for(i=1;i<=n-1;i++)
for(j=0;j<=n-i-1;j++)
if(s[j].classnum>s[j+1].classnum)
{
t=s[j];
s[j]=s[j+1];
s[j+1]=t;}
int min=0,max=n-1;//二分法查找
int mid;
while(min<=max)
{
mid=(min+max)/2;
if(s[mid].classnum==x)
return &s[mid];
if(s[mid].classnum<x)
min=mid+1;
else
max=mid-1;
}
return 0;
}
const int M=100;
void main()
{people peo[M];
input(peo,5);
int g;
cout<<"请输入一个待查学生的学号:"; cin>>g;
int f=erfenfa(peo,5,g);
cout<<peo[f].name<<peo[f].classnum<<peo[f]
.phone<<endl;
}
求大神指教
菜鸟新手 展开
#include "string.h"
struct people
{
int phone,classnum;
char name[20],adress[50];
};
void input(people s[],int p)//输入模块
{
for(int i=0;i<p;i++)
{
cout<<"请输入第"<<i+1<<"联系人信息"<<endl;
cout<<"输入名字:";
cin>>s[i].name;
cout<<"输入学号:";
cin>>s[i].classnum;
cout<<"输入电话号码:";
cin>>s[i].phone;
cout<<"输入地址:";
cin>>s[i].adress;
}
cout<<"共输入"<<i<<"名联系人信息"<<endl;
}
people * erfenfa(people s[],int n,int x)//学生个人信息按学号搜索模块
{
int i,j;//学生学号按小到大排序
people t;
for(i=1;i<=n-1;i++)
for(j=0;j<=n-i-1;j++)
if(s[j].classnum>s[j+1].classnum)
{
t=s[j];
s[j]=s[j+1];
s[j+1]=t;}
int min=0,max=n-1;//二分法查找
int mid;
while(min<=max)
{
mid=(min+max)/2;
if(s[mid].classnum==x)
return &s[mid];
if(s[mid].classnum<x)
min=mid+1;
else
max=mid-1;
}
return 0;
}
const int M=100;
void main()
{people peo[M];
input(peo,5);
int g;
cout<<"请输入一个待查学生的学号:"; cin>>g;
int f=erfenfa(peo,5,g);
cout<<peo[f].name<<peo[f].classnum<<peo[f]
.phone<<endl;
}
求大神指教
菜鸟新手 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询