java编写这个通讯录管理系统
java编写这个通讯录管理系统_Java如何实现通讯录管理系统
咕噜噜在芬兰
原创
关注
3点赞·2305人阅读
Java如何实现通讯录管理系统
发布时间:2020-07-28 09:39:42
来源:亿速云
阅读:65
作者:Leah
这篇文章将为大家详细讲解有关Java如何实现通讯录管理系统,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
本文实例为大家分享了java实现通讯录管理系统的具体代码,供大家参考,具体内容如下
完成项目的流程:
1.根据需求,确定大体方向
2.功能模块分析
3.界面实现
4.功能模块设计
5.coding
6.代码测试
下面是源代码:import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.SynchronousQueue;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.text.html.HTMLDocument.Iterator;
class Infro{
public String id;
public String name;
public String sex;
public String address;
public String e_mail;
public String phoneNumber;
static int index = 0;
static ArrayList list = new ArrayList();
static int len = list.size();
//构造函数
public Infro(String id,String name,String sex,String address,String e_mail,String phoneNumber){
this.id = id;
this.name = name;
this.sex = sex;
this.address = address;
this.e_mail = e_mail;
this.phoneNumber = phoneNumber;
}
public String toString(){
return "编号:"+id+" 姓名:"+name+" 性别:"+sex+" 通讯地址:"+address+" 邮箱地址:"+e_mail+" 电话:"+phoneNumber;
}
/**
* 添加功能
**/
public static void addFunction(){//添加功能
Infro infro = new Infro("","","","","","");
System.out.println("请输入添加的数据:");
Scanner in = new Scanner(System.in);
System.out.println("输入编号:");
infro.id = in.next();
System.out.println("输入姓名:");
infro.name = in.next();
System.out.println("输入性别:");
infro.sex = in.next();
System.out.println("输入通讯地址:");
infro.address = in.next();
System.
out.println("输入邮箱地址:");
infro.e_mail = in.next();
System.out.println("输入电话:");
infro.phoneNumber = in.next();
list.add(index,infro);
index++;
if(list.isEmpty()){
System.out.println("数据添加失败啦");
}else{
System.out.println("数据添加成功啦");
len++;//list集合长度加一
// System.out.println(list.get(0).toString());
}
}
// public static void deleteFunction(){//删除功能
// System.out.println("输入要删除的联系人的编号");
// Scanner in_2 = new Scanner(System.in);
// String d1 = in_2.nextLine();
// for(int a= 0; a
// if(d1.equals(list.get(a).id)){
// list.remove(list.get(a));
// len --;
// }
// }
// }
/**
* 删除功能
**/
public static void deleteFunction(){
System.out.println("输入要删除的联系人的编号");
Scanner in_2 = new Scanner(System.in);
String d1 = in_2.nextLine();
java.util.Iterator it = list.iterator();
while (it.hasNext()){
Infro infro = it.next();
if (infro.id.equals(d1)){
it.remove();
--index;//一定要加这个,否则当做了删除操作再做添加操作的时候会出现异常(类似于指针,栈)
System.out.println("删除完毕"+"此时通讯录记录条数为:" + --len);
}
}
}
/**
* 修改功能
**/
public static void reditFunction(){
System.out.println("输入要修改的通讯录的Id");
Scanner in_r = new Scanner(System.in);
String r1 = in_r.nextLine();
for(int a = 0; a < len;a++){
if(r1.equals(list.get(a).id)){
System.out.println("输入修改后的姓名:");
String name_1 = in_r.next();
list.get(a).name = name_1;
System.out.println("输入修改后的性别:");
String sex_1 = in_r.next();
list.get(a).sex = sex_1;
System.out.println("输入修改后的通讯地址:");
String address_1 = in_r.next();
list.get(a).address = address_1;
System.out.println("输入修改后的邮箱地址:");
String e_mail_1 = in_r.next();
list.get(a).e_mail = e_mail_1;
System.out.println("输入修改后的电话:");
String phoneNumber_1 = in_r.next();
list.get(a).phoneNumber = phoneNumber_1;
System.out.println("数据修改完毕");
}
}
}
/**
* 查询功能
**/
public static void searchFunction() throws Exception{//查询功能
System.out.println("请输入要查询的姓名:");
Scanner in_1 = new Scanner(System.in);
String s1=in_1.nextLine();
for(int a= 0; a
if(s1.equals(list.get(a).name)){
System.out.println(list.get(a).toString());
}
}
}
/**
* 显示功能
**/
public static void showFunction(){
for(int i = 0 ;i
System.out.println(list.get(i).toString());
}
}
/**
* 保存功能
**/
public static void writeFunction() throws IOException{
FileWriter writer = new FileWriter("通讯录管理.txt");
for(int i = 0 ;i
String []strwriter = new String[len];
strwriter[i]=list.get(i).toString();
writer.write(strwriter[i]);
writer.write("\r\n");
System.out.println("成功写入一行数据到 通讯录管理.txt 中");
}
writer.close();//关闭写入流,释放资源
}
/**
* 读取功能
**/
public static void readFunction() throws IOException{
FileReader reader = new FileReader("通讯录管理.txt");
BufferedReader br = new BufferedReader(reader);
String str;
while((str = br.readLine()) != null){//每次读取一行文本,判断是否到达文件尾
System.out.println(str);
}
br.close();
}
}
public class Demo extends JFrame {
/**
* 界面设计
**/
public Demo(){
Container c = getContentPane(); //定义一个顶级容器c
JPanel jp = new JPanel(); //新建JPanel面板--jp
JButton button1 = new JButton("新建联系人");
JButton button2 = new JButton("删除联系人");
JButton button3 = new JButton("编辑联系人");
JButton button4 = new JButton("查找联系人");
JButton button5 = new JButton("显示所有联系人");
JButton button6 = new JButton("保存联系人到本地");
JButton button7 = new JButton("读取本地联系人");
jp.setLayout(new GridLayout(2,4,5,5));//新建网格布局管理器(行数,列数,组件间的水平垂直间距)
jp.add(button1);
jp.add(button2);
jp.add(button3);
jp.add(button4);
jp.add(button5);
jp.add(button6);
jp.add(button7);
c.add(jp);//将JPanel面板jp添加到顶级容器c中
setSize(600,500);
setTitle("*通 讯 录 管 理 系 统*");
setVisible(true);
setResizable(false);//窗体大小由程序员决定,用户不能自由改变大小
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
/**
*按键响应
*
**/
button1.addActionListener(new ActionListener(){//添加功能实现
public void actionPerformed(ActionEvent arg0){
Infro.addFunction();
}
});
button2.addActionListener(new ActionListener(){//删除功能实现
public void actionPerformed(ActionEvent arg0){
Infro.deleteFunction();
}
});
button3.addActionListener(new ActionListener(){//修改功能实现
public void actionPerformed(ActionEvent arg0){
Infro.reditFunction();
}
});
button4.addActionListener(new ActionListener(){//查询功能实现
public void actionPerformed(ActionEvent arg0){
try {
Infro.searchFunction();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
button5.addActionListener(new ActionListener(){//显示功能实现
public void actionPerformed(ActionEvent arg0){
Infro.showFunction();
}
});
button6.addActionListener(new ActionListener(){//保存功能实现
public void actionPerformed(ActionEvent arg0){
try {
Infro.writeFunction();
} catch (IOException e) {
e.printStackTrace();
}
}
});
button7.addActionListener(new ActionListener(){//读取功能实现
public void actionPerformed(ActionEvent arg0){
try {
Infro.readFunction();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Demo();
Infro a = new Infro("", "", "", "", "", "");
}
}
关于Java如何实现通讯录管理系统就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
Ⅱ 急求通讯录管理系统(有链表的)数据结构c语言版的源代码。要求c++可以测试通过
这个绝对满足了你的要求了,谢谢采纳`
#include<iostream.h>
#include<string>
#include<stdlib.h>
class List;
class person
{
public:
friend class List;
private:
person() {next=0;}
person *next;
char name[10],tel[15];
};
class List
{
public:
List(){list=0;}
int gncd(); // 功能菜单
int print(); // 输出所有信息
int append(); // 增加一个信息
int revise(); // 根据姓名、电话修改信息
int dele(); // 根据姓名、电话删除信息
int exit(); // 退出
private:
person *end();
person *list;
};
int List::exit()
{
abort();
return 1;
}
int List::gncd()
{
cout<<"************欢迎使用****************************"<<endl;
cout<<"1.输入信息。"<<endl;
cout<<"2.根据姓名、电话修改信息。"<<endl;
cout<<"3.根据姓名、电话删除信息"<<endl;
cout<<"4.输出所有现有成员信息"<<endl;
cout<<"5.退出"<<endl;
cout<<"选择:";
int a;
cin>>a;
switch(a)
{
case(1):this->append();break;
case(2):this->revise();break;
case(3):this->dele();break;
case(4):this->print();break;
case(5):this->exit();break;
}
this->gncd();
return 1;
}
int List::print()
{
if(list==0)
{
cout<<"为空或没输入内容"<<endl;
return 0;
}
person *p=list;
while(p!=NULL)
{
cout<<"姓名:"<<p->name<<endl;
cout<<"电话:"<<p->tel<<endl;
p=p->next;
}
cout<<endl;
return 1;
}
int List::append()
{
person *p=new person;
cout<<"请输入姓名:"<<endl;
cin>>p->name;
cout<<"请输入电话号码:"<<endl;
cin>>p->tel;
char temp;
cout<<"是否继续输入(y/n)";
cin>>temp;
if(temp=='y'||temp=='Y')
this->append();
if(list==0)
list=p;
else
(end())->next=p;
return 1;
}
person *List::end()
{
person *p,*q;
for(q=p=list;p;q=p,p=p->next) ;
return q;
}
int List::revise()
{
person *p=list;
char temp[20];
cout<<"你选择了根据姓名、电话修改信息。"<<endl<<"请输入将要修改的姓名或电话:";
cin>>temp;
int i=0;
while(p!=NULL)
{
if(!strcmp(p->name,temp)||!strcmp(p->tel,temp))
{
i=1;
cout<<"请输入新的姓名:";
cin>>p->name;
cout<<"请输入新的电话号码:";
cin>>p->tel;
}
p=p->next;
}
if(i==1) cout<<"修改成功!"<<endl;
if(i!=1) cout<<"未能找到。"<<endl;
return 1;
}
int List::dele()
{
person *q,*p=list;
char temp[20];
cout<<"你选择了根据姓名、电话删除信息。"<<endl<<"请输入将要删除的姓名或电话:";
cin>>temp;
if(p==NULL)
cout<<"为空或没有输入信息。"<<endl;
if(!strcmp(p->name,temp)||!strcmp(p->tel,temp)) //要删除的结点是第一个时
{
list=p->next;
delete p;
cout<<"删除成功!"<<endl;
}
else
{
while(p!=NULL&&(strcmp(p->name,temp)||strcmp(p->tel,temp)))
{
q=p;
p=p->next;
}
if(p==NULL) return 0;
else if(q==NULL)
cout<<"没能找到。"<<endl;
else
{
q->next=p->next;
delete p;
cout<<"删除成功!"<<endl;
}
}
return 1;
}
void main()
{
List L;
L.gncd();
}
Ⅲ 一个C++的通讯录的源代码
http://post..com/f?kz=115539557
这里有别人问的
你看看吧
太长,贴不过来
下面是题干:
1、利用如下数据结构建立一个同学通讯录
struct Address
{
CString Name; //姓名
CString Location; //住址
CString City; //城市
CString Zip; //邮政编码
CString Telephone; //电话
CString Email; //电子邮件
struct Address * Next; //链表后向指针
struct Address * Prior; //链表前向指针
};
要求实现数据录入,删除,查找,文件操作等多种功能。通讯录根据同学姓名的字符顺序排列。其具体功能请同学们在讲义-〉大作业中去下载例程。同时察看讲义中的几点提示。
Ⅳ 用C作学生通讯录信息管理系统,怎么实现还有源代码
详细情况请到"编程中国"的论坛看看
用C简单编写通讯录源代码(经典)申请加精通讯录源代码
/*10.3.2源程序*/
/******头文件(.h)***********/
#include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*标准库函数*/
#include "string.h"/*字符串函数*/
#include "ctype.h" /*字符操作函数*/
#define M 50 /*定义常数表示记录数*/
typedef struct /*定义数据结构*/
{
char name[20]; /*姓名*/
char units[30]; /*单位*/
char tele[10]; /*电话*/
}ADDRESS;
/******以下是函数原型*******/
int enter(ADDRESS t[]); /*输入记录*/
void list(ADDRESS t[],int n); /*显示记录*/
void search(ADDRESS t[],int n); /*按姓名查找显示记录*/
int delete(ADDRESS t[],int n); /*删除记录*/
int add(ADDRESS t[],int n); /*插入记录*/
void save(ADDRESS t[],int n); /*记录保存为文件*/
int load(ADDRESS t[]); /*从文件中读记录*/
void display(ADDRESS t[]); /*按序号查找显示记录*/
void sort(ADDRESS t[],int n); /*按姓名排序*/
void qseek(ADDRESS t[],int n); /*快速查找记录*/
void (); /*文件复制*/
void print(ADDRESS temp); /*显示单条记录*/
int find(ADDRESS t[],int n,char *s) ; /*查找函数*/
int menu_select(); /*主菜单函数*/
/******主函数开始*******/
main()
{
int i;
ADDRESS adr[M]; /*定义结构体数组*/
int length; /*保存记录长度*/
clrscr(); /*清屏*/
for(;;)/*无限循环*/
{
switch(menu_select()) /*调用主菜单函数,返回值整数作开关语句的条件*/
{
case 0:length=enter(adr);break;/*输入记录*/
case 1:list(adr,length);break; /*显示全部记录*/
case 2:search(adr,length);break; /*查找记录*/
case 3:length=delete(adr,length);break; /*删除记录*/
case 4:length=add(adr,length); break; /*插入记录*/
case 5:save(adr,length);break; /*保存文件*/
case 6:length=load(adr); break; /*读文件*/
case 7:display(adr);break; /*按序号显示记录*/
case 8:sort(adr,length);break; /*按姓名排序*/
case 9:qseek(adr,length);break; /*快速查找记录*/
case 10:();break; /*复制文件*/
case 11:exit(0); /*如返回值为11则程序结束*/
}
}
}
/*菜单函数,函数返回值为整数,代表所选的菜单项*/
menu_select()
{
char s[80];
int c;
gotoxy(1,25);/*将光标定为在第25行,第1列*/
printf("press any key enter menu......\n");/*提示压任意键继续*/
getch(); /*读入任意字符*/
clrscr(); /*清屏*/
gotoxy(1,1);
printf("********************MENU*********************\n\n");
printf(" 0. Enter record\n");
printf(" 1. List the file\n");
printf(" 2. Search record on name\n");
printf(" 3. Delete a record\n");
printf(" 4. add record \n");
printf(" 5. Save the file\n");
printf(" 6. Load the file\n");
printf(" 7. display record on order\n");
printf(" 8. sort to make new file\n");
printf(" 9. Quick seek record\n");
printf(" 10. the file to new file\n");
printf(" 11. Quit\n");
printf("***********************************************\n");
do{
printf("\n Enter you choice(0~11):"); /*提示输入选项*/
scanf("%s",s); /*输入选择项*/
c=atoi(s); /*将输入的字符串转化为整型数*/
}while(c<0||c>11); /*选择项不在0~11之间重输*/
return c; /*返回选择项,主程序根据该数调用相应的函数*/
}
/***输入记录,形参为结构体数组,函数值返回类型为整型表示记录长度*/
int enter(ADDRESS t[])
{
int i,n;
char *s;
clrscr(); /*清屏*/
printf("\nplease input num \n"); /*提示信息*/
scanf("%d",&n); /*输入记录数*/
printf("please input record \n"); /*提示输入记录*/
printf("name unit telephone\n");
printf("------------------------------------------------\n");
for(i=0;i<n;i++)
{
scanf("%s%s%s",t[i].name,t[i].units,t[i].tele); /*输入记录*/
printf("----------------------------------------------\n");
}
return n; /*返回记录条数*/
}
/*显示记录,参数为记录数组和记录条数*/
void list(ADDRESS t[],int n)
{
int i;
clrscr();
printf("\n\n*******************ADDRESS******************\n");
printf("name unit telephone\n");
printf("------------------------------------------------\n");
for(i=0;i<n;i++)
printf("%-20s%-30s%-10s\n",t[i].name,t[i].units,t[i].tele);
if((i+1)%10==0) /*判断输出是否达到10条记录*/
{
printf("Press any key continue...\n"); /*提示信息*/
getch(); /*压任意键继续*/
}
printf("************************end*******************\n");
}
/*查找记录*/
void search(ADDRESS t[],int n)
{
char s[20]; /*保存待查找姓名字符串*/
int i; /*保存查找到结点的序号*/
clrscr(); /*清屏*/
printf("please search name\n");
scanf("%s",s); /*输入待查找姓名*/
i=find(t,n,s); /*调用find函数,得到一个整数*/
if(i>n-1) /*如果整数i值大于n-1,说明没找到*/
printf("not found\n");
else
print(t[i]); /*找到,调用显示函数显示记录*/
}
/*显示指定的一条记录*/
void print(ADDRESS temp)
{
clrscr();
printf("\n\n********************************************\n");
printf("name unit telephone\n");
printf("------------------------------------------------\n");
printf("%-20s%-30s%-10s\n",temp.name,temp.units,temp.tele);
printf("**********************end***********************\n");
}
/*查找函数,参数为记录数组和记录条数以及姓名s */
int find(ADDRESS t[],int n,char *s)
{
int i;
for(i=0;i<n;i++)/*从第一条记录开始,直到最后一条*/
{
if(strcmp(s,t[i].name)==0) /*记录中的姓名和待比较的姓名是否相等*/
return i; /*相等,则返回该记录的下标号,程序提前结结束*/
}
return i; /*返回i值*/
}
/*删除函数,参数为记录数组和记录条数*/
int delete(ADDRESS t[],int n)
{
char s[20]; /*要删除记录的姓名*/
int ch=0;
int i,j;
printf("please deleted name\n"); /*提示信息*/
scanf("%s",s);/*输入姓名*/
i=find(t,n,s); /*调用find函数*/
if(i>n-1) /*如果i>n-1超过了数组的长度*/
printf("no found not deleted\n"); /*显示没找到要删除的记录*/
else
{
print(t[i]); /*调用输出函数显示该条记录信息*/
printf("Are you sure delete it(1/0)\n"); /*确认是否要删除*/
scanf("%d",&ch); /*输入一个整数0或1*/
if(ch==1) /*如果确认删除整数为1*/
{
for(j=i+1;j<n;j++) /*删除该记录,实际后续记录前移*/
{
strcpy(t[j-1].name,t[j].name); /*将后一条记录的姓名拷贝到前一条*/
strcpy(t[j-1].units,t[j].units); /*将后一条记录的单位拷贝到前一条*/
strcpy(t[j-1].tele,t[j].tele); /*将后一条记录的电话拷贝到前一条*/
}
n--; /*记录数减1*/
}
}
return n; /*返回记录数*/
}
/*插入记录函数,参数为结构体数组和记录数*/
int add(ADDRESS t[],int n)/*插入函数,参数为结构体数组和记录数*/
{
ADDRESS temp; /*新插入记录信息*/
int i,j;
char s[20]; /*确定插入在哪个记录之前*/
printf("please input record\n");
printf("************************************************\n");
printf("name unit telephone\n");
printf("--------------------------------------------------\n");
scanf("%s%s%s",temp.name,temp.units,temp.tele); /*输入插入信息*/
printf("------------------------------------------------\n");
printf("please input locate name \n");
scanf("%s",s); /*输入插入位置的姓名*/
i=find(t,n,s); /*调用find,确定插入位置*/
for(j=n-1;j>=i;j--) /*从最后一个结点开始向后移动一条*/
{
strcpy(t[j+1].name,t[j].name); /*当前记录的姓名拷贝到后一条*/
strcpy(t[j+1].units,t[j].units); /*当前记录的单位拷贝到后一条*/
strcpy(t[j+1].tele,t[j].tele); /*当前记录的电话拷贝到后一条*/
}
strcpy(t[i].name,temp.name); /*将新插入记录的姓名拷贝到第i个位置*/
strcpy(t[i].units,temp.units); /*将新插入记录的单位拷贝到第i个位置*/
strcpy(t[i].tele,temp.tele); /*将新插入记录的电话拷贝到第i个位置*/
n++; /*记录数加1*/
return n; /*返回记录数*/
}
/*保存函数,参数为结构体数组和记录数*/
void save(ADDRESS t[],int n)
{
int i;
FILE *fp; /*指向文件的指针*/
if((fp=fopen("record.txt","wb"))==NULL) /*打开文件,并判断打开是否正常*/
{
printf("can not open file\n");/*没打开*/
exit(1); /*退出*/
}
printf("\nSaving file\n"); /*输出提示信息*/
fprintf(fp,"%d",n); /*将记录数写入文件*/
fprintf(fp,"\r\n"); /*将换行符号写入文件*/
for(i=0;i<n;i++)
{
fprintf(fp,"%-20s%-30s%-10s",t[i].name,t[i].units,t[i].tele);/*格式写入记录*/
fprintf(fp,"\r\n"); /*将换行符号写入文件*/
}
fclose(fp);/*关闭文件*/
printf("****save success***\n"); /*显示保存成功*/
}
/*读入函数,参数为结构体数组*/
int load(ADDRESS t[])
{
int i,n;
FILE *fp; /*指向文件的指针*/
if((fp=fopen("record.txt","rb"))==NULL)/*打开文件*/
{
printf("can not open file\n"); /*不能打开*/
exit(1); /*退出*/
}
fscanf(fp,"%d",&n); /*读入记录数*/
for(i=0;i<n;i++)
fscanf(fp,"%20s%30s%10s",t[i].name,t[i].units,t[i].tele); /*按格式读入记录*/
fclose(fp); /*关闭文件*/
printf("You have success read data from file!!!\n"); /*显示保存成功*/
return n; /*返回记录数*/
}
/*按序号显示记录函数*/
void display(ADDRESS t[])
{
int id,n;
FILE *fp; /*指向文件的指针*/
if((fp=fopen("record.txt","rb"))==NULL) /*打开文件*/
{
printf("can not open file\n"); /*不能打开文件*/
exit(1); /*退出*/
}
printf("Enter order number...\n"); /*显示信息*/
scanf("%d",&id); /*输入序号*/
fscanf(fp,"%d",&n); /*从文件读入记录数*/
if(id>=0&&id<n) /*判断序号是否在记录范围内*/
{
fseek(fp,(id-1)*sizeof(ADDRESS),1); /*移动文件指针到该记录位置*/
print(t[id]); /*调用输出函数显示该记录*/
printf("\r\n");
}
else
printf("no %d number record!!!\n ",id); /*如果序号不合理显示信息*/
fclose(fp); /*关闭文件*/
}
/*排序函数,参数为结构体数组和记录数*/
void sort(ADDRESS t[],int n)
{
int i,j,flag;
ADDRESS temp; /*临时变量做交换数据用*/
for(i=0;i<n;i++)
{
flag=0; /*设标志判断是否发生过交换*/
for(j=0;j<n-1;j++)
if((strcmp(t[j].name,t[j+1].name))>0) /*比较大小*/
{
flag=1;
strcpy(temp.name,t[j].name); /*交换记录*/
strcpy(temp.units,t[j].units);
strcpy(temp.tele,t[j].tele);
strcpy(t[j].name,t[j+1].name);
strcpy(t[j].units,t[j+1].units);
strcpy(t[j].tele,t[j+1].tele);
strcpy(t[j+1].name,temp.name);
strcpy(t[j+1].units,temp.units);
strcpy(t[j+1].tele,temp.tele);
}
if(flag==0)break; /*如果标志为0,说明没有发生过交换循环结束*/
}
printf("sort sucess!!!\n"); /*显示排序成功*/
}
/*快速查找,参数为结构体数组和记录数*/
void qseek(ADDRESS t[],int n)
{
char s[20];
int l,r,m;
printf("\nPlease sort before qseek!\n"); /*提示确认在查找之前,记录是否已排序*/
printf("please enter name for qseek\n"); /*提示输入*/
scanf("%s",s); /*输入待查找的姓名*/
l=0;r=n-1; /*设置左边界与右边界的初值*/
while(l<=r) /*当左边界<=右边界时*/
{
m=(l+r)/2; /*计算中间位置*/
if(strcmp(t[m].name,s)==0) /*与中间结点姓名字段做比较判是否相等*/
{
print(t[m]); /*如果相等,则调用print函数显示记录信息*/
return ; /*返回*/
}
if(strcmp(t[m].name,s)<0) /*如果中间结点小*/
l=m+1; /*修改左边界*/
else
r=m-1; /*否则,中间结点大,修改右边界*/
}
if(l>r) /*如果左边界大于右边界时*/
printf("not found\n"); /*显示没找到*/
}
/*复制文件*/
void ()
{
char outfile[20]; /*目标文件名*/
int i,n;
ADDRESS temp[M]; /*定义临时变量*/
FILE *sfp,*tfp; /*定义指向文件的指针*/
clrscr();/*清屏*/
if((sfp=fopen("record.txt","rb"))==NULL) /*打开记录文件*/
{
printf("can not open file\n"); /*显示不能打开文件信息*/
exit(1); /*退出*/
}
printf("Enter outfile name,for example c:\\f1\\te.txt:\n"); /*提示信息*/
scanf("%s",outfile); /*输入目标文件名*/
if((tfp=fopen(outfile,"wb"))==NULL) /*打开目标文件*/
{
printf("can not open file\n"); /*显示不能打开文件信息*/
exit(1); /*退出*/
}
fscanf(sfp,"%d",&n); /*读出文件记录数*/
fprintf(tfp,"%d",n);/*写入目标文件数*/
fprintf(tfp,"\r\n"); /*写入换行符*/
for(i=0;i<n;i++)
{
fscanf(sfp,"%20s%30s%10s\n",temp[i].name,temp[i].units,
temp[i].tele); /*读入记录*/
fprintf(tfp,"%-20s%-30s%-10s\n",temp[i].name,
temp[i].units,temp[i].tele); /*写入记录*/
fprintf(tfp,"\r\n"); /*写入换行符*/
}
fclose(sfp); /*关闭源文件*/
fclose(tfp); /*关闭目标文件*/
printf("you have success file!!!\n"); /*显示复制成功*/
}
Ⅳ 学生通讯录管理系统谁能提供一下c++源代码
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void input();
void search();
void modify();
void tongji();
void menu();
extern class student
{ public:
char name[20];
int num;
int age;
char sex;
char addr[50];
int tel;
int roomnum;
};
extern student s1;
extern student n;
//int n; //学生人数,全局变量
****************************************
//学生信息的输入
#include "1.h"
//***********************************************************************
void input()
{
fstream file;
file.open("d://student.txt",ios::out);//以输出方式打开文件,如果已经有此名字的文件,则其原有内容全部删除。
cout<<" please input student's message!"<<endl;
char ch='y';
while(ch=='y'||ch=='Y')
{
student n;
cout<<setw(6)<<"姓名"<<setw(6)<<"学号"<<setw(6)<<"年龄" <<setw(6)<<"性别"<<setw(6)<<"地址" <<setw(10)<<"联系电话"<<setw(9)<<"寝室号"<<endl;
cin>>n.name>>n.num>>n.age>>n.sex>>n.addr>>n.tel>>n.roomnum;
file<<setw(6)<<n.name<<setw(6)<<n.num<<setw(6)<<n.age<<setw(6)<<n.sex<<setw(10)<<n.addr<<setw(10)<<n.tel<<setw(9)<<n.roomnum<<endl;
cout<<"继续输入?Y/N";
cin>>ch;
}
menu();
file.close();
}
//*************************************************************************
//学生信息的修改
void modify()
{
fstream file;
//student s1;
file.open("d:://student.txt",ios::in|ios::out);//以输入输出方式打开文件,文件可读可写。
cout<<"please enter password(1):";
int p;
cin>>p;
if(p!=1)
{
cout<<"error!try again!"<<endl;
return;
}
file.close();
//else
menu();
}
//***********************************************************************
//学生信息查询
void search()
{
char *inputname=new char[20];
fstream file;
file.open("d:\\student.txt",ios::in|ios::out);//以输方式打开文件
student n;
cout<<"1.按姓名查询 "<<" 2.按学号查询"<<endl;
int a;
cin>>a;
if(a==1)
{
cout<<"请输入您要查询的学生的姓名:";
cin>>inputname;
if(strcmp(n.name,inputname)==0)
{
cout<<"学生"<<inputname<<"的信息如下:"<<endl;
cout<<setw(6)<<n.name<<setw(6)<<n.num<<setw(6)<<n.age<<setw(6)<<n.sex<<setw(10)<<n.addr<<setw(10)<<n.tel<<setw(9)<<n.roomnum<<endl;
}
else cout<<"您的输入有误,请重新输入!";return;
}
else if(a==2)
{
cout<<"请输入您要查询的学生的学号:";
int inputnum;
cin>>inputnum;
file>>n.name>>n.num;
if(n.num==inputnum)
{
cout<<"学生"<<inputnum<<"的信息如下:"<<endl;
cout<<setw(6)<<n.name<<setw(6)<<n.num<<setw(6)<<n.age<<setw(6)<<n.sex<<setw(6)<<n.addr<<setw(10)<<n.tel<<setw(9)<<n.roomnum<<endl;
}
else cout<<"您的输入有误,请重新输入!"<<endl;
}
file.close();
menu();
}
//********************************************************************
//学生信息统计
void tongji()
{
fstream file;
cout<<"学生信息按学号统计如下:"<<endl;
cout<<setw(6)<<"姓名"<<setw(6)<<"学号"<<setw(6)<<"年龄" <<setw(6)<<"性别"<<setw(6)<<"地址" <<setw(10)<<"联系电话"<<setw(9)<<"寝室号"<<endl;
file.open("d:://student.txt",ios::in|ios::out); //以输入输出方式打开文件,文件可读可写。
cout<<setw(6)<<n.name<<setw(6)<<n.num<<setw(6)<<n.age<<setw(6)<<n.sex<<setw(6)<<n.addr<<setw(10)<<n.tel<<setw(9)<<n.roomnum<<endl;
menu();
}
************************************************************
#include "11.h"
void menu()
{
cout<<" ************************************* "<<endl;
cout<<"*********欢迎使用学生通讯录管理系统*********"<<endl;
cout<<" ************************************* "<<endl;
while(1)
{
cout<<"请选择服务种类:"<<endl;
cout<<"1 数据录入 "<<"2 数据查询 "<<"3 数据修改 "<<"4 数据统计 "<<"5 退出系统"<<endl;
int ch;
cin>>ch;
switch(ch)
{
case 1:input();break;
case 2:search();break;
case 3:modify();break;
case 4:tongji();break;
case 5:cout<<"谢谢您的使用!"<<endl;return;break;
default:cout<<"您的选择有误!";break;
}
}
}
int main ()
{
menu();
return 0;
}
Ⅵ javaweb 做一个通讯录的小项目 求源代码 急求。
先设计数据库中通讯录表格(字段有:id,联系人姓名,手机号,备注),然后,hebinate实现数据库表到javabean的映射,同时也会生成对通讯录表格的增删改查的基本sql语句对应的接口。然后你再写一个Servlet,连接页面自己数据库操作接口即可
Ⅶ 怎么使用Asp做通讯录的源码
要看你做什么通讯录了。最好是去网上下载中文的对照拼音数据库。然后录入的时候将姓名对应的拼音也存进去。
如果只是存储然后查询就很简单了。弄个ACCESS就行了。然后左边或者上面有A-Z字母可以点击跳到相应的记录。
Ⅷ c++通讯录源码
昨晚实现了用C++编写通讯录,深刻的感受到了封装的便利性啊,vector真是太方便了!!!
代码如下:
info.h
#ifndef_PERSON_H_
#define_PERSON_H_
#include<iostream>
#include<vector>
#include<string>
usingnamespacestd;
classInfo
{
private:
intid;
stringname;
stringtel;
stringaddr;
public:
Info();
~Info();
staticintcount;//记录通讯录中的人数
intGetId();
voidSetName();
stringGetName()const;
voidSetTel();
stringGetTel()const;
voidSetAddr();
stringGetAddr()const;
voidchoose();
voidinsert();
voidshow();
voidsearch();
voidinterface();
voiddelete_info();
voidexit_info();
voidmodify();
};
#endif
Ⅸ 用C语言编写一个通讯录管理系统
C语言编写一个通讯录管理系统的源代码如下:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*定义保存通迅录的信息*/
structfriends
{
charname[20];/*名字*/
charprovince[20];/*省份*/
charcity[20];/*所在城市*/
charnation[20];/*民族*/
charsex[2];/*性别M/F*/
intage;/*年龄*/
}
(9)网页版通讯录系统源码扩展阅读
1、在C++中应该使用inline内连函数替代宏调用,这样既可达到宏调用的目的,又避免了宏调用的弊端。
2、在C语言两个函数的名称不能相同,否则会导致编译错误。在C++中,函数名相同而参数不同的两个函数被解释为重载。
3、在大型程序中,使函数名易于管理和使用,不必绞尽脑汁地去处理函数名。