// Delete and insert a name for among 5 string.
#include<iostream> #include<stdlib.h> #include<string.h> using namespace std; struct name { char a[10]; }; int main() { int i,l=5; struct name s[5]; cout<<strcpy(s[0].a,"biku")<<"\n"; cout<<strcpy(s[1].a,"montu")<<"\n"; cout<<strcpy(s[2].a,"sunil")<<"\n"; cout<<strcpy(s[3].a,"balram")<<"\n"; cout<<strcpy(s[4].a,"chirag")<<"\n"; x: system("clear"); cout<<"\n\n You only delete or insert 5 value \n\n"; for(i=0; i<l; i++) { cout<<s[i].a<<"\n"; } cout<<"\n\n1.insert a name :"; cout<<"\n2.remove a name :"; int ch; cout<<"\n\n Enter your choice : "; cin>>ch; if(ch==1) { if(l<5){ cout<<"\nEnter a name : "; cin>>s[l].a; l++; } else{ cout<<"\n\n You cannot insert a name \n\n"; } } char n[10]; if(ch==2) { if(l>0){ cout<<"\n\nENter a name to delete : "; cin>>n; for(i=0; i<l; i++) { if(strcmp(n,s[i].a)==0) { for(i=i; i<l; i++) { strcpy(s[i].a,s[i+1].a); } l--; } } } else{ cout<<"\n You cannot delete a value\n\n"; } } cout<<"\n\n"; for(i=0; i<l; i++) { cout<<s[i].a<<"\n"; } cout<<"\n\n Do you want to again (Y/N) : "; char ch1; cin>>ch1; if(ch1=='y'){ int x; goto x; } }
You only delete or insert 5 value biku montu sunil balram chirag 1.insert a name : 2.remove a name : Enter your choice : 2 ENter a name to delete : balram biku montu sunil chirag Do you want to again (Y/N) : n
0 Comments