You are here:

C++/Array Processing!


Hi. I'm Donn and I'm from the Philippines. I'm a 2nd year college
student right now taking up Chemical Engineering. I'm having a hard time
with my machine problem and I was hoping you could help me with it. I need a complete program to see what was wrong with the one I made.

Here it is:


Write a program that will offer the following services:
1>Create the Array
2>Edit the array- with 3 options: Add, Delete and Change element
3>Sort the array
4>Display the Array
5>Quit this program

The size N of the array and the N integers will be entered on the
keyboard. Sorting will be done in ascending order.The array will be
displayed in 2 columns, the first column showing the index and the second
column showing the content. Make a loop, so that the program always displays
the Menu, as shown above, after performing a task. The program
terminates if the user selects 5 on the menu.

I would really appreciate it if you could help me with it. Yhank you so
much and GOD bless you always.  

Dear Donn!

 Array processing is the simplest and most fundamental operation in data structures !

Here i present you complete code written in C ++   ,I present you some information regarding this program!
1. Program uses bubble sort algorithm to sort the array  , ( Which is the simplest sorting algorithm )
2. Deletion is not possible in array (Its possible only is array is implemented as a list  , where as list are not stored in contiguous memory location ) So to represent the deletion operation  , i replaced  the element to 0
3. All other aspects are self explainable!

Here is the program !

#define max 100
int array[max];
int maxsize , counter = -1;
void sort( int *a  , int n)
  for( int i  = 0 ; i < n ; i  )
     for( int j = 0 ; j < n-1; j  )
        if(a[j] > a[j+1] )
         int temp = a[j];
         a[j] = a[j+1];
         a[j+1] = temp;

void add(int n)
  if(counter == maxsize - 1)
     cerr<<"Error : Overflow .."<<endl;
  array[++counter] = n;
void disp()
  if( counter == -1)
     cerr<<"Error : No element in the array .."<<endl;
  cout<<"The array elements are :";
  for(int i = 0 ; i <= counter ; i  )
     cout<<array[i]<<" ";
void edit( int loc , int data)
  if( loc == 0)
     cerr<<"Invalid location"<<endl;
  else if( loc >= counter )
     cerr<<"Error : Location out of limit :"<<endl;
  array[loc-1] = data;
void Delete ( int loc)
  if( loc <= 0)
     cerr<<"Error : Invalid location .."<<endl;
  else if( loc >= counter )
     cerr<<"Error : Location out of limit :"<<endl;
  array[loc] = 0;
void main()
  int opt , data , loc;

  cout<<"Array processing in C++  "<<endl;
  cout<<"Enter the size of array :";
     <<"2.Edit Array"<<endl
     <<"3.Display "<<endl
     <<"4.Delete Element"<<endl

     cout<<"Enter your choice :";
        case 1:
         cout<<"Enter element to insert in array:";
        case 2:
         cout<<"Enter loc  , data to change ";
         cin>>loc>> data;
         edit(loc , data);
        case 3:
        case 4:
         cout<<"Enter a location to delete :";
        case 5:
         sort(array , counter);
  }while(opt != 6);

Thanks and regards!
Prince M. Premnath.


All Answers

Answers by Expert:

Ask Experts


Prince M. Premnath


Years of research in C/C++ Will bring you all facts regarding , OOPS , SVGA , MOUSE , BIOS , IVT , Feel free to query me :-)


More than 5 years


©2017 All rights reserved.