Question

Write a program that deletes an element of a one-dimensional array of characters. The program should:...

Write a program that deletes an element of a one-dimensional array of characters. The program should: Ask user to input the number of characters in the array the values of the array a character to be deleted Call a method to delete the character Print the resulting array or, if the character is not found, print “Value not found” The method called by the main program should: Pass the array and the character to be found as parameters If the character is found in the array, move all the following values to the preceding element and return ‘true’ If the character is not found, do nothing and return ‘false’

Plz write in C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:::

#include <iostream>
using namespace std;

bool deleteCharacter(char *array,int &size,char deleteMe){

   bool found = false;
   for(int i=0;i<size;i++){
       if(array[i]==deleteMe){
           found = true;
           for(int j=i;j<size-1;j++){
               array[j] =array[j+1];
           }
           array[size-1] = '\0';
           break;
       }
   }
   return found;

}

int main( )
{
   int size;
   cout<<"Enter number of character of the array : ";
   cin>>size;
   char array[size];

   cout<<"Enter array "<<endl;
   for(int i=0;i<size;i++){
       cin>>array[i];
   }

   cout<<"Enter a character the needs to be delte : ";
   char deleteMe;
   cin>>deleteMe;

   cout<<"Array before delete : "<<array<<endl;
   if(deleteCharacter(array,size,deleteMe)){
       cout<<"Array after delete : "<<array<<endl;
   }else{
       cout<<"Character not found!!!"<<endl;
   }

   return 0;
}

output:

Add a comment
Know the answer?
Add Answer to:
Write a program that deletes an element of a one-dimensional array of characters. The program should:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT