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、在大型程序中,使函數名易於管理和使用,不必絞盡腦汁地去處理函數名。