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
  • Write a program that creates an array of 10 integers. The array should be populated with values: each element should be equal to its subscript/index. The program should then print each element. Make use of a loop in storing values to the array. Make use o

    Write a program that creates an array of 10 integers. The array should be populated with values: each element should be equal to its subscript/index. The program should then print each element. Make use of a loop in storing values to the array. Make use of another loop in printing the values of the array.

  • Write program in JAVA with a method that returns an array. The method should accept as input a co...

    Write program in JAVA with a method that returns an array. The method should accept as input a comma-delimited string with three values from a user. The array should store each value in a different element. Use Try..Catch error handling and print any failure messages, or print success from within method if execution is successful (see Chapter 13 in the text). Call the method from the main method of the program to demonstrate its functionality by looping through the array...

  • (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...

    (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...

  • Write a program that performs the following operations on a one dimensional array with 50 unsigned...

    Write a program that performs the following operations on a one dimensional array with 50 unsigned integers. The main program will initialize the array, print the array values to the screen and then call a function that will determine and print the maximum and minimum values. •Declare the array and any other variables. •Use a loop to initialize the array with 50 random integer values between 0 and 99 using the rand() function. (number = rand() % 100;) •Using cout...

  • - Write a program that performs several operations on an array of positive ints. The program...

    - Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...

  • Write in c and in the simplest form (beginner) Write a program pointers with multi-dimensional integer...

    Write in c and in the simplest form (beginner) Write a program pointers with multi-dimensional integer array [2] [4]. Use data set {#,88,89,90},{?,65,66,67}. Now the input characters would be converted to ASCII decimal value and put into the first cell of the row’s array, and so on. When getting the values out of the array, convert the decimal value to equivalent ASCII character. Print the address of the first array followed by the four decimal values, followed by the four...

  • 4. Write a program that finds the smallest element in a one-dimensional array containing 20 integer...

    4. Write a program that finds the smallest element in a one-dimensional array containing 20 integer values in the range 0 to N Hint: Consider following fragment of code Program in C language: for(c=0;c<size;c++) {     if(array[c] < minimum)     {         minimum = array[c];         location = c;     } } this c code is not running and missing some code . please add the missing code so when i paste it will run and provide flowchart

  • Write a C program (not C++) that calls a function to multiply a matrix (two dimensional...

    Write a C program (not C++) that calls a function to multiply a matrix (two dimensional array). The main program should ask the user to enter an integer that will be used as the matrix “adder” and then call the function. The function should perform a matrix increment (every element of the array is incremented by the same value) and assign the result to another array. The function should be flexible enough to work with any array size and “adder”,...

  • In Java, write a program that prompts the user to input a sequence of characters and...

    In Java, write a program that prompts the user to input a sequence of characters and outputs the number of vowels. You will need to write a method to return a value called isAVowel which will return true if a given character is a vowel and returns false if the character is not a vowel. A second method, called isAConstant, should return true if a given character is a constant and return false if the character is not a constant....

  • Write a console-based program ( C # ) that asks a user to enter a number...

    Write a console-based program ( C # ) that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined...

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