Answer to Question #99433 in C++ for Caleb

Question #99433
Replace any alphabetic character with '_' in 2-character string passCode. Ex: If passCode is "9a", output is:
9_
Hint: Use two if statements to check each of the two characters in the string, using isalpha().
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main() {
string passCode;

cin >> passCode;

/* Your solution goes here */

cout << passCode << endl;
return 0;
}
1
Expert's answer
2019-11-27T08:00:12-0500
#include <iostream>
#include <string>
#include <cctype>
#include <ctime>

using namespace std;

void Replace_symbol(char &elem)
{
	int symbol = rand() % 4+1;
	if (symbol == 1) elem = '_';
	if (symbol == 2) elem = '&';
	if (symbol == 3) elem = ';';
	if (symbol == 4) elem = '#';
}

int main() {
	string passCode;
	cin >> passCode;
	srand(time(NULL));
	if (isalpha(passCode[0]))
	{
		Replace_symbol(passCode[0]);
	}
	if (isalpha(passCode[1]))
	{
		Replace_symbol(passCode[1]);
	}
	cout << passCode << endl;
	system("pause");
	return 0;


}

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