I have written this program and i am facing problems in the SearchRec() and DelRec() function.....SearchRec() function is supposed to search for a record on the basis of the pptno provided and if found would return 1 else it would return 0(but it is no working).And the DelRec() function should delete the record of which pptNo is provided(but its also not working).I just can figure it out.....Can anyone please help me on this....
Thank you very much....

#include<iostream.h>			
#include<iomanip.h>
#include<string.h>

const int NUM=100;
int record_Count=0;

struct Date							//Declaration of Date structure
{
	int day,month,year;
};

struct Passport						//Declaration of Passport structure
{
	int pptNo;						//pptno set as primary key
	char name[25];
	char father_Name[25];
	Date dob;
	char city[25];

};

//Passport pass[NUM];

void AddRec(Passport [],int);				//prototype for adding record function
void ModRec(Passport []);				//prototype for modifying record function
int SearchRec(const Passport [],int);			//prototype for searching a record function
void DelRec(Passport [],int);				//prototype for deleting record function
void PrintRec(const Passport [],int,int);			//function prototype for printing a record
void PrintAll(const Passport []);			//function prototype for printing all record
//int Total(const Passport []);		//function prototype for counting total number of elements
//void Initialize(Passport []);			//function prototype for initialization of pptno of array of structure

	//START OF MAIN FUNCTION
int main()					//main function
{
	int ch;
	char cont;
	
	cout<<"\n\t\t=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-==-=-===-=-=-=-=-=-=-=-=-=\n"
	    <<"\t\t=-\tWelcome to the Passport Detail Entry Program\t -=\n"
	    <<"\t\t=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
		
		cout<<"\n\n\n";

	Passport pass[NUM];			//instance of struct Passport
	//Passport*ptr_Pass=&pass[NUM];
	//Initialize(pass);
	do
	{
			cin.clear();
			cout<<"\n\nPlease enter the Choice:\n"			//Menu display
				<<"For adding new record press\t[1]\n"
				<<"For modifying any record press  [2]\n"
				<<"For searching any record press  [3]\n"
				<<"For deleting record press\t[4]\n"
				<<"For printing any record press   [5]\n"
				<<"For exiting the program press   [6]: [ ]\b\b";
			while(true)               //to check if numeric value of ch is entered
			{
				cin>>ch;
				if(cin.good())
				{
					if((ch>0)&&(ch<7))
					{
						cin.ignore(100,'\n');
						break;
					}
				}
				cin.clear();
				cout<<"Please enter a numeric value in the range 1-6: ";
				cin.ignore(100,'\n');
			}
		
			cout<<endl<<endl;
		bool check=true;
		switch(ch)				//operation selection
		{
			case 1:
				int limit;
				do
				{
					cout<<"How many records do you want to enter:";
					while(check)               //to check if numeric value of ch is entered
					{
						cin>>limit;
						if(cin.good())
						{
							if((limit>0)&&(limit<NUM))
							{
								cin.ignore(100,'\n');
								check=false;
								break;
							}
						}
						cin.clear();
						cout<<"Please enter a numeric value in range 1-100";
						cin.ignore(100,'\n');
					}
				}while(check);
				AddRec(pass,limit);
				break;
			case 2:
				ModRec(pass);
				break;
			case 3:
				int pptNo;
				cin.clear();
				cout<<"Please enter passport number: ";
				cin>>pptNo;
				cin.ignore(100,'\n');
				
				if(SearchRec(pass,pptNo))
					PrintRec(pass,1,pptNo);
				else
					cout<<"Record not found\n";
				break;
			case 4:
				DelRec(pass,pptNo);
				break;
			case 5:
				int sel;
				cout<<"For printing single record press 1\n"
					<<"For printing All records press 2: ";
				while(true)               //to check if numeric value of ch is entered
				{
					cin>>sel;
					if(cin.good())
					{
						if((sel>0)&&(sel<3))
						{
							cin.ignore(100,'\n');
							break;
						}
					}
					cin.clear();
					cout<<"Please enter 1-2 only: ";
					cin.ignore(100,'\n');
				}
				if(sel==1)
				{
					int pptNo;
					cout<<"Please enter Passport number";
					cin>>pptNo;
					if(SearchRec(pass,pptNo))
						cout<<"Record not found\n";
					else
						PrintRec(pass,sel,pptNo);
				}
				
				break;
			case 6:
				cout<<"\n\t\t*-*-*-*-* Thankyou for using the program *-*-*-*-*\n\n";
				//cout<<Total(pass)<<endl;
				return 0;
		}

	cout<<"\tIf you want to perform another operation please press Y"
		<<"\t\n\t Otherwise press q to exit: ";
		if(ch!=6)
		{	
			for(;;)
			{
				cin>>cont;
				if((cont==89)||(cont==121)||(cont==81)||(cont==113))
					break;
				else
					cout<<"\tPlease enter only Y to continue\n"
						<<"\t\tPress q to exit: ";
			}
		}
	}while((cont=='y')||(cont=='Y'));
	
	return 0;
}

	//ADD RECORD FUNCTION
void AddRec(Passport pass[NUM],int limit)				//function definition for adding record
{
	//Passport*pass=ptr;
	for(int i=0;i<limit;i++)
	{
		int len1,len2,len3;
		do
		{		
			cin.clear();
			//cin.ignore();
			int pptNo;
			cout<<"Please enter passport number: ";
			bool valid_ppt=false;
			do			
			{
				cin>>pptNo;
				cin.ignore(100,'\n');
					if(SearchRec(pass,pptNo))
					{
						cout<<"Passport number already exists"
							<<".Please enter a valid number"
							<<" from "<<i+1<<" to "<<NUM-i
							<<": ";
						valid_ppt=false;
						break;
					}
					else
						valid_ppt=true;
			}while(!valid_ppt);			
			cout<<"Please enter applicant name:";
			cin.getline(pass[i].name,25,'\n');
			len1=strlen(pass[i].name);
			cout<<"Please enter father's name of applicant:";
			cin.getline(pass[i].father_Name,25,'\n');
			len2=strlen(pass[i].father_Name);
			cout<<"Please enter city of residence of applicant:";
			cin.getline(pass[i].city,25,'\n');
			len3=strlen(pass[i].city);
			cout<<"Please enter applicant's Date of Birth:\n";
			bool valid=false;
			while(!valid)
			{
				cout<<"Please enter the day:";
				cin>>pass[i].dob.day;
				if((pass[i].dob.day<1)||(pass[i].dob.day>31))
					cout<<"\nPlease enter a valid day\n";
				else
					valid=true;
				cin.clear();				
			
				cout<<"Please enter the month:";
				cin>>pass[i].dob.month;
				if((pass[i].dob.month<1)||(pass[i].dob.month>12))
					cout<<"\nPlease enter a valid month\n";
				else
					valid=true;
				cin.clear();
			
				cout<<"Please enter the year:";
				cin>>pass[i].dob.year;
				if((pass[i].dob.year<1900)||(pass[i].dob.day>2009))
					cout<<"\nPlease enter a valid year\n";
				else
					valid=true;
				
				if(!valid)
					cout<<"\nPlease Re-Enter the Date of Birth of applicant\n";
				
				cin.clear();
			}
				if((len1<1||len1>25)&&(len2<1||len2>25)&&(len3<1||len3>25))
					cout<<"Please enter between 1-25 character(s) names only\n\n";
				else
					++record_Count;
			
		}while((len1<1||len1>25)&&(len2<1||len2>25)&&(len3<1||len3>25));	
		
		//++pass;	
	}
		//++record_Count;

}

	//SEARCH RECORD FUNCTION
int SearchRec(const Passport pass[NUM],int pptNo)		//definition of searchRecord
{
	//cout<<"I am the search record function"<<endl;
	for(int i=0;i<NUM;i++)
	{
		int srch=pass[i].pptNo;
		if(srch==pptNo)
		{
			cout<<"i am searching in a loop"<<endl;
			PrintRec(pass,1,i);
			return 1;
		}
	}
		return 0;
}

	//MODIFY RECORD FUNCTION
void ModRec(Passport pass[NUM])				//definition of modifyRecord
{
	cout<<NUM<<endl;

}

	//DELETE RECORD FUNCTION
void DelRec(Passport pass[NUM],int pptNo)				//definition of modifyRecord
{
	for(int i=pptNo;i<NUM;i++)
	{
			pass[i].pptNo=pass[i+1].pptNo-1;
			strcpy(pass[i].name,pass[i+1].name);
			strcpy(pass[i].father_Name,pass[i+1].father_Name);
			pass[i].dob.day=pass[i+1].dob.day;
			pass[i].dob.month=pass[i+1].dob.month;
			pass[i].dob.year=pass[i+1].dob.year;
			strcpy(pass[i].city,pass[i+1].city);
	}
	--record_Count;
	cout<<"The Record has been deleted...\n";
}

	//PRINT ALL RECORDS FUNCTION
void PrintAll(const Passport pass[NUM])		//definition of printAllRecords
{
	for(int i=0;i<NUM;i++)
	{
		cout<<pass[i].name<<' '
			<<pass[i].father_Name<<' '
			<<pass[i].city<<' '
			<<pass[i].dob.day<<"/"
			<<pass[i].dob.month<<"/"
			<<pass[i].dob.year<<endl;
	
	}

}

	//PRINT FUNCTION
void PrintRec(const Passport pass[NUM],int opt,int pptNo)		//definition of printRecord
{
	int sel=opt;
	char ch;
		if(sel==2)
		{
			cout<<"printing all the records"<<endl;
			PrintAll(pass);
		}
		else
		{
			do
			{	
				cout<<pass[pptNo].name<<' '
					<<pass[pptNo].father_Name<<' '
					<<pass[pptNo].city<<' '
					<<pass[pptNo].dob.day<<"/"
					<<pass[pptNo].dob.month<<"/"
					<<pass[pptNo].dob.year<<endl;
				cout<<"If you want to see another record press y."
					<<"Else press any key to exit: ";
				cin>>ch;
			}while(!SearchRec(pass,pptNo)||ch=='y'||ch=='Y');	
		
		}

}
// line 286:
void DelRec(Passport pass[NUM],int pptNo)//definition of modifyRecord
{	
for(int i=pptNo;i<NUM;i++)	{

pptNo is supposed to be the passport number of the record to be deleted. Right? If yes, then why is the for loop initializing variable i to pptNo? If you look at the addRec() function you will see that the passport number can be almost anything, so its not the index value into the array. To delete the record you need to search the entire array for the passport number, then when and if found delete it.

for(int i = 0; i < NUM; i++)
{
    if( pass[i].pptNo == pptNo)
    {
           // found -- delete this record
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.