⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 telephone_directory.cpp

📁 Contains a project on the managment of a telephone directory.. Feel free to download and use..
💻 CPP
📖 第 1 页 / 共 3 页
字号:

//**********************************************************
//      PROJECT TELEPHONE DIARY
//**********************************************************

//**********************************************************
//      INCLUDED HEADER FILES
//**********************************************************

#include <conio.h>
#include <dos.h>
#include <string.h>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>


//**********************************************************
//      CLASS NAME : MENU
//      DETAILS    : IT CONTROLS OVER ALL THE FUNCTIONS
//**********************************************************

class menu
{
	public :
			void main_menu(void) ;
			void startup(void) ;
			void box(void) ;
			void line_hor (int, int, int, char) ;
			void line_ver (int, int, int, char) ;
} ;

//**********************************************************
//      CLASS NAME : DIARY
//      DETAILS    : IT CONTROLLS OVER ALL THE FUNCTIONS
//                         RELATED TO DIARY
//**********************************************************

class diary
{
	public :
			diary(void) ;
			~diary(void) ;
			void add(void) ;
			void modify(void) ;
			void deletion(void) ;
			void display_list(void) ;
	private :
			void sort(void) ;
			void display_record(int) ;
			int  found_record(int) ;
			void delete_record(int) ;
			void modify_record(int) ;
			int  recordno(int) ;
			int  last_code(void) ;

			int code ;
			char name[20], phone1[10], phone2[10], phone3[10],
					     e_mail[30], address[45] ;

} ;


//**********************************************************
//      CLASS NAME    : MENU
//      FUNCTION NAME : LINE_HOR
//      DETAILS       : IT ACCEPTS THE ROWS AND COLUMNS AND
//                               DRAW THE HORIZONTAL LINE
//**********************************************************

void menu :: line_hor(int column1, int column2, int row, char c)
{
	for ( column1; column1<=column2; column1++ )
	{
		gotoxy(column1,row) ;
		cout <<c ;
	}
}


//**********************************************************
//      CLASS NAME    : MENU
//      FUNCTION NAME : LINE_VER
//      DETAILS       : IT ACCEPTS THE ROWS AND COLUMNS AND
//                               DRAW THE VERTICAL LINE
//**********************************************************

void menu :: line_ver(int row1, int row2, int column, char c)
{
	for ( row1; row1<=row2; row1++ )
	{
		gotoxy(column,row1) ;
		cout <<c ;
	}
}


//**********************************************************
//      CLASS NAME    : MENU
//      FUNCTION NAME : STARTUP
//      DETAILS       : IT CREATS THE STARTING SCREEN
//**********************************************************

void menu :: startup(void)
{
	clrscr() ;
	int i, j, s ;

	char a[]="T E L E P H O N E" ;
	char b[]="D I A R Y" ;
	for (i=1; i<=79; i++)
		line_ver(1,25,i,179) ;
	gotoxy(1,11) ; clreol() ;
	gotoxy(1,13) ; clreol() ;
	gotoxy(29,5);clreol();
	gotoxy(29,7);clreol();
	gotoxy(29,6);cout<<"S A U R A B H  J A I N";
	for(i=51;i<=79;i++)
	 line_ver(5,7,i,179);
	gotoxy(18,18);clreol();
	gotoxy(18,20);clreol();
	gotoxy(18,19);cout<<"S Y E D  A S A D  H A I D E R  Z A I D I ";
	for(i=58;i<=79;i++)
	 line_ver(18,20,i,179);
	j = 63 ;
	s = 100 ;
	for (i=1; i<=43; i++)
	{
		sound(s) ;
		s = s + 20 ;
		delay(50) ;
		gotoxy(1,12) ;
		clreol() ;
		gotoxy(i,12) ;
		cout <<b ;
		gotoxy(j,12) ;
		cout <<a ;
		j-- ;
		gotoxy(1,1) ;
	}
	nosound() ;
	delay(100) ;
	char ch=219 ;
	s = 500 ;
	for (i=1; i<=79; i++)
	{
		sound(s) ;
		s = s + 10 ;
		gotoxy(i,10) ;
		cout <<ch ;
		delay(5) ;
	}
	nosound() ;
	delay(200) ;
	ch=219 ;
	s = 1290 ;
	for (i=79; i>=1; i--)
	{
		sound(s) ;
		s = s - 10 ;
		gotoxy(i,14) ;
		cout <<ch ;
		delay(5) ;
	}
	nosound() ;
	delay(1000) ;
}


//**********************************************************
//      CLASS NAME    : MENU
//      FUNCTION NAME : BOX
//      DETAILS       : IT CREATS BOX FOR THE MENU
//**********************************************************

void menu :: box(void)
{
	line_hor(2,39,1,219) ;
	line_hor(2,39,24,219) ;
	line_ver(1,24,2,219) ;
	line_ver(1,24,39,219) ;
}


//**********************************************************
//      CLASS NAME    : MENU
//      FUNCTION NAME : MAIN_MENU
//      DETAILS       : IT CREATS MENU AND CONTROL OTHER
//                   FUNCTIONS
//**********************************************************

void menu :: main_menu(void)
{
	char ch ;
	while(1)
	{
		clrscr() ;
		textmode(C40) ;
		clrscr() ;
		box() ;
		gotoxy(12,5) ;
		cout <<"TELEPHONE DIARY" ;
		gotoxy(12,6) ;
		cout <<"---------------" ;
		gotoxy(12,10) ;
		cout <<"1: ADD RECORDS" ;
		gotoxy(12,11) ;
		cout <<"2: DISPLAY LIST" ;
		gotoxy(12,12) ;
		cout <<"3: DELETE RECORD" ;
		gotoxy(12,13) ;
		cout <<"4: MODIFY RECORD" ;
		gotoxy(12,14) ;
		cout <<"0: QUIT" ;
		gotoxy(11,18) ;
		cout <<"Enter your choice:" ;
		ch = getch() ;
		textmode(C80) ;
		clrscr() ;
		if (ch == '1')
		{
			diary d ;
			d.add() ;
		}
		else
		if (ch == '2')
		{
			diary d ;
			d.display_list() ;
		}
		else
		if (ch == '3')
		{
			diary d ;
			d.deletion() ;
		}
		else
		if (ch == '4')
		{
			diary d ;
			d.modify() ;
		}
		else
		if (ch == '0')
			break ;
	}
}


//**********************************************************
//      CLASS NAME    : DIARY
//      FUNCTION NAME : DIARY (CONSTRUCTOR)
//      DETAILS       : IT IS CONSTRUCTOR FUNCTION, GIVING
//                   DEFAULT VALUES
//**********************************************************

diary :: diary(void)
{
	code = 0 ;
	name[0] = '\0' ;
	phone1[0] = '\0' ;
	phone2[0] = '\0' ;
	phone3[0] = '\0' ;
	e_mail[0] = '\0' ;
	address[0] = '\0' ;
}


//**********************************************************
//      CLASS NAME    : DIARY
//      FUNCTION NAME : ~DIARY (DISTRUCTOR)
//      DETAILS       : IT IS DISTRUCTOR FUNCTION
//**********************************************************

diary :: ~diary(void)
{
}



//**********************************************************
//      CLASS NAME    : DIARY
//      FUNCTION NAME : DISPLAY_LIST
//      DETAILS       : IT DISPLAYS LIST OF THE PERSON'S
//                   RECORDS
//**********************************************************

