Simple Phone directory system without using structure/Classes in c++

Telephone Directory System


       
 #include<iostream>//headerfile

#include<string>//headerfile

using namespace std;

int top = 0;//globle variable

//functions

void addPhone(string *N,string *Ad,string *No,int *ID,int size)

{

	if (top >= size){

		cout << "We cannot add more Data there" << endl;

	}

	else{

		cout << "Enter the ID:";

		cin >> ID[top]; cin.ignore();

		cout << "Enter the phone number:";

		getline(cin, No[top]);

		cout << "Enter the Name:";

		getline(cin, N[top]);

		cout << "Enter the Address:";

		getline(cin, Ad[top]);

		top++;

	}

}

void Modify(string *N, string *Ad, string *No, int *ID, int size)

{

	int count = 0; int id;

	cout << "Enter the number to Modify" << endl;

	cin >> id;

	for (int i = 0; i < top; i++){

		if (ID[i] == id){

			cout << "Enter the ID:";

			cin >> ID[i]; cin.ignore();

			cout << "Enter the phone number:";

			getline(cin, No[i]);

			cout << "Enter the Name:";

			getline(cin, N[i]);

			cout << "Enter the Address:";

			getline(cin, Ad[i]);

		}

		else

		{

			count++;

		}

	}

	if (count > 0)

	{

		cout << "Id is not found" << endl; system("pause");

	}

}

void Search(string *N, string *Ad, string *No, int *ID, int size)

{

	int count = 0;

	int id;

	cout << "Enter the number to Search" << endl;

	cin >> id;

	for (int i = 0; i < top; i++){

		if (ID[i] == id){

			cout << "ID of this Person is:" << ID[i] << endl;

			cout << "Name of this person is:" << N[i] << endl;

			cout << "Phone number of this person is:" << No[i] << endl;

			cout << "Address of this person is:" << Ad[i] << endl;

			system("pause");

		}

		else

		{

			count++;

		}

	}

	if (count > 0)

	{

		cout << "ID not found" << endl; system("pause");

	}

}

void Del(string *N, string *Ad, string *No, int *ID, int size)

{

	int id;

	cout << "Enter the if number to Delete" << endl;

	cin >> id;

	int count = 0;

	for (int i = 0; i < top; i++){

		if (ID[i] == id){

			N[i] = '/0';

			Ad[i] = '/0';

			No[i] = '/0';

			ID[i] = 0;

		}

		else

		{

			count++;

		}

	}

	if (count > 0)

	{

		cout << "ID not found" << endl; system("pause");

	}

}

void Show(string *N, string *Ad, string *No, int *ID, int size)

{

	if (top >= size){

		cout << "There is not enough space" << endl; system("pause");

	}

	else{

		for (int i = 0; i < top; i++){

			cout << "ID of this Person is:" << ID[i] << endl;

			cout << "Name of this person is:" << N[i] << endl;

			cout << "Phone number of this person is:"<<No[i] << endl;

			cout << "Address of this person is:" << Ad[i] << endl;

			system("pause");

		}

	}

}

//main

int main()

{

	int size = 20;

	string name[20], addr[20], phone[20]; int id[20];

	int choice=0;

	while (choice != 6){

		system("cls");

		cout << "Enter 1 to add Pone number" << endl;

		cout << "Enter 2 to Show Data" << endl;

		cout << "Enter 3 to Search for phone number" << endl;

		cout << "Enter 4 to Modify Phone number" << endl;

		cout << "Enter 5 to Delete Phone number" << endl;

		cout << "Enter 6 to Cancel" << endl;

		cin >> choice;

		switch (choice){

		case 1:

			addPhone(name, addr, phone, id, size);

			break;

		case 2:

			Show(name, addr, phone, id, size);

			break;

		case 3:

			Search(name, addr, phone, id, size); break;

		case 4:

			Modify(name, addr, phone, id, size); break;

		case 5:

			Del(name, addr, phone, id, size);

			break;

		case 6:

			cout << "Thank You so much 4 our services" << endl;

			system("pause");

			break;

		default:

			cout <<"Tis coice is not available" << endl;

			system("pause");

			break;



		}

	}

	getchar();

	getchar();

	return 0;

}
          

       
 

Comments

Popular posts from this blog

Multiple inheritance,friend function and multiple file in oop(object oriented programming)

Concepts of OOP (object oriented programming)

Concepts in c++........