Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////
- //Code Written By: Sergio A. Nuñez //
- //Date of Final Revision: 1/20/2017 //
- ////////////////////////////////////////////////////////////////////////
- //Summary of Code: //
- //This program will take an input form the system and decide whether //
- //the input is an email or a phone number then it will do two things //
- //------------------------------------------------------------------- //
- //1: //
- //Email: If an email is detected it will find the '@' symbol then //
- //replace the characters in the email with five '*' and print //
- //--------------------------------------------------------------------//
- //2: //
- //Phone: If a phone number is detected it will extract every digit //
- //and '+' if detected then based on the amount of digits in the //
- //string determine the number of hyphens neccessary. Once Hyphens //
- //are in place iterate through the string replacing all, but the last //
- //four digits with '*'s //
- ////////////////////////////////////////////////////////////////////////
- #include <map>
- #include <set>
- #include <list>
- #include <cmath>
- #include <ctime>
- #include <deque>
- #include <queue>
- #include <stack>
- #include <string>
- #include <bitset>
- #include <cstdio>
- #include <limits>
- #include <vector>
- #include <climits>
- #include <cstring>
- #include <cstdlib>
- #include <fstream>
- #include <numeric>
- #include <sstream>
- #include <iostream>
- #include <algorithm>
- #include <unordered_map>
- using namespace std;
- //--------------------------------------------------
- //Prototype for masking function
- //Used for modular programming
- //--------------------------------------------------
- void mask(string& input, bool& inputover);
- int main() {
- //--------------------------------------------------------
- //Driver program used only to manage input
- //--------------------------------------------------------
- //Declare and initialize any variables that will be needed
- bool inputover = false; //When boolean is true it will signal
- //there is no more input to manage.
- string input; //String for input
- //Start Loop to get all inputs
- while (!inputover)
- {
- //Get Input and clear Cin to get next input
- getline(cin, input);
- cin.clear();
- //===========================================
- //Begin Modular Programming
- //===========================================
- //Mask input, and check if program over
- mask(input, inputover);
- }
- return 0;
- }
- //Function for data masking
- void mask(string& input, bool& inputover)
- {
- //-----------------------------------------
- //Variable declaration
- //-----------------------------------------
- string email, phone; //Variables used for manipulating input
- int at; //Integer will store the position of the
- //'@' in an email address from the input
- //Use Email Procedure
- if (input[0] == 'E')
- {
- //assign input to email for manipulation
- email = input;
- //iterate through email until '@' is found
- for (int i = 3; email[i-1] != '@'; i++)
- {
- //Once '@' is found store it's position
- if (email[i] == '@')
- {
- at = i;
- }
- }
- //Once position is found simply replace all the characters
- //from the second character to the second to last from the '@'
- // ie. From: abcdefghijklmnopqrstuvwxyz@website.com
- // ^----------------------^
- // To: a*****z@website.com
- //
- email.replace(3, at-4, "*****");
- //output result
- cout << email << endl;
- }
- //Use Phone Procedure
- else if (input[0] == 'P')
- {
- //Iterate through input and extract numbers, and +
- //and assign them to phone string for manipulation
- for (int i = 0; i < input.length(); i++)
- {
- if (input[i] > '/' && input[i] < ':' || input[i] == '+')
- {
- phone += input[i];
- }
- }
- //Insert phone identifier at beginning of phone string
- phone.insert(0, "P:");
- //=====================================================
- //applying format, and determining international code
- //=====================================================
- //Note: Standard Phone numbers are length 10 without
- //international code: (XXX) XXX-XXXX
- //if international code is included length will surpass
- //length 10: +XXX (XXX) XXX-XXXX
- //-----------------------------------------------------
- //check length for International code and insert hyphen
- //in phone string if International code is there
- if (phone.length() > 12)
- {
- phone.insert(phone.length() - 10, "-");
- }
- //Add standard hyphens that are included on all phone
- //formats regardless of size or international code
- phone.insert(phone.length() - 4, "-");
- phone.insert(phone.length() - 8, "-");
- //Mask every number except last 4
- for (int i = 0; i <phone.length() - 4; i++)
- {
- if (isdigit(phone[i]))
- {
- phone[i] = '*';
- }
- }
- //Display results
- cout << phone << endl;
- }
- //If no input or if not email or phone end program
- else
- {
- inputover = true;
- }
- //Clear strings for next input
- email.clear();
- phone.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement