Answer to Question #332223 in C++ for Ashiir

Question #332223

Write a C++ program that takes five alphabets from the user and ask the user to delete any


alphabet. You should store the alphabets in a char array.

1
Expert's answer
2022-04-25T13:37:36-0400
#include <iostream>

using namespace std;


char* Delete(char* str, char c)
{
	char* res = new char[strlen(str) - 1];
	int j = 0;
	for (int i = 0; i < strlen(str); i++)
	{
		if (str[i] != c)
			res[j++] = str[i];
	}
	res[j] = '\0';
	return res;
}

int main()
{
	char alph[6];
	cout << "Please, enter membsers of alphabet: ";
	for (int i = 0; i < 5; i++)
	{
		cin >> alph[i];
	}
	alph[5] = '\0';
	char del;
	cout << "Please, enter an alphabet to delete: ";
	cin >> del;
	char* res = Delete(alph, del);
	cout << "Resulting alphabet is : ";
	for (int i = 0; i < strlen(res); i++)
	{
		cout<<res[i]<<" ";
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS