0% found this document useful (0 votes)
40 views37 pages

Training Project

The document describes an address book program that allows users to perform basic contact management functions like adding, modifying, deleting, searching, and viewing contacts. It includes coding for the program structure, classes and functions used to manage contacts stored in a file. The main menu offers options to add new contacts, modify existing ones, delete records, search by name, and view all. Screenshots demonstrate sample outputs for different menu options.

Uploaded by

kulwantsingh159
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views37 pages

Training Project

The document describes an address book program that allows users to perform basic contact management functions like adding, modifying, deleting, searching, and viewing contacts. It includes coding for the program structure, classes and functions used to manage contacts stored in a file. The main menu offers options to add new contacts, modify existing ones, delete records, search by name, and view all. Screenshots demonstrate sample outputs for different menu options.

Uploaded by

kulwantsingh159
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 37

Project Address

Manager

Index
S no
1
2
3
4
5

Topic
Coding
Brief analysis of the program
code
Snapshots of the program
Main menu

Choice 1: add new record

Choice 2
Modify record

Choice 3
Record deletion

Choice 4

Search record
9

Choice 5
View all records

10

Choice 6
Exit

Coding
#include<iostream.h>
#include<conio.h>
#include <process.h>
#include<stdio.h> //for gets and puts
#include<fstream.h>
#include<string.h>
//------------------------------------------------------------------------------struct addres{
char city[10],block;
int houseno;
}s1;
//------------------------------------------------------------------------------class addr{
private:
char name[51];
addres add;
char phoneno[11];
public:
void getvalue();
void putvalue();
char* rename() // a fntn to return name for
search bcz we can access private name with object
{
return name;
}
}o1;

//-----------------------------------class
functions-------------------------------------------void addr::getvalue()
{
cout <<"\tEnter the value of name (maximum 50
characters)"<<endl;
cin>>name;
cout<<"\tEnter the Address "<<endl;
cout<<"\t Enter the house number"<<endl;
cin>>add.houseno;
cout<<"Enter the block "<<endl;
cin>>add.block;
cout<<"Enter the city"<<endl;
cin>>add.city;
cout<<"Enter the phone number ( only digits(0-9)
permitted)"<<endl;
gets(phoneno);
}
//----------------------------------------------------------------------------void addr:: putvalue()
{
cout<<endl<<endl;
cout<<" Following are the details of the person"<<endl;
cout<<"name is :\t"<<name<<endl;
cout<<"address is :\t"<<add.block<<" " <<add.houseno<<"
"<<add.city<<endl;
cout<<"phone number is :\t";
puts(phoneno);
}
//-------------------------------FILE
FUNCTIONS----------------------------------------------------void display();
void insertion();
void search();
void delet();

void modification();
//---------------------------------------------------------------------------------main()
{
textcolor(CYAN);
textbackground(BLACK);
char ch=0;
clrscr();
cout<<"\t ||
===============================================
=====||"<<
endl;
cout<<"\t ||
||"<<
endl;
cout<<"\t ||
ADDRESS MANAGER
||"<<
endl;
cout<<"\t ||
||"<<
endl;
cout<<"\t ||
===============================================
=====||"<<
endl;
cout<<"\t ||
===============================================
=====||"<<
endl;
cout<<"\t ||
||"<<
endl;
cout<<"\t ||
WELCOME
||"<<
endl;
cout<<"\t ||
TO YOUR PERSONAL
||"<<
endl;

cout<<"\t ||
ADDRESS MANAGER
||"<<
endl;
cout<<"\t ||
||"<<
endl;
cout<<"\t ||
BROUGHT TO YOU BY
||"<<
endl;
cout<<"\t ||
||"<<
endl;
cout<<"\t ||
!!!!!!!!!!!!!!!!!!!
||"<<
endl;
cout<<"\t ||
! Mayank Batra !
||"<<
endl;
cout<<"\t ||
!!!!!!!!!!!!!!!!!!!
||"<<
endl;
cout<<"\t ||
||"<<
endl;
cout<<"\t ||
===============================================
=====||"<<
endl;
cout<<"\t ||
===============================================
=====||"<<
endl;
cout<<"\t ||
PRESS ANY KEY TO CONTINUE.......
||"<<
endl;
cout<<"\t ||
===============================================
=====||"<<
endl;
getch();

while(ch!=6)
{
clrscr();
cout<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<
endl;
cout<<"\t ||
===============================================
======||"<<
endl;
cout<<"\t ||
||"<<
endl;
cout<<"\t ||
ADDRESS
MANGER
||"<<
endl;
cout<<"\t || -------------------------------------------- ||"<<
endl;
cout<<"\t ||
||"<<
endl;
cout<<"\t ||
MAIN MENU
||"<<
endl;
cout<<"\t ||
----------||"<<
endl;
cout<<"\t ||
||"<<
endl;
cout<<"\t ||
1. [A]dd new record
||"<<
endl;
cout<<"\t ||
2. [M]odify existing record
||"<<
endl;
cout<<"\t ||
3. [D]elete record
||"<<
endl;
cout<<"\t ||
4. search a record
||"<<
endl;

cout<<"\t
endl;

||

5. [V]iew all records

||"<<

cout<<"\t ||
6. [E]xit
||"<<
endl;
cout<<"\t ||
||"<<
endl;
cout<<"\t ||
===============================================
======||"<<endl<<endl;
cout<<"
Enter your choice";
cin>>ch;
switch(ch)
{
case '1':insertion();
break;
case '2':modification();
break;
case '3':delet();
break;
case '4':search();
break;
case '5':display();
break;
case '6':exit(0);
break;
default:cout<<"Wrong Choice Entered Exiting..................";
exit(0);
break;
}
getch();
}

}
//-----------------------FILE FUNCTION
DEFINATIONS---------------------------------------void display()
{
fstream f;
f.open("addr.dat",ios::binary|ios::in);
while(f.read((char*)&o1,sizeof(o1)))
o1.putvalue();
f.close();
}
//---------------------------------------------------------------------------------------------void delet()
{
fstream f1,f2;
char name[10];
f1.open("addr.dat",ios::binary|ios::in);
f2.open("addr1.dat",ios::binary|ios::out);
cout<<endl;
cout<<"enter the name of whose record is to be
deleted"<<endl;
cin>>name;
while(f1.read((char*)&o1,sizeof(o1)))
if(strcmp(o1.rename(),name)!=0)
f2.write((char*)&o1,sizeof(o1));
remove("addr.dat");
rename("addr1.dat","addr.dat");
cout<<"deletion process succesful"<<endl;
f1.close();
f2.close();
}

