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 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.
#include <iostream>
#include <string>
using namespace std;
int main(){
  string ssn, password, name;
  int id;
  cout<<"Enter name: ";
  cin>>name;
  cout<<"Enter social security number: ";
  cin>>ssn;
  cout<<"Enter user ID: ";
  cin>>id;
  cout<<"Enter password: ";
  cin>>password;
  cout<<"\nSSN: xxx-xx-xxxx\n";
  cout<<"Password: ";
  for(int i = 0; i < password.length(); i++){
    cout<<"x";
  }
  cout<<endl;
  return 0;
}
Comments
Leave a comment