In This program Inserting,display ,deleting and updating elements in an array with the help of Cpp Program .
#include<iostream.h> #include<conio.h> int array[50],position,option_select,array_elements,first,value,loop; /*******INSERT ELEMENTS*******/ void insert(){ cout<<"ENTER NUMBER OF ELEMENTS IN ARRAY\n"; cin>>array_elements; if(array_elements>50){ cout<<"ELEMENTS NOT GREATER THEN 50 "; array_elements=0; insert(); }else{ cout<<"ENTER "<<array_elements<<" ELEMENTS\n"; for (first = 0; first < array_elements; first++){ cin>>array[first]; } } } /******* END INSERT ELEMENTS*******/ /*******DISPLAY ELEMENTS*******/ void display_list(){ cout<<"\n LIST OF ARRAY ELEMENTS \n"; for (first = 0; first < array_elements; first++){ cout<<"\t"<<array[first]; if(first%5==0 && first!=0)cout<<"\n"; } } /*******END DISPLAY ELEMENTS*******/ /*******UPDATE ELEMENTS*******/ void update_list(){ cout<<"ENTER THE LOCATION WHERE YOU WISH TO INSERT AN ELEMENT\n"; cin>>position; cout<<"ENTER THE VALUE TO INSERT\n"; cin>>value; for (first = array_elements - 1; first > position - 1; first--) array[first+1] = array[first]; array[position-1] = value; display_list(); } /******* END UPDATE ELEMENTS*******/ /*******DELETE ELEMENTS*******/ void delete_element(){ cout<<"ENTER THE LOCATAION WHERE YOU WISH TO DELETE AN ELEMENT \n"; cin>>position; cout<<"\n LIST START FROM 0 \n"; cout<<"ENTER THE VALUE THE ELEMENT \n"; cin>>value; if(array[position-1]==value){ cout<<"ELEMENT DELETE"; array[position-1]=0; for(first=position-1;first<array_elements;first++){ array[first] = array[first+1]; } array_elements--; }else{ cout<<"\n MISSED MATCH VALUE"; } } /*******END DELETE ELEMENTS*******/ /*******EXIT*******/ void exit(){ loop=0; cout<<"\n PRESS ENTER FOR EXIT"; } /******* END EXIT ***************/ /******* OPTION SELECT ***************/ void option_selecttion(){ cout<<"\nSELECT OPTION \n 1.INSERT ELEMENT \n 2.DISPLAY ELEMENT \n 3.UPDATE ELEMENT \n 4.DELETE ELEMENT \n 5.EXIT YOURS OPTIONS: "; cin>>option_select; switch(option_select){ case 1: insert(); break; case 2: display_list(); break; case 3: update_list(); break; case 4: delete_element(); break; case 5: exit(); break; default : exit(); break; } } /******* END OPTION SELECT **********/ /******* MAIN ************/ void main(){ int i=0; clrscr(); cout<<" WWW.AHIRLABS.COM "; loop=1; while(loop){ option_selecttion(); i++; if(i==100){ break; } } getch(); } /******* END MAIN ***********/
(Visited 367 times, 1 visits today)
Written by: