#include
class Assc_array
{ struct Item
{ char *name;
long tel_num;
};
Item *table;
int max;
int items;
public:
Assc_array(int);
long & operator[](char *);
void printAll();
};
Assc_array::Assc_array(int nm=0)
{ max=nm;
items=0;
table=new Item[max];
}
long & Assc_array::operator[](char *nm)
{ Item *pi;
for (pi=table;pi
return pi->tel_num;
pi=table+items++;
pi->name=new char[strlen(nm)+1];
strcpy(pi->name,nm);
pi->tel_num=0;
return pi->tel_num;
}
void Assc_array::printAll()
{ for (int i=0;i
void main()
{ Assc_array tel_num_table(10);
tel_num_table["zhang"]=7075461;
tel_num_table["li"]=4047658;
tel_num_table["tan"]=2595121;
tel_num_table["cai"]=7732435;
cout<<"zhang->"<
}
同学,是理工的吧?