Write a program that reads in a line consisting of a student’sname, Social Security number, user ID, and password. The programoutputs the string in which all the digits of the Social Securitynumber and all the characters in the password are replacedby x. (The Social Security number is in theform 000-00-0000, and the user ID and the password do notcontain any spaces.) Your program should not use theoperator [] to access a string element.
With Program written in C++.
This is how my program is written, however my problem is itshould only be the SSN and the password that should output x's. Myprogram outputs everything as x's except for the last twoletter if the user ID and the password. how do I fix the issue?
#include <iostream>
using namespace std;
int main() {
// Write your main here
string str;
int name;
int ssn;
int userID;
int password;
cout << "enter student first and then last name, then social security number, then user ID and password all in one line: " <<endl;
getline(cin, str);
name = str.find(' ', 0);
ssn = str.find(' ', name + 1);
str.replace(ssn +1, 4, "xxxx");
str.replace(ssn + 5, 3, "xxx");
str.replace(ssn + 8, 5, "xxxxx");
userID = str.find(' ', ssn + 1);
password = str.find(' ', userID + 1);
str.replace(password + 1, 10, "xxxxxxxxxx");
cout << str << endl;
return 0;
}
Write a program that reads in a line consisting of a student’s name, Social Security number, user ID, and password. The
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am