27
A Project Report On telephone directory Submitted By ABHAY MODI Class : XII A Under the Guidance of Mrs. NEHA SONONE PGT (Computer Science) Department of Computer Science Ramshree India international school, Shivpuri

Telephonedirectory (1)

Embed Size (px)

Citation preview

Page 1: Telephonedirectory (1)

A Project Report On telephone directory

Submitted By ABHAY MODI Class : XII A

Under the Guidance of

Mrs. NEHA SONONE PGT (Computer Science)

Department of Computer Science Ramshree India international school, Shivpuri

Page 2: Telephonedirectory (1)

CERTIFICATE This is to certify that ABHAY MODI of Class XII A has prepared the report on the Project entitled “Telephone directory”. The report is the result of his efforts & endeavors. The report is found worthy of acceptance as final project report for the subject Computer Science of Class XII. He has prepared the report under my guidance. INTERNAL EXAMINER PRINCIPAL (SIGN) (SIGN) (SIGN)

Page 3: Telephonedirectory (1)

ACKNOWLEDGEMENT I would like to express a deep sense of thanks & gratitude to my project guide Mrs. Neha Sonone Mam for guiding me immensely through the course of the project. She always evinced keen interest in my work. Her constructive advice and constant motivation have been responsible for the successful completion of this project. My sincere thanks goes to Mrs Ashwini Tambat, Our principal mam, for her coordination in extending every possible support for the completion of this project. I also thanks to my parents for their motivation & support. I must thanks to my classmates for their timely help & support for compilation of this project. Last but not the least, I would like to thank all those who had helped directly or indirectly towards the completion of this project.

ABHAY MODI Class: XIIA

Page 4: Telephonedirectory (1)

INTRODUCTION

C++ is a statically typed, compiled, general-purpose, case-sensitive, free-form programming language that supports procedural, object-oriented, and generic programming. C++ is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features.

C++ was developed by Bjarne Stroustrup starting in 1979 at Bell Labs in Murray Hill, New Jersey, as an enhancement to the C language and originally named “C with Classes” but later it was renamed C++ in 1983. C++ is a superset of C, and that virtually any legal C program is a legal C++ program. Object-Oriented Programming:- C++ fully supports object-oriented programming, including the four pillars of object-oriented development: Encapsulation:- Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. Data hiding:- The insulation of data from direct access by the program is called data hiding or information hididng. In other words, we can say that encapsulation is implmented through information hiding. Inheritance:- Inheritance is the process by which one object can acquire the properties of another object. This is important because it supports the concept of classification. If you think about it, most knowledge is made manageable by hierarchical classifications. Polymorphism:- Object-oriented programming languages support polymorphism, which is characterized by the phrase "one interface, multiple methods." In simple terms, polymorphism is the attribute that allows one interface to control access to a general class of actions.

Page 5: Telephonedirectory (1)

Contents:- 1. Header file used 2. Files generated 3. Working description 4. Source Code 5. Output Screens 6. Bibliography

Page 6: Telephonedirectory (1)

HEADER FILES USED 1. iostream:- for cin and cout. 2. Conio.h:- for getch(). 3. Fstream.h:- for file handling. 4. Iomanip:- for setw(). 5. String.h:- for string handling. 6. Stdio.h:- for standard i/o operation.

FILES GENERATED DATA FILE:- tele.dat PROGRAM FILE:-telephone_directory.cpp OBJECT FILE:- tele.dat EXECUTION FILE:- telephone_directory.exe

WORKING DESCRIPTION This program is designed to keep the friend’s record.

This program consists of FIVE options as follows 1.addition of new record 2. display all records 3. search a record by telephone no. 4. search a record by fname 5. search a record by lname 6. search a record by street 7. search a record by city 8. search a record by state 9. deletion of telephone no. 10. exit

Page 7: Telephonedirectory (1)

SOURCE CODE #include<fstream> #include<iostream> #include<conio.h> #include<iomanip> #include<string.h> #include<stdio.h> using namespace std; class phone { private:

char tno[12],fname[10],lname[10]; char street[10],city[10],state[10];

public: void heading(); void line1(); void read(); void show(); void add(); void disp_all(); void search_tno(); void search_fname(); void search_lname(); void search_street(); void search_city(); void search_state(); void del_telno();

}; void phone::line1() { int i; for(i=1;i<=70;i++)

Page 8: Telephonedirectory (1)

{ cout<<"-"; } cout<<endl; } void phone::heading() { //clrscr(); cout<<endl<<endl; cout<<" T e l e p h o n e R e c o r d s "<<endl; cout<<" ======================================"<<endl; line1(); cout<<setw(12)<<"Tele no"<<setw(20)<<"Name"; cout<<setw(10)<<"Street"<<setw(10)<<"City"; cout<<setw(10)<<"State"<<endl; line1(); } void phone::read() { cout<<"Enter telephone no "; cin>>tno; cout<<"Enter fname and lname "; cin>>fname>>lname; strupr(fname); strupr(lname); cout<<"Enter street , city and state "; cin>>street>>city>>state; strupr(street); strupr(city); strupr(state); } void phone::show() { cout<<setw(12)<<tno<<setw(15)<<fname<<" "<<lname; cout<<setw(10)<<street<<setw(10)<<city<<setw(10)<<state<<endl; } void phone::add() {

Page 9: Telephonedirectory (1)

phone p; fstream abc; abc.open("tele",ios::in); if(abc.fail()) { abc.open("tele",ios::out); } else { abc.close(); abc.open("tele",ios::app); } p.read(); abc.write((char*)&p,sizeof(p)); abc.close(); } void phone::disp_all() { fstream abc; phone p; abc.open("tele",ios::in); if(abc.fail()) { cout<<"unable to open the file"<<endl; return; } heading(); abc.read((char*)&p,sizeof(p)); while(!abc.eof()) { p.show(); abc.read((char*)&p,sizeof(p)); } line1(); abc.close(); } void phone::search_tno() { fstream abc;

Page 10: Telephonedirectory (1)

phone p; char tt[12]; int z=0; cout<<"Enter tele no to search "; cin>>tt; abc.open("tele",ios::in); if(abc.fail()) { cout<<"unable to open the file"<<endl; return; } abc.read((char*)&p,sizeof(p)); while(!abc.eof()) { if(strcmp(p.tno,tt)==0) { z=1; heading(); p.show(); } abc.read((char*)&p,sizeof(p)); } line1(); if(z==0) cout<<"record is not present"<<endl; abc.close(); } void phone::search_fname() { fstream abc; phone p; char tfn[12]; int z=0; cout<<"Enter fitst name to search "; cin>>tfn; abc.open("tele",ios::in);

Page 11: Telephonedirectory (1)

if(abc.fail()) { cout<<"unable to open the file"<<endl; return; } heading(); abc.read((char*)&p,sizeof(p)); while(!abc.eof()) { if(strcmpi(p.fname,tfn)==0) { z=1; //heading(); p.show(); } abc.read((char*)&p,sizeof(p)); } line1(); if(z==0) cout<<"record is not present"<<endl; abc.close(); } void phone::search_lname() { fstream abc; phone p; char tln[12]; int z=0; cout<<"Enter last name to search "; cin>>tln; abc.open("tele",ios::in); if(abc.fail()) { cout<<"unable to open the file"<<endl; return; } heading();

Page 12: Telephonedirectory (1)

abc.read((char*)&p,sizeof(p)); while(!abc.eof()) { if(strcmpi(p.lname,tln)==0) { z=1; //heading(); p.show(); } abc.read((char*)&p,sizeof(p)); } line1(); if(z==0) cout<<"record is not present"<<endl; abc.close(); } void phone::search_street() { fstream abc; phone p; char tsn[12]; int z=0; cout<<"Enter name of the street "; cin>>tsn; abc.open("tele",ios::in); if(abc.fail()) { cout<<"unable to open the file"<<endl; return; } heading(); abc.read((char*)&p,sizeof(p)); while(!abc.eof()) { if(strcmpi(p.street,tsn)==0) {

Page 13: Telephonedirectory (1)

z=1; //heading(); p.show(); } abc.read((char*)&p,sizeof(p)); } line1(); if(z==0) cout<<"record is not present"<<endl; abc.close(); } void phone::search_city() { fstream abc; phone p; char tc[12]; int z=0; cout<<"Enter name of the city "; cin>>tc; abc.open("tele",ios::in); if(abc.fail()) { cout<<"unable to open the file"<<endl; return; } heading(); abc.read((char*)&p,sizeof(p)); while(!abc.eof()) { if(strcmpi(p.city,tc)==0) { z=1; //heading(); p.show(); } abc.read((char*)&p,sizeof(p)); }

Page 14: Telephonedirectory (1)

line1(); if(z==0) cout<<"record is not present"<<endl; abc.close(); } void phone::search_state() { fstream abc; phone p; char ts[12]; int z=0; cout<<"Enter name of the state "; cin>>ts; abc.open("tele",ios::in); if(abc.fail()) { cout<<"unable to open the file"<<endl; return; } heading(); abc.read((char*)&p,sizeof(p)); while(!abc.eof()) { if(strcmpi(p.state,ts)==0) { z=1; //heading(); p.show(); } abc.read((char*)&p,sizeof(p)); } line1(); if(z==0) cout<<"record is not present"<<endl; abc.close();

Page 15: Telephonedirectory (1)

} void phone::del_telno() { fstream abc,pqr; phone p; char tt[12]; int z=0; cout<<"Enter tele no to delete "; cin>>tt; abc.open("tele",ios::in); pqr.open("temp",ios::out); if(abc.fail()) { cout<<"unable to open the file"<<endl; return; } abc.read((char*)&p,sizeof(p)); while(!abc.eof()) { if(strcmp(p.tno,tt)==0) { z=1; heading(); p.show(); } else pqr.write((char*)&p,sizeof(p)); abc.read((char*)&p,sizeof(p)); } line1(); if(z==0) cout<<"record is not present"<<endl; else { remove("tele"); rename("temp","tele");

Page 16: Telephonedirectory (1)

} abc.close(); } int main() { //clrscr(); phone p1; int op=0; while(op!=10) { //clrscr(); cout<<"1. Addition of record"<<endl; cout<<"2. Display all redords "<<endl; cout<<"3. search a record by tel no"<<endl; cout<<"4. Search a record by fname"<<endl; cout<<"5. search a record by lname"<<endl; cout<<"6. Search a record by street"<<endl; cout<<"7. Search a record by city"<<endl; cout<<"8. Search a record by state"<<endl; cout<<"9. Deletion of record by tel no"<<endl; cout<<"10. Exit"<<endl; cout<<"Enter your choice "; cin>>op; switch(op) { case 1:

p1.add(); break;

case 2: p1.disp_all(); break;

case 3: p1.search_tno(); break;

case 4: p1.search_fname();

Page 17: Telephonedirectory (1)

break; case 5:

p1.search_lname(); break;

case 6: p1.search_street(); break;

case 7: p1.search_city(); break;

case 8: p1.search_state(); break;

case 9: p1.del_telno(); break;

case 10: cout<<"end"<<endl; break;

default: cout<<"Invalid chocie "<<endl; break;

} getch(); } }

Page 18: Telephonedirectory (1)

OUTPUT

Page 19: Telephonedirectory (1)
Page 20: Telephonedirectory (1)
Page 21: Telephonedirectory (1)
Page 22: Telephonedirectory (1)
Page 23: Telephonedirectory (1)
Page 24: Telephonedirectory (1)
Page 25: Telephonedirectory (1)
Page 26: Telephonedirectory (1)
Page 27: Telephonedirectory (1)

BIBLIOGRAPHY

1. http://www.google.com/ 2. http://en.wikipedia.org 3. Computer Science with C++ by Sumita Arora 4. Object Oriented Programing by Robert Lafore 5. www.bOtskOOL.com 6. computer science teacher:- Mrs. Neha Sonone