void diary :: display_list(void)
{
	clrscr() ;
	menu m ;
	char t_name[20], t1_name[20] ;
	gotoxy(3,5) ;
	cout <<"Enter name for selective list" ;
	gotoxy(3,6) ;
	cout <<"\nor press <ENTER> for whole list or `0' for exit : " ;
	gets(t_name) ;
	if (t_name[0] == '0')
		return ;
	int len = strlen(t_name) ;
	clrscr() ;
	fstream file ;
	file.open("TDIARY.DAT", ios::in) ;
	file.seekg(0,ios::beg) ;
	int row = 5 ;
	int found = 0 ;
	int pageno = 1 ;
	int flag = 1 ;
	char ch ;
	gotoxy(1,2) ;
	cout <<" CODE   NAME " ;
	m.line_hor(1,79,3,196) ;
	m.line_hor(1,79,24,196) ;
	while (file.read((char *) this, sizeof(diary)))
	{
		flag = 1 ;
		for (int i=0; i<len; i++)
			t1_name[i] = name[i] ;
		t1_name[len] = '\0' ;
		if (strcmpi(t_name,t1_name)==0)
		{
			delay(20) ;
			found = 1 ;
			gotoxy(1,row) ;
			cout <<code ;
			gotoxy(7,row) ;
			puts(name) ;
			gotoxy(27,row) ;
			cout    <<"PHONE  : " <<phone1 <<", " <<phone2 <<", "
					  <<phone3;
					  gotoxy(27,row+1);
					  cout<<"E_MAIL  : "<<e_mail;

			gotoxy(27,row+2) ;
			cout    <<"ADDRESS: " ;
			puts(address) ;
			if ( row == 20 )
			{
				flag = 0 ;
				row = 5 ;
				gotoxy(66,1) ;
				cout <<"Page no. : " <<pageno ;
				pageno++ ;
				gotoxy(1,25) ;
				cout <<"Press <ESC> to exit or any other key to continue..." ;
				ch = getch() ;
				if (ch == 27)
					return ;
				clrscr() ;
				gotoxy(1,2) ;
				cout <<" CODE   NAME " ;
				m.line_hor(1,79,3,196) ;
				m.line_hor(1,79,24,196) ;
			}
			else
				row = row + 3 ;
		}
	}
	if ( !found )
	{
		sound(500) ;
		delay(100) ;
		nosound() ;
		gotoxy(1,5) ;
		cout <<"Records not found" ;
	}
	if (flag)
	{
		gotoxy(66,1) ;
		cout <<"Page no. : " <<pageno ;
		gotoxy(1,25) ;
		cout <<"Press any key to continue..." ;
		getch() ;
	}
	file.close() ;
}


//**********************************************************
//      CLASS NAME    : DIARY
//      FUNCTION NAME : DISPLAY_RECORD
//      DETAILS       : IT DISPLAYS SINGLE RECORD FOR THE
//                   GIVEN RECORD
//**********************************************************

void diary :: display_record(int t_code)
{
	fstream file ;
	file.open("TDIARY.DAT", ios::in) ;
	file.seekg(0,ios::beg) ;
	while (file.read((char *) this, sizeof(diary)))
	{
		if (t_code == code)
		{
			gotoxy(3,3) ;
			cout <<"Code # " <<code ;
			gotoxy(3,5) ;
			cout <<"Name    : " ;
			puts(name) ;
			gotoxy(3,6) ;
			cout <<"Phone 1 : " <<phone1 ;
			gotoxy(3,7) ;
			cout <<"Phone 2 : " <<phone2 ;
			gotoxy(3,8) ;
			cout <<"Phone 3 : " <<phone3 ;
			gotoxy(3,9) ;
			cout <<"E_mail  : " <<e_mail ;
			gotoxy(3,10) ;
			cout <<"Address : " ;
			puts(address) ;
			break ;
		}
	}
	file.close() ;
}


//**********************************************************
//      CLASS NAME    : DIARY
//      FUNCTION NAME : LAST_CODE
//      DETAILS       : IT COUNTS THE RECORD IN THE FILE AND
//                   RETURN THE LAST CODE NO.
//**********************************************************

int diary :: last_code()
{
	fstream file ;
	file.open("TDIARY.DAT", ios::in) ;
	file.seekg(0,ios::beg) ;
	int t=0 ;
	while (file.read((char *) this, sizeof(diary)))
		t++ ;
	file.close() ;
	return t ;
}


//**********************************************************
//      CLASS NAME    : DIARY
//      FUNCTION NAME : FOUND_RECORD
//      DETAILS       : IT RETURNS THAT RECORD IS FOUND FOR
//                   THE GIVEN CODE NO. OR NOT
//**********************************************************

int diary :: found_record(int t_code)
{
	fstream file ;
	file.open("TDIARY.DAT", ios::in) ;
	file.seekg(0,ios::beg) ;
	int found=0 ;
	while (file.read((char *) this, sizeof(diary)))
	{
		if (t_code == code)
		{
			found++ ;
			break ;
		}
	}
	file.close() ;
	return found ;
}



//**********************************************************
//      CLASS NAME    : DIARY
//      FUNCTION NAME : ADD
//      DETAILS       : IT ADDS THE RECORDS IN THE DIARY'S
//                   FILE (TDIARY.DAT)
//**********************************************************

void diary :: add(void)
{
	menu m ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -