I'm new to programming (only 4th week) and i am supposed to try and create a program that will... well ill just post what it wants as its alot. I'm just not sure how to get started on this as im drawing a blank on what to do. it is homework so im not looking for any "do it for me" help.

Write a program that simulates the dial of a phone number. The program will input a phone number and the program will acknowledge the call by either writing an error message or the 8 digit phone number to the console window. The phone number may have either digits, letters, or both.

Define a function named ReadDials() that reads each digit/letter dialed into 8 separate char variables (DO NOT USE ARRAYS). All 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, return 0 by value indicating it is a valid digit. If the digit is a letter, the number corresponding to the letter is returned by reference and return 0 by value indicating 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 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. Also 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 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, 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 to a digit and to verify the user has entered a valid phone number. Have the program work for any number of phone numbers. Continue processing until the user enters a Q.

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

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.

Recommended Answers

All 6 Replies

You can start by writing an empty main function, and other functions that the question states (ReadDials) etc. put the 8 char variables in main, and call ReadDials with those 8 variables.

.

ok heres what i got so far. any help would be great.

#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>
char readDial( int & d);
int toDigit(int & d);
int acknowledgeCall();
int phoneNumber;
using namespace std;

//prototypes


int main()
{
	

	char readDial(int & d);

	int returnValue = 0;
    while (returnValue != -5)
	{
	switch(returnValue)
	{
		case -1: cout << "ERROR - An invalid character was entered" << endl; break;
		case -2: cout << "ERROR - Phone number cannont begin with 0" << endl; break;
		case -3: cout << "ERROR - Phone number cannont begin with 555" << endl; break;
		case -4: cout << "ERROR - Hyphen is not in the correct position" << endl; break;
		}
	}
}
	int toDigit(int & d)
	{
		toupper(d);

		switch(d)
		{
		case 'A': case 'B': case 'C':
			d = '2'; break;
		case 'D': case 'E': case 'F':
			d = '3'; break;
		case 'G': case 'H': case 'I':
			d = '4'; break;
		case 'J': case 'K': case 'L':
			d = '5'; break;
		case 'M': case 'N': case 'O':
			d = '6'; break;
		case 'P': case 'Q': case 'R': case 'S':
			d = '7'; break;
		case 'T': case 'U': case 'V': 
			d = '8'; break;
		case 'W': case 'X': case 'Y': case 'Z':
			d = '9'; break;
		}
	}
	char readDial(int & d)
	{
		

		cout << "Please enter a phone number: " << endl;
		getline(cin, phoneNumber);
		if (phoneNumber == 'Q' || phoneNumber == 'q')
		{
			return -5;
		}
		phoneNumber = toDigit(int & d);
	}
	int acknowledgeCall()
	{
		cout << "Phone number dialed: " << phoneNumber << endl;
	}
}

I am having sort of the same problem as you, did you ever find a solution?

I am having sort of the same problem as you, did you ever find a solution?

not yet..still waiting for help

not yet..still waiting for help

Are you taking this for a class at devry?

I finished most of the code except one error that I have not been able to figure out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.