This is the question for C++ Many user-created passwords are simple and easy to
ID: 3916007 • Letter: T
Question
This is the question for C++
Many user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending "q*s" to the end of the input string.
i becomes !
a becomes @
m becomes M
B becomes 8
o becomes .
If the input is mypassword, the output is: Myp@ssw.rdq*s
So this is what I did:
#include <iostream>
#include <string>
using namespace std;
int main() {
string simplePassword;
int indxChangei;
int indxChangea;
int indxChangem;
int indxChangeB;
int indxChangeo;
indxChangei = simplePassword.find('i');
indxChangea = simplePassword.find('a');
indxChangem = simplePassword.find('m');
indxChangeB = simplePassword.find('B');
indxChangeo = simplePassword.find('o');
while (simplePassword.find('i') != string::npos){
simplePassword = simplePassword.replace(indxChangei,1,"!");
}
while (simplePassword.find('a') != string::npos){
simplePassword = simplePassword.replace(indxChangea,1,"@");
}
while (simplePassword.find('m') != string::npos){
simplePassword = simplePassword.replace(indxChangem,1,"M");
}
while (simplePassword.find('B') != string::npos){
simplePassword = simplePassword.replace(indxChangeB,1,"8");
}
while (simplePassword.find('o') != string::npos){
simplePassword = simplePassword.replace(indxChangeo,1,".");
}
cout<< simplePassword<<endl;
return 0;
}
what Did I do wrong!!!
Explanation / Answer
Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you
#include <iostream>
#include <string>
using namespace std;
int main() {
string simplePassword;
string newPassword = "";
char ch;
cout << "Enter a password: ";
cin >> simplePassword;
for(int i = 0; i < simplePassword.size(); i++)
{
ch = simplePassword[i];
if(ch == 'i')
ch = '!';
else if(ch == 'a')
ch = '@';
else if(ch == 'm')
ch = 'M';
else if(ch == 'B')
ch = '8';
else if(ch == 'o')
ch = '.';
newPassword = newPassword + ch;
}
newPassword += "q*s";
cout << "old password: " << simplePassword << endl;
cout<< "new password: " << newPassword<<endl;
return 0;
}
output
-----
Enter a password: mypassword
old password: mypassword
new password: Myp@ssw.rdq*s
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.