Write a program that reads in a line consisting of a student%u2019s name, Social
ID: 3539606 • Letter: W
Question
Write a program that reads in a line consisting of a student%u2019s name, Social
Security number, user ID, and password. The program outputs the string in
which all the 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-0000, and the user ID and the password do not contain any
spaces.) Your program should not use the operator [] to access a string
element.
Use c++ code that compiles in visual studio 2010.
I will not rate any answer written for java!!!
Explanation / Answer
please rate - thanks
any changes needed let me know
#include <iostream>
#include <string>
using namespace std;
int main()
{string input,output="",ss="xxx-xx-xxxx";
int start,xs;
cout<<"Enter a line consisting of a student's name, Social ";
cout<<"Security number, 6 character user ID, and password: ";
getline(cin,input);
start=input.find('-',0)-3;
output.append(input,0,start);
output.append(ss);
output.append(input,start+11,6);
xs=input.length()-(start+17);
output.insert(start+17,xs,'x');
cout<<input<<" with SS# and password changed to x "<<output<<endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.