Raptor FlowCharts

closed account (LvfERXSz)
Need help with Raptor flowcharts, I will later need to write a C++ program that does the same thing. So far have input to string, a test if it is a number then write to another string, but if characters other than a number are entered it still records a space..How do I get around that

Many websites ask for phone numbers. The problem is that there are many ways
to represent a phone number. Examples include 817-555-1234, 817 555 1234
(c), and (817) 555-1234 x23. Write a Raptor program which inputs a string
containing a US phone number in any format and outputs it in the international
standard format. The international standard for US phone numbers is -
+1-817-555-1234
Your Raptor program should:
1. Input a string including the number
2. Copy only the digits from the input string into another string
3. If the input string contains more than 10 digits, include only the first 10
digits in the formatted number
4. If the input string contains less than 10 digits replace the missing digits
with lower case x.
5. Output the phone number in the international standard format
Hints:
1. In Raptor, a string is just an array of characters.
2. Lesson #9 has an example of working with strings in Raptor.
3. When only digits are input, Raptor assumes it is an integer instead of a
string. Your flowchart does not need to properly handle an input like
8175551234, but your C++ version does need to handle that.
4. I recommend passing the digits only string to a procedure which outputs it
in the standard format.
Sample Output (inputs in bold)
Please enter a phone number: 817-555-1234
The properly formatted number is +1-817-555-1234
Please enter a phone number: (817)515 7259 x23
The properly formatted number is +1-817-515-7259
Please enter a phone number: 214-555-99
The properly formatted number is +1-214-555-99xx
Please enter a phone number: 800**4444xxx333
The properly formatted number is +1-800-444-4333
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

string telephone( const string &input )
{
   const string IDC = "+1";
   string digits;
   for ( char c : input ) if ( isdigit( c ) ) digits += c;
   if ( digits.size() < 10 ) digits += string( 10-digits.size(), 'x' );
   return IDC + "-" + digits.substr( 0, 3 ) + "-" + digits.substr( 3, 3 ) + "-" + digits.substr( 6, 4 );
}

int main()
{
   string phone;
   cout << "Enter a 'phone number: ";   getline( cin, phone );
   cout << telephone( phone ) << '\n';
}


Enter a 'phone number: ET phone home on (999) 6781234
+1-999-678-1234
closed account (LvfERXSz)
Thank you
amfedor12, Please don't abuse the forum.

When you have your answer don't edit your original post as it makes it useless for others to learn from.
closed account (LvfERXSz)
@Grey Wolf
Understood.
I still cannot figure out Raptor, which I feel is unnecessary if C++ is what I'm supposed to be learning
I did a 'net search on RAPTOR Flowcharts ( https://duckduckgo.com/?q=raptor+flowcharts&t=ffsb&ia=web ), and the app has virtually nothing to do with C++ programming. More to do with an alternate way to program other than using a conventional programming language, if that, more about learning to use and understand programming flowcharts.

A C/C++ fora was probably not the best place to get support on this software, but really was no need to close out the account.

RAPTOR, Windows only, and originally developed by the U.S. Air Force Academy, Department of Computer Science. O-o-o-o-o-o-kay!


Registered users can post here. Sign in or register to post.