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

Please review all necessary requirements for this assignment: ***ANSWER MUST BE

ID: 3808008 • Letter: P

Question

Please review all necessary requirements for this assignment:

***ANSWER MUST BE COMPATIBLE WITH VISUAL STUDIO AS WE DO NOT USE ANY OTHER CODING PROGRAMS FOR THIS CLASS***

Write a program that reads in a line consisting of a student’s name (first and last), Social Security number, user ID, and password.

Use getline not cin so you can demonstrate an understanding of the string manipulation concepts

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.

Enter a student's name social security number user id, and password in one line: Jane Smith 222-33-4444 S12345 password Jane Smith xxx-xx-xxxx S12345 xxxxxxxx Press any key to continue

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{
string input;
string s ;
cout<<"Enter a student's name, social security number, user id, password in one line: "<<endl;
getline(cin, input);
s = input;
string firstName = s.substr(0, s.find(" "));
s = s.substr(s.find(" ")+1);

string lastName = s.substr(0, s.find(" "));
s = s.substr(s.find(" ")+1, s.length());
string ssn = s.substr(0, s.find(" "));
s = s.substr(s.find(" ")+1, s.length());
string userId = s.substr(0, s.find(" "));
s = s.substr(s.find(" ")+1, s.length());
string password = s.substr(0, s.find(" "));
s = s.substr(s.find(" ")+1, s.length());

input.replace(input.find(password), password.length(), password.length(), 'x');
input.replace(input.find(ssn), 3, 3, 'x');
input.replace(input.find("-")+1, 2, 2, 'x');
input.replace(input.find("-")+4, 4, 4, 'x');
cout<<input<<endl;
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter a student's name, social security number, user id, password in one line:                                                                                                                                                                                         

Suresh Murapaka 222-33-4444 S12345 password   

Suresh Murapaka xxx-xx-xxxx S12345 xxxxxxxx

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote