Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program that reads in a line consisting of a student\'s name, social sec

ID: 3624949 • Letter: W

Question

write a program that reads in a line consisting of a student's name, social security number, user ID, and password. The program outputs the string in which all digits of the social security number, and all the characters in the password are replaced by x.( The social security number is in the form 000-00-000, and the user ID and password do not contain any spaces.) The program should not use the operator[ ] to access a string element.
Thank you
#include<iostream>
#include <string>
using namespace std;
int main()
{string input;
int n,m;
cout<<"Enter a student's name, social security number, user id, and password in one line:";
getline(cin,input);
n=input.find(' ',0);
input.replace(n+1,11,"xxx-xx-xxxx");
n=input.find(' ',n+13)+1;
m=input.length();
m=m-n;
input.erase(n,m);
input.insert(n,m,'x');
cout<<"changed: "<<input<<endl;
system("pause");
return 0;
} but its suppose to read Enter a student's name, social security number, user id, and password in one line: Chris Henderson, 123456789, 1166, chessie711 and the out put should look like this
Chris Henderson, xxxxxxxxx, 1166, xxxxxxxxxx
Press any key to continue. . .

Explanation / Answer

// now code worknig perfectly

#include<iostream>
#include <string>
using namespace std;
int main()
{
string input;
int n,m;
cout<<"Enter a student's name, social security number, user id, and password in one line:";
getline(cin,input);
n=input.find(',',0);
input.replace(n+1,11,"xxxxxxxxx");
n=input.find(',',n+13)+1;
m=input.length();
m=m-n;
input.erase(n,m);
input.insert(n,m,'x');
cout<<endl;
cout<<"changed: "<<input<<endl;
system("pause");
return 0;
}