Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey guy. I have\' been having a problem with the delete function and couple othe

ID: 3795091 • Letter: H

Question

Hey guy.

I have' been having a problem with the delete function and couple other functions in this assignment.

Write a OOP program that store an array of 100 integers.

    Add/code 1 of the top 2 sorting algorithms you mentioned above

    Add/code 1 of the top 2 searching algorithms you mentioned above

    Have a function to ask the user for input.

    Have a function to print out the array

    Have a function to delete an integer

    Have the ability to know/printout the count the number of integers

this is my code so farm:

#include "stdafx.h"
#include<iostream>
#include<cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
void search(int t, int A[]);
void print(int A[]);
void deletelemnt(int orig[], int lenght, int newarr[], int index);

int main()
{
   int i, j,x,e;
   int temp = 0;
   int A[100];
   int N[100];
   int value;
   srand(time(NULL));

   for (i = 0; i < 100; i++)// buble sort
   {
       value = rand() % 101;
       A[i] = value;
   }//array filled
   for (i = 0; i <= 100; i++) {
       cout << A[i] << endl;
   }
   cout << "your sorted array is next" << endl;
   for (i = 0; i < 100; i++) {

       for (j = 0; j < 100 - 1; j++) {
           if (A[j] > A[j + 1]) {
               temp = A[j];
               A[j] = A[j + 1];
               A[j + 1] = temp;

           }
       }//inner loop ends
   }//outer loop ends

  
   cout << "Please eneter a number to search for" << endl;
   cin >> x;
   search(x, A[i]);

   print(A[i]);

       cout << "which index do you want to delet?" << endl;
   cin >> e;

   void deletelemnt (A[i],100, N[100], e);
   print(A[i]);

   system("pause");
   return 0;
}

void search(int t, int A[]) {
   for (int i = 0; i < 100; i++) {
       if (t == A[i]) {
           cout << "we found your numb at locations" << i + 1 << endl;
       }
   }
}
void deletelemnt(int orig[], int lenght, int newarr[], int index) {


   for (int i = 0; i < lenght - 1; i++) {
       newarr[i] = orig[i];
       int index = 0;
   }for (int x = index; x < lenght - 1; x++) {
       newarr[x] = orig[x + 1];
   }
}

void print(int A[]){
   for (int i = 0; i < 100; i++)
   {
       printf("%d ", A[]);
       cout << endl;

   }
}

Explanation / Answer

//#include <stdafx.h>
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
void search(int t, int A[]);
void print(int A[]);
void deletelemnt(int orig[], int lenght, int index);

int main()
{
     int i, j,x,e,size;
     int temp = 0;
     int A[100];
     int N[100];
     int value;
int currentMin;
     int currentMinIndex ;

     srand(time(NULL));

    for (i = 0; i < 100; i++)// buble sort
     {
         value = rand() % 101;
         A[i] = value;
     }//array filled

     /* cout << "Enter the array size:" << endl;
      cin >> size;

    
   cout << "Enter the array vlaue:" << endl;
for (i = 0; i < size; i++)
{
cin >> A[i];
     }*/

cout << "Print the array vlaue :" << endl;
print(A);


    
     cout << "your sorted array is next" << endl;
    
/*for (i = 0; i < size; i++) {

        for (j = 0; j < size - 1; j++) {
             if (A[j] > A[j + 1]) {
                 temp = A[j];
                 A[j] = A[j + 1];
                 A[j + 1] = temp;

            }
         }//inner loop ends
     }//outer loop ends*/


for(int i = 0; i < 100; i++)
    {
         currentMin = A[i];
         currentMinIndex = i;

        for(int j = i + 1; j < 100; j++)
        {
            if(currentMin > A[j])
            {
                currentMin = A[j];
                currentMinIndex = j;
            }
        }
          
            if(currentMinIndex != i){
                A[currentMinIndex] = A[i];
                A[i] = currentMin;

            }
     }



     print(A);
    


     cout << "Please eneter a number to search for" << endl;
     cin >> x;
     search(x, A);


     cout << "which index do you want to delete?" << endl;
     cin >> e;

     deletelemnt (A,100,e);
     print(A);

    //system("pause");
     return 0;
}

void search(int t, int A[]) {
     for (int i = 0; i < 100; i++) {
         if (t == A[i]) {
             cout << "found your number at locations " << i + 1 << endl;
    break;
         }
     }
}
void deletelemnt(int orig[], int lenght, int index) {


   /* for (int i = 0; i < lenght - 1; i++) {
         newarr[i] = orig[i];
         int index = 0;
     }*/
for(int i=index - 1;i<=lenght - 1;i++)
       {
          orig[i]=orig[i+1];
       }

print(orig);
}

void print(int A[]){
     for (int i = 0; i < 100; i++)
     {
         printf(" %d", A[i]);
       
    }
cout << endl;

}