Question

Write a program that reads in a line consisting of a student’s name, Social Security number,...

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. Use the appropriate functions described in Table 7-1 below.

Expression Effect
strVar.at(index) Returns the element at the position specified by index
strVar[index] Returns the element at the position specified by index
strVar.append(n, ch) Appends n copies of ch to strVar, where ch is a char variable or a char constant
strVar.append(str) Appends str to strVar
strVar.clear() Deletes all the characters in strVar
strVar.compare(str) Returns 1 if strVar > str returns 0 if strVar == str; returns −1 if strVar < str
strVar.empty() Returns true if strVar is empty; otherwise it returns false
strVar.erase() Deletes all the characters in strVar
strVar.erase(pos, n) Deletes n characters from strVar starting at position pos
strVar.find(str) Returns the index of the first occurrence of str in strVar. If str is not found, the special value string::npos is returned
strVar.find(str, pos) Returns the index of the first occurrence at or after pos where str is found in strVar
strVar.find_first_of(str, pos) Returns the index of the first occurrence of any character of strVar in str. The search starts at pos
strVar.find_first_not_of(str, pos) Returns the index of the first occurrence of any character of str not in strVar. The search starts at pos
strVar.insert(pos, n, ch) Inserts n occurrences of the character ch at index pos into strVar; pos and n are of type string::size_type; and ch is a character
strVar.insert(pos, str) Inserts all the characters of str at index pos into strVar
strVar.length() Returns a value of type string::size_type giving the number of characters in strVar
strVar.replace(pos, n, str) Starting at index pos, replaces the next n characters of strVar with all the characters of str. If n > length of strVar, then all the characters until the end of strVar are replaced
strVar.substr(pos, len) Returns a string which is a substring of strVar starting at pos. The length of the substring is at most len characters. If len is too large, it means “to the end“ of the string in *strVar
strVar.size() Returns a value of type string::size_type giving the number of characters in strVar
strVar.swap(str1). C++

Homework Answers

Answer #1

#include<iostream>
#include<string>
using namespace std;
int main()
{
   string str;
getline(cin, str);
int i=str.find("-");
str.replace(i-4,4,"XXXX");
str.replace(i+1,2,"XX");
str.replace(i+4,4,"XXXX");
int j;
for(j=i+9;j<str.length();j++)
{
if(!str.substr(j,1).compare(" ")==0)
break;
}
int p = str.find(" ",j);
while(p<str.length()&&str.substr(p,1).compare(" ")==0)
p++;
for(int k=p;k<str.length();k++)
str.replace(k,1,"X");
cout<<str;
   return 0;

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please provide answer in the format that I provided, thank you Write a program that prompts...
Please provide answer in the format that I provided, thank you Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
6.31 LAB: Count characters - methods ----- javascript please Write a program whose input is a...
6.31 LAB: Count characters - methods ----- javascript please Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex:...
Write a function int count_consonants(char str[]) that determines and returns the number of consonants in a...
Write a function int count_consonants(char str[]) that determines and returns the number of consonants in a given string. Then write a simple main() function where you can repeatedly enter a string and then the num- ber of consonants is determined and printed on the screen (from the main() function). If the entered string is empty (it will contain only a ’\n’ then) the program should stop its execution. You can safely assume that the entered string will be not longer...
Write a C program that creates a security access code from a social security number entered...
Write a C program that creates a security access code from a social security number entered by a user as follows: Using a recursive function it adds all of the digits of the social security number and then using a regular function gets the square number of the sum and displays it. The access code displayed should be initialized as an integer number but using type casting is displayed as a floating number.
Objectives:The focus of this assignment is to create and use a recursive method given a moderately...
Objectives:The focus of this assignment is to create and use a recursive method given a moderately difficult problem. Program Description: This project will alter the EmployeeManager to add a search feature, allowing the user to find an Employee by a substring of their name. This will be done by implementing the Rabin-Karp algorithm. A total of seven classes are required. Employee (From previous assignment) HourlyEmployee (From previous assignment) SalaryEmployee (From previous assignment) CommissionEmployee (From previous assignment) EmployeeManager (Altered from previous...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs and compares the character by character. If the two strings are exactly same it returns 0, otherwise it returns the difference between the first two dissimilar characters. You are not allowed to use built-in functions (other than strlen()) for this task. The function prototype is given below: int compare_strings(char * str1, char * str2); Task 3: Test if a string is subset of another...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...