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

using namespace std;


struct biodata
{
string fname;
string lname;
string mname;
string address;
string pbirth;
string dbirth;
string religion;
string citizen;
string civilstat;
string gender;
string email;


}*student;

main( )
{
int n,i,xx,c,d,a=0,e=1;
char b,y;

cout<<"how many records?";
cin>>n;
cin.ignore( );

student= new biodata[n];

for(i=0;i<n;i++)
{
cout<<"\nLast name:"<<" ";
getline(cin,student.lname);
cout<<"First name:"<<" ";
getline(cin,student.fname);
cout<<"Middle name:"<<" ";
getline(cin,student.mname);
cout<<"Full Addess:"<<" ";
getline(cin,student.address);
cout<<"Gender:"<<" ";
getline(cin,student.gender);
cout<<"Place of Birth:"<<" ";
getline(cin,student.pbirth);
cout<<"Date of birth"<<" ";
getline(cin,student.dbirth);
cout<<"Citizenship:"<<" ";
getline(cin,student.citizen);
cout<<"Religion:"<<" ";
getline(cin,student.religion);
cout<<"Civil Status:"<<" ";
getline(cin,student.civilstat);
cout<<"Email Address"<<" ";
getline(cin,student.email);

}
cout<<"\n[1]"<<" "<< "VIEW ALL"<<endl;
cout<<"[2]"<<" "<< "VIEW"<<endl;
cout<<"[3]"<<" "<< "ADD"<<endl;
cout<<"[4]"<<" "<< "DELETE"<<endl;
cout<<"[5]"<<" "<< "EXIT"<<endl;
cout<<"\nEnter choice:";
cin>>c;
cin.ignore( );

do
{
do
{
if(c==1)
{
cout<<" "<<"\n\nTHIS IS ALL OF YOUR RECORD"<<endl;
for(i=0;i<n;i++)
{
cout<<"\nNAME:"<<" "<<student.lname<<" "<<student.fname<<" "<<student.mname<<endl;
cout<<"____________________________________________________"<<endl;
cout<<" Surname"<<" "<<" First name"<<" "<<" Middle name"<<endl;
cout<<"\nAddress:"<<" "<<student.address<<endl;
cout<<"Place of Birth:"<<" "<<student.pbirth<<endl;
cout<<"Date of Birth:"<<" "<<student.dbirth<<endl;
cout<<"Email Address:"<<" "<<student.email<<endl;
cout<<"Gender:"<<" "<<student.gender<<endl;
cout<<"Citizenship:"<<" "<<student.citizen<<endl;
cout<<"Civil Status:"<<" "<<student.civilstat<<endl;
cout<<"Religion:"<<" "<<student.religion<<endl;
}
cout<<"\n\nPress b to back to mian menu:";
cin>>b;

if(b=='b'||b=='B')
{
cout<<"\n[2]"<<" "<< "VIEW"<<endl;
cout<<"[3]"<<" "<< "ADD"<<endl;
cout<<"[4]"<<" "<< "DELETE"<<endl;
cout<<"[5]"<<" "<< "EXIT"<<endl;
cout<<"\nEnter choice:";
cin>>c;
cin.ignore( );
}
}
}while(c==1);

do
{
do
{
system("cls");
if(c==4)
{
cout<<"Enter index that you want to delete:"<<" ";
cin>>d;
if(d>=n)
cout<<"\ninvalid!"<<" "<<"no Index found";
else
{
cout<<"\nThe index was successfully deleted:";
a=a+1;

}

cout<<"\n\nPress b to back to mian menu:";
cin>>b;
if(b=='b'||b=='B')
{
cout<<"\n[1]" "New View"<<endl;
cout<<"[2]" "VIEW"<<endl;
cout<<"[3]" "ADD"<<endl;
cout<<"[4]" "DELETE"<<endl;
cout<<"[5]" "EXIT"<<endl;
cout<<"\nEnter choice:";
cin>>c;
cin.ignore( );
}
}
}while(c==4);


do
{
system("cls");
if(c==3)
{
if(a==0)
cout<<"\nSorry the index is full!" "Delete some index to use this Menu";
else
{
{
cout<<"\nLast name:"<<" ";
getline(cin,student[d-a+1].lname);
cout<<"First name:"<<" ";
getline(cin,student[d-a+1].fname);
cout<<"Middle name:"<<" ";
getline(cin,student[d-a+1].mname);
cout<<"Full Addess:"<<" ";
getline(cin,student[d-a+1].address);
cout<<"Gender:"<<" ";
getline(cin,student[d-a+1].gender);
cout<<"Place of Birth:"<<" ";
getline(cin,student[d-a+1].pbirth);
cout<<"Date of birth"<<" ";
getline(cin,student[d-a+1].dbirth);
cout<<"Citizenship:"<<" ";
getline(cin,student[d-a+1].citizen);
cout<<"Religion:"<<" ";
getline(cin,student[d-a+1].religion);
cout<<"Civil Status:"<<" ";
getline(cin,student[d-a+1].civilstat);
cout<<"Email Address"<<" ";
getline(cin,student[d-a+1].email);
a=a-1;
}
}
cout<<"\n\nPress b to back to mian menu:";
cin>>b;

if(b=='b'||b=='B')
{
cout<<"\n[2]" "VIEW"<<endl;
cout<<"[3]" "ADD"<<endl;
cout<<"[4]" "DELETE"<<endl;
cout<<"[5]" "EXIT"<<endl;
cout<<"\nEnter choice:";
cin>>c;
cin.ignore();
}
}
}while(c==3);
}while(c!=2);


if(c==2)
{

cout<<"You choose the VIEW menu please Enter index"<<" ";
cin>>xx;
}
if(xx>=n)
{
cout<<"\ninvalid!"<<" "<<"NO Index found";
}
else
if(xx==d)
{
for(i=d;i<n;i++)
student=student[i-1];
student[i-1];
cout<<" ";
}
else
{
cout<<"\nNAME:"<<" "<<student[xx].lname<<" "<<student[xx].fname<<" "<<student[xx].mname<<endl;
cout<<"____________________________________________________"<<endl;
cout<<" Surname"<<" "<<" First name"<<" "<<" Middle name"<<endl;
cout<<"\nAddress:"<<" "<<student[xx].address<<endl;
cout<<"Place of Birth:"<<" "<<student[xx].pbirth<<endl;
cout<<"Date of Birth:"<<" "<<student[xx].dbirth<<endl;
cout<<"Email Address:"<<" "<<student[xx].email<<endl;
cout<<"Gender:"<<" "<<student[xx].gender<<endl;
cout<<"Citizenship:"<<" "<<student[xx].citizen<<endl;
cout<<"Civil Status:"<<" "<<student[xx].civilstat<<endl;
cout<<"Religion:"<<" "<<student[xx].religion<<endl;
}
cout<<"\n\nPress b to back to mian menu:";
cin>>b;
if(b=='b'||b=='B')
{
cout<<"\n[2]" "VIEW"<<endl;
cout<<"[3]" "ADD"<<endl;
cout<<"[4]" "DELETE"<<endl;
cout<<"[5]" "EXIT"<<endl;

cout<<"\nEnter choice:";
cin>>c;
cin.ignore( );
}

}while(c!=5);
a++;
getch( );
return 0;
}

hey i have a problem in this program,Is anyone who help me?
can you please help how to delete record?

What problem are you facing? Post the error that you get.
Also please edit your first post by aligning the code properly and wrap [code] tag so that it is easily understandable for us to analyze.

try to run the program it is easy program. my problem is when i delete an index i cant shift the element to the right to insert a new record.

can you atleast tell which line you are trying to delete the index.

look for "if(c==4)" and "if(c==2)". "if(c==4)" this line is i work for delete and "if(c==2)" is i work to view the records

Also please edit your first post by aligning the code properly and wrap [code] tag so that it is easily understandable for us to analyze.

I don't see where you did this. If you want help, make your code readable so we can understand it.

ok! this program is a data structure program.The main idea in this is you have to enter a record in biodata format.Example you have enter 4 record so the index is like [john,michael,renz,steve] I like to delete the record of michael so the index like now is [john,renz,steve,empty], and I can add a new record in the last array and my problem is how to shift the empty element to the right until they go to the last.

Locate the index to be "erased" by overwriting. Then use a loop to assign the data at index + 1 to index starting at index and going to next to last used index. When done the last used index will be available for overwriting (be free, "empty") as the data that's there has already been rewritten to the index to the left.

It is like
for(i="index that i want to delete";i<"size of my array";i++)
myarray=myarray[i+1]; ??

but how to empty a record that i want to delete?

how to edit this post

When you want to type code in a post, please enclose that code in code-tags and use proper indenting! Even if it's only a couple of lines of code. For instance, your previous post should have looked like this:

const int indexToDelete;
const int sizeOfArray;

// ...

for( int i= indexToDelete; i < sizeOfArray; ++i )
   myarray[ i ] = myarray[ i+1 ];

You don't empty the index, you overwrite it. Your code is the correct except that "size of my array" is not a valid index, it's one too high. An array of size 3 has last valid index of 2 if the array is completely full, so you want i to less than the last valid index. Using the last valid index allows you to use the same amount of memory to keep track of elements up to the size of the array (meaning you can "remove" more the one element, add one element after removing 4, etc), without having to allocate new memory as long as the last valid index is less than the size of the array.

say you start with an int array with 3 elements all of which are valid.
[1][2][3]
you want to delete 2. you overwrite 2 like this
[1][3][3]
which results in a 3 element array with 2 active elements, the last 3 is ignored as it doesn't have a valid index any longer.

Another option would be to create a 2 element array and copy the desired elements only to the new array so you would get
[1][[3]
The creation of new arrays and copying desired data only is often not the preferred method.

The third method is to place a default value where the undesired element is. Say you define -1 to be invalid then to remove 2 you would do:
[1][-1][3]
and everytime you found -1 in an element you would ignore it.

Remember, if you declare an array like this;
int array[3];
and you try to disply array[0] before you assign some valid value to it, it isn't empty, it's junk.

ok thanks! my only problem is when i choose the viewall menu this is the output
exapmle i have a record [michael,peter,jonh] when i delete index 2 [michael,jonh,john] this is correct right? but the output that i want is when i delete index 2 the output is like this [michael,jonh," "] the last index is a double quotation what code in this?

thaks you very much for helping me!

If you shift everything to the left by one, and you display every element in the array immediately after the shift, then the output would be michael john john after you overwrte ("delete") peter. If you want an empty string instead of a "double entry" for the last element, then assign an empty string to the desired element after the shift is completed.

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.