//----------------------------------------------------------------------------------------------------void insertion()
{
fstream f1,f2;
f1.open("addr.dat",ios::binary|ios::in);
f2.open("addr1.dat",ios::binary|ios::out);
addr o1, o1new;
int ins=0;
o1new.getvalue();
while(f1.read((char*)&o1,sizeof(o1)))
{
if(ins==0&&o1new.rename()<o1.rename())
{
f2.write((char*)&o1new,sizeof(addr));
ins++;
}
f2.write((char*)&o1,sizeof(addr));
}
if(ins==0)
{
f2.write((char*)&o1new,sizeof(addr));
}
remove("addr.dat");
rename("addr1.dat","addr.dat");
f1.close();
f2.close();
}
//---------------------------------------------------------------------------------------------------void search()
{
char name[51],found;
int check;
fstream f;

f.seekg(ios::beg);
f.open("addr.dat",ios::in|ios::out|ios::binary);
cout<<"enter the name of the record which is to be searched
for ........"<<endl;
cin>>name;
while(f)
{
f.read((char*)&o1,sizeof(addr));
check=strcmp(name,o1.rename());
if(!check)
{
found='y';
}
else
{
found='n';
}
}
if(found=='y')
{
cout<<"search succesfull record found "<<endl;
o1.putvalue();
}
else
{
cout<<"sorry record not present "<<endl;
}
getch();
}
//-----------------------------------------------------------------------------------void modification()
{
char name[51],found='n';
int check;

fstream f;
f.open("addr.dat",ios::in|ios::out);
long pos;
cout<<endl<<"Enter the name of the person whose records need to
be modified ......"<<endl;
cin>>name;
while(f)
{
pos=f.tellg();
f.read((char*)&o1,sizeof(addr));
check=strcmp(name,o1.rename());
if(!check)
{
found='y';
cout<<"enter the details of the person "<<endl;
f.seekg(pos);
o1.getvalue();
f.write((char*)&o1,sizeof(addr));
}
}
if(found=='n')
{
cout<<"Record not found ....you seem to have entered wrong
name\n aborting.....................";
}
f.close(); }

Brief Analysis Of
The Program code
Header files used:
1. iostream.h
2. conio.h
3. process.h
4. stdio.h
5. fstream.h
6. string.h
Use of header files:
1. iostream for console input / output and related functions.
2. conio for clear screen and for freezing the screen.
3. process for exit from the program
4. stdio is a standard input /output file used for file functions
such as rename / remove etc.
5. fstream is used to link file with the program.
6. string file is used to manipulate strings.

User defined data types used:


structure
2. classes
1.

Components of user define data types and their


importance in the program:
struct addres : city ,block and house no.
this structure stores the address of a person.
1.

2. class addr : it is the main key structure of the file .the class
addr forms the framework of the file in which the data is
organized .
Data members of class are :
1. name
2. address (of type struct).
3. phone number .
Member function of class
1. putvalue (){ for output of the data on the monitor }
2. getvalue () { for input of data }

File functions used :


1. display ()
2. insertion ()
3. search ()
4. delet ()
5. modification ()

Use of File Functions :


1. display : function is defined with the main motto to display
the contents of the file .
2. insertion : function aims at the insertion of the data into the
file.
3. search : the function of search function is to search for the
record in the given file .
4. delet : the function is used to delete all the unwanted data
from the file .
5. modification : the function aims at modifying the required
data .

Snapshots of the
program
First screen

Main Menu

Choice 1: add new record

Enter details

Details entered:
Name: Gantavya
Address: a-328 delhi
Phone no: 9989825647

Choice 2
Modify record

New details
Name: rohan
Address :a-324 delhi
Phono no: 9968513939

Choice 3
Record deletion

Record deleted: rohan

Choice 4
Search record

( record of rohan again entered )


Name entered : rohan

Record found and displayed.

Choice 5
View all records

Choice 6
Exit

You might also like