Desperate Need of Assistance

Hello I am in week 4 of my c++ programming class and I am not gettng a handle on this language.

The professor wants us to create a program for the following:

-------------------------------------------------------------------------------

Write a program that simulates the dialing of a phone number.

A user will input an 8-place number, for example: 359-3177 (note that the hyphen is considered a digit).
The rules for entering phone numbers follow.

• 8 places
• It may have numbers, letters, or both.
• The phone number cannot begin with 555.
• The phone number cannot begin with 0.
• The hyphen must be in the 4th position.
• No other characters (@#$%^&*()_+=\|/><etc.) are allowed.
• If a letter is entered, its output will be a number (check your phone pad).
• Enter Q to Quit.

If all of the rules are met, you will output a message to the console that reads like the following.
Phone Number Dialed: UN9-3177 *the number entered

If all of the rules are not met, then you output one of the following error messages to the console.

• ERROR - Phone number cannot begin with 555
• ERROR - Phone number cannot begin with 0
• ERROR - Hyphen is not in the correct position
• ERROR - An invalid character was entered

It will then prompt the user to try again.


This should be a lot of fun!
Here are some great things to think about as you begin your program!

Define a function named ReadDials() that reads each digit and letter dialed into 8 separate char variables (DO NOT USE ARRAYS). All the digits are sent back through parameters by reference.

Then, for each digit, the program will use a function named ToDigit(), which receives a single char argument (pass by reference) that may be a number or a letter of one of the digits dialed.

If it is a number, then return 0 by value indicating that it is a valid digit. If the digit is a letter, then the number corresponding to the letter is returned by reference, and return 0 by value indicating that it is a valid digit. Here are the letters associated with each digit.

0 5 J K L
1 6 M N O
2 A B C 7 P Q R S
3 D E F 8 T U V
4 G H I 9 W X Y Z

If the digit entered is not one of the valid digits or one of the valid letters, return –1 by value indicating that you have an invalid digit.

A phone number never begins with a 0, so the program should flag an error if such a number is entered. Make ReadDials() return –2 in this case.

A phone number never begins with 555, so the program should flag an error if such a number is entered. Make ReadDials() return –3 in this case.

A phone number always has a hyphen (-) in the 4th position. Make ReadDials() return –4 in this case (if it doesn't have a hyphen in the 4th position). If a hyphen is in any other position, it is considered an invalid digit.

If the phone number is valid, the main calls the AcknowledgeCall function to write the converted number to the output file.

All the logic of the program should be put in functions that are called from Main(): ReadDials() and AcknowledgeCall().

The ToDigits() function is called from the ReadDials() function and is used to convert each letter entered individually into a digit and to verify that the user has entered a valid phone number. Have the program work for any number of phone numbers.

In the ToDigits() function uses the toupper function to convert any letters entered to uppercase. All the error messages are to be written to the output file from main() based on the return value from the functions.

Continue processing until the user enters a Q.

You will set up the 8 char variables to hold the digits of the phone number in main() and pass the variables to the functions by reference.


--------------------------------------------------------------------------------

But I don't even Know where to begin.
If anybody can shed light or point me in the right direction I would appreciate it.

FYI: The program is due on 09-30-2012 by midnight
start by thinking about the functions and variables you will need.

With simple problems I always start by declaring the variables and functions I know I need in comments like

1
2
3
4
5
6
7
8
9
10
int main()
{
//var num1;
//var num2;

...
return 0;
}
//int ReadDials(...)
//{...} 


And then once you have everything written out start removing the comments and begin implementing the actual program.
Begin with what you know and build from there. There must be something in there that you yourself can start with.

For example, the instructions give you many details on a particular function. Try to write it out. Use your textbook to help with syntax. What must all functions look like ? What must this function have according to the instructions ?

In addition, there's lots of if/elses in the instructions. Translate them into simple code and build from there. Put all of that together including a skeleton for main() and you'll be in business. We can then help you fill in the gaps.

gl ! XD
Topic archived. No new replies allowed.