729809d51c75da2de9381dc33f42887d okay guys this the program in which we have to add a record,modify it or delete it. it adds and shows it successfully but whenever we want to delete a record it doesn't. When we add to records and delete the second one ,the list looks like this,

can you post the code?

After you've deleted a record and pressed 'y' to go back to the menu, what happens if you select option "b) List Employee Records"?
Does the list still contain the record you just deleted? (Your screenshot does not show this information)

If so, then you are correct, you have a problem somewhere in your code. :)

Because you haven't posted any code, the only useful advice I can give at the moment is:
1. Run a debug build of your program through a debugger (All IDE's should have some kind of debugger support and if you aren't using an IDE, then you'll need to use something like gdb on the command line)
2. Set a breakpoint in the code which is supposed to deal with deleting a record.
3. When your program hits the breakpoint - step through the code and check the values of all variables and see if you can spot the problem.

Otherwise as Nathan has said; you're going to have to post some source code for your program in order for somebody here to help you further!

Don't send us the code. Post the code.

#include <cstdlib>
#include <iostream>
#include <conio.h>

using namespace std;

int i;
int size=0;

struct employRecord
{
    string firstName;
    string lastName;
    int age;
    string department;
    string qualification;
};

void addRecord();
void listRecord();
void modifyRecord();
void deleteRecord();

struct employRecord empl[100];

int main()
{
    char Y;
    char choice;
    do
    {
        cout << "\t\t***** EMPLOY MANAGEMENT SYSTEM *****";
        cout << "\n \t\t a) Add Employee Records";
        cout << "\n \t\t b) List Employee Records";
        cout << "\n \t\t c) Modify Employee Records";
        cout << "\n \t\t d) Delete Employee Records";
        cout << "\n \t\t e) Exit Employee Records" << endl;
        cout << "\t\t Select Your Choice (a to e) : ";
        cin >> choice;
        switch (choice)
        {
            case 'a':
                cout << "\n";
                addRecord();
                break;
            case 'b':
                cout << "\n";
                listRecord();
                break;
            case 'c':
                cout << "\n";
                modifyRecord();
                break;
            case 'd':
                cout << "\n";
                deleteRecord();
                break;
            case 'e':
                exit(0);
                break;
            default:
                cout << "Invalid!!!" << endl;
        }
        cout << "\n****** Enter\'y\'for main menu. \'n\' for Exit. ******" << endl;
        cin >> Y;
    }while( Y == 'y' );

    getch();
    return 0;
}

void addRecord()
{
    char Y;
    i = 0;
    size = 0;
    do
    {
        cout << "*****ADD RECORD MENU*****" << endl;
        cout << "Enter Employee's first name: ";
        cin >> empl[i].firstName;
        cout << "Enter Employee's last name: ";
        cin >> empl[i].lastName;
        cout << "Enter Employee's age: ";
        cin >> empl[i].age;
        cout << "Enter Employee's qualification: ";
        cin >> empl[i].qualification;
        cout << "Enter Employee's department: ";
        cin >> empl[i].department;

        cout<<"Do You want to enter a new record? (n/y)";
        cin>>Y;
        i++;
        size++;
    } while( Y == 'y' );
}

void listRecord()
{
    cout << "**********************EMPLOYEE'S RECORD LIST**********************" << endl;
    cout << "First Name\tLast Name\tAge\tqualification\tdepartment\t\n";
    for (int i = 0; i < size; i++)
        cout << empl[i].firstName 
             << "\t\t" << empl[i].lastName 
             << " \t" << empl[i].age 
             << " \t" << empl[i].qualification 
             << "\t\t" << empl[i].department << "\n";
}

void modifyRecord()
{
    cout << "Enter the number of Employee in the list" << endl;
    cin >> i;
    if( i == i )
    {
        cout << "*****RECORD MODIFICATION MENU*****" << endl;
        cout << "Enter Employee's first name: ";
        cin >> empl[i].firstName;
        cout << "Enter Employee's last name: ";
        cin >> empl[i].lastName;
        cout << "Enter Employee's age: ";
        cin >> empl[i].age;
        cout << "Enter Employee's qualification: ";
        cin >> empl[i].qualification;
        cout << "Enter Employee's department: ";
        cin >> empl[i].department;
        cout << "*****RECORD MODIFIED*****";
    }
}

void deleteRecord()
{
    cout << "Enter the number of employee in the list " << endl;
    cin >> i;
    if( i == i)
    {
        empl[i].firstName = ' ';
        empl[i].lastName = ' ';
        empl[i].age = ' ';
        empl[i].age = ' ';
        empl[i].qualification = ' ';
        empl[i].department = ' ';
    }
    cout << "*****RECORD DELETED*****" << endl;
}

Right, record deletion. You're setting everytihng to be a blank char. Even the int value. Don't set an int value to a char value. It makes no sense.

if(i==i) Can you tell me when this will ever be false? When will i ever not be the same as i?

You still haven't told us what the problem is. How do you know it doesn't change the record to all blank values?

I have run your code and it works fine to delete a record except that, because you set the int value to ' ', the age isn't blanked - it is set to 32 because ' ' has the numerical value 32.. Here is the output. I added an employee, listed the employees, and then deleted that employee.

        ***** EMPLOY MANAGEMENT SYSTEM *****
         a) Add Employee Records
         b) List Employee Records
         c) Modify Employee Records
         d) Delete Employee Records
         e) Exit Employee Records
         Select Your Choice (a to e) : a

*****ADD RECORD MENU*****
Enter Employee's first name: a
Enter Employee's last name: b
Enter Employee's age: 2
Enter Employee's qualification: df
Enter Employee's department: fe
Do You want to enter a new record? (n/y)n

****** Enter'y'for main menu. 'n' for Exit. ******
y
        ***** EMPLOY MANAGEMENT SYSTEM *****
         a) Add Employee Records
         b) List Employee Records
         c) Modify Employee Records
         d) Delete Employee Records
         e) Exit Employee Records
         Select Your Choice (a to e) : b

**********************EMPLOYEE'S RECORD LIST**********************
First Name  Last Name   Age qualification   department  
a       b   2   df      fe

****** Enter'y'for main menu. 'n' for Exit. ******
y
        ***** EMPLOY MANAGEMENT SYSTEM *****
         a) Add Employee Records
         b) List Employee Records
         c) Modify Employee Records
         d) Delete Employee Records
         e) Exit Employee Records
         Select Your Choice (a to e) : d

Enter the number of employee in the list 
0
*****RECORD DELETED*****

****** Enter'y'for main menu. 'n' for Exit. ******
y
        ***** EMPLOY MANAGEMENT SYSTEM *****
         a) Add Employee Records
         b) List Employee Records
         c) Modify Employee Records
         d) Delete Employee Records
         e) Exit Employee Records
         Select Your Choice (a to e) : b

**********************EMPLOYEE'S RECORD LIST**********************
First Name  Last Name   Age qualification   department  
            32           

****** Enter'y'for main menu. 'n' for Exit. ******
n

so what do you suggest?How should I edit my code so the we don't see the value 32 in output ?Is there any other way to delete except the way I used which I only know of..kindly help if there are other ways to sort out this problem. Thanks!

At the moment you're not deleting the record. You're just setting all the values to blank, except the age, becuase there is no number that shows as blank.

How about you mark records as deleted or not deleted, and just don't display the deleted records?

how'll I do that?

Here's some code for you.
I modified your delete routine move the record to the empty part of the array.
I added code throughout to use the size variable as the end of the records and to check for out of bounds conditions.
I removed i from the global namespace and made it local, because your code is using it for different things.
I added a number index to the display routine. This way the user has a point of reference when asked to input a record number. Because of the difference between how most people count and the way indexes are counted, I made the displayed index more natural for the user and modified the code to accommodate this.

Hope this helps:

#include <cstdlib>
#include <iostream>

using namespace std;
int size=0;
const int MaxRecords = 100;
struct employRecord
{

    string firstName;
    string lastName;
    int age;
    string department;
    string qualification;
};
void addRecord();
void listRecord();
void modifyRecord();
void deleteRecord();
void swap_empl(int, int);
struct employRecord empl[MaxRecords];
int main()
{

    char Y;
    char choice;
    do
    {
        cout << "\t\t***** EMPLOY MANAGEMENT SYSTEM *****";
        cout << "\n \t\t a) Add Employee Records";
        cout << "\n \t\t b) List Employee Records";
        cout << "\n \t\t c) Modify Employee Records";
        cout << "\n \t\t d) Delete Employee Records";
        cout << "\n \t\t e) Exit Employee Records"<<endl;
        cout << "\t\t Select Your Choice (a to e) : ";
        cin>>choice;
        switch (choice)
        {
        case 'a':
            cout<<"\n";
            addRecord();
            break;
        case 'b':
            cout<<"\n";
            listRecord();
            break;
        case 'c':
            cout<<"\n";
            modifyRecord();
            break;
        case 'd':
            cout<<"\n";
            deleteRecord();
            break;
        case 'e':
            exit(0);
            break;
        default:
            cout<<"Invalid!!!"<<endl;
        }
        cout<<"\n****** Enter\'y\'for main menu. \'n\' for Exit. ******"<<endl;
        cin>>Y;
    }
    while(Y=='y');
    return 0;

}
void addRecord()
{
    char Y;
    int i=size;
    if(size ==  MaxRecords)
    {
        cout <<"No more room" << endl;
        return;
    }
    do
    {
        cout<<"*****ADD RECORD MENU*****"<<endl;
        cout << "Enter Employee's first name: ";
        cin>>empl[i].firstName;
        cout<<"Enter Employee's last name: ";
        cin >>empl[i].lastName;
        cout<<"Enter Employee's age: ";
        cin>>empl[i].age;
        cout << "Enter Employee's qualification: ";
        cin >>empl[i].qualification;
        cout<<"Enter Employee's department: ";
        cin>>empl[i].department;

        cout<<"Do You want to enter a new record? (n/y)";
        cin>>Y;
        i++;
        if(size < MaxRecords)
        {
            size++;
        }
        else
        {
            if(Y == 'y')
            {
                cout <<"No more room" << endl;
                return;
            }

        }
    }
    while(Y=='y');
}
void listRecord()
{

    if(size == 0)
    {
        cout << "There are no records to display" << endl;
        return;
    }
    cout<<"**********************EMPLOYEE'S RECORD LIST**********************"<<endl;
    cout<<"No.\tFirst Name\tLast Name\tAge\tqualification\tdepartment\t\n";
    for (int i = 0; i < size; i++)
        cout<<i+1<<"\t"<<empl[i].firstName<<"\t\t"<<empl[i].lastName<<" \t"<<empl[i].age<<" \t"<<empl[i].qualification<<"\t\t"<<empl[i].department<<"\n";
}
void modifyRecord()
{
    if(size == 0)
    {
        cout << "There are no records to modify" << endl;
        return;
    }
    int i;
    cout<<"Enter the number of Employee in the list"<<endl;
    cin>>i;
    if(i< size)
    {
        i-=1;
        cout<<"*****RECORD MODIFICATION MENU*****"<<endl;
        cout << "Enter Employee's first name: ";
        cin>>empl[i].firstName;
        cout<<"Enter Employee's last name: ";
        cin >> empl[i].lastName;
        cout<<"Enter Employee's age: ";
        cin>>empl[i].age;
        cout << "Enter Employee's qualification: ";
        cin >> empl[i].qualification;
        cout<<"Enter Employee's department: ";
        cin>>empl[i].department;
        cout<<"*****RECORD MODIFIED*****";

    }

}

void deleteRecord()
{
    if(size == 0)
    {
        cout << "There are no records to delete" << endl;
        return;
    }
    int i;
    cout<<"Enter the number of employee in the list "<<endl;
    cin>>i;
    //move deleted record to the bottom of the array
    for (int j = i-1 ; j<size-1; j++)
    {
        swap_empl(j,j+1);
    }
    //decrement size
    size --;
    cout<<"*****RECORD DELETED*****"<<endl;
}
void swap_empl(int first, int second)
{
    employRecord temp  = empl[first];
    empl[first] = empl[second];
    empl[second] = temp;
}

There are probably other way of doing this, but I wanted to keep as mouch of your original code as possible.

will not making "i" the local variable affect the rest of the code?And thanks alot alto for that index number making more user friendly...but I've a question, how the loop and swamp function will work?could you explain that a bit..the last portion

int i;
    cout<<"Enter the number of employee in the list "<<endl;
    cin>>i;
    //move deleted record to the bottom of the array
    for (int j = i-1 ; j<size-1; j++)
    {
    swap_empl(j,j+1);
    }
    //decrement size
    size --;
    cout<<"*****RECORD DELETED*****"<<endl;
    }
    void swap_empl(int first, int second)
    {
    employRecord temp = empl[first];
    empl[first] = empl[second];
    empl[second] = temp;
    }

it isn't modifying it correctly now..

it just shows the "enter y for main menue and n for exit..

The basic structure of your program is using an array. However you only need to work with a portion of it. The size variable tells the code which part of the array is useable. To delete a record all my code does is move the record to the bottom of the useable portion, then decrease size by 1. Now the record isn't in the useable portion and won't be displayed when you list the records. The technique I used for this is to keep swapping the record with the one below it until it's at the bottom of the useable portion.

Making i local just means declaring it in each routine where you use it. It might sound like it's not important. but in more complicated projects, it will give you huge headaches when you have a global variable that you use and modify in different areas for different things.

What do you want it to do? It should say record deleted then ask to return to main menu. If you do a display after that you'll see that the deleted record doesn't show up .

Thanks for your help Tinstaafi but there is still a problem in modification..When I add two records and want to modify the 2nd one it just shows "enter y for main menue and n for exit"..could you correct this?thanks

change this if(i< size)(ine 133) to this if(i<= size)

Thanks alot Tinstaafi. Just another request..can you give me an overview of this program so when I go for presentation I don't mmake any mistakes..Thanks loads for all the help.

The basic structure of the program is using an array to store the data. However only a portion of it is needed. The size variable tells the code which part of the array is useable.

Adding a record merely updates the data on the first index after the useable portion of the array. then size is incremented by 1 to include that record

Modifying a record replaces all the data for a particular record in the useable portion of the array

Deleting a record moves the record to the bottom of the useable portion, then decrease size by 1. Now the record isn't in the useable portion and won't be displayed when you list the records. The technique used for this is to keep swapping the record with the one below it until it's at the bottom of the useable portion.

As always please remember to mark this solved. Thanks

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.