phone numbers using classes?

This is a discussion on phone numbers using classes? within the C++ Programming forums, part of the General Programming Boards category; Can anyone point me to a simple phone number program using classes that i can learn from? Any examples are ...

  1. #1
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    phone numbers using classes?

    Can anyone point me to a simple phone number program using classes that i can learn from? Any examples are welcome.

    This is what i am trying to accomplish.

    A phone number consists of four separate pieces of information: an area code, an exchange, a local number, and a long-distance indicator (true or false). Design and build a PhoneNumber class that models a phone number, providing operations to construct, input, output extract each of the data members of a PhoneNumber object, and indicate whether or not the number is long-distance. The input operation should read a local or long-distance number and set the long-distance indicator accordingly. The output operation should display a local number differently from the way it displays a long-distance number (e.g., 555-1234 vs. (616) 555-1234).

    Thanks!!
    Last edited by correlcj; 11-09-2002 at 09:51 AM.
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Code:
    #include <iostream>
    #include <map>
    #include <string>
    int main()
    {
      using namespace std;
      map<string,int> numbers;
      numbers["petter"] = 19339;
      numbers["sos"] = 112;
      //...
    
      string s;
      cout << "Whose number do you want?";
      cin >> s;
      cout << s << "\'s number is:" << numbers[s];
    }
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Can anyone point me to a simple phone number program using classes that i can learn f

    Thanks for the input but I need something like so

    class PhoneNo

    public:

    //blah

    private:

    //blah

    to this effect so i can learn from...

    Can you help me?

    p.s. here is some code i have tinkered with but still clueless...
    Code:
    class PhoneNumber
    	{
    public:
    
    
    	// have a clue
    
    private:
    		int myLocalNumber;	//"555-5555"
    		int myLongDistance;	//"813-555-5555"
    		int myAreaCode;		//"813"
    		int myLocalExchange;	//
    	};
    i am clueless on where to put the code, how to run it so it would work. I think i would place it in a file like so...PhoneNo.h. Yes or no?

    Can someone shed some light for me?
    Last edited by correlcj; 11-09-2002 at 09:36 AM.
    "Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
    -Bruce Lee

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    an area code, an exchange, a local number, and a long-distance indicator (true or false). Design and build a PhoneNumber class that models a phone number, providing operations to construct, input, output extract each of the data members of a PhoneNumber object, and indicate whether or not the number is long-distance. The input operation should read a local or long-distance number and set the long-distance indicator accordingly. The output operation should display a local number differently from the way it displays a long-distance number (e.g., 555-1234 vs. (616) 555-1234).

    Code:
    class PhoneNumber
    {
       public:
         //declare constructor here
         //declare functions to change and retrieve each of the private data members here
         //declare function to get input here
         //declare function to output phone number here
     
       private:
         //declare private data members here
         int areaCode;
         int exchange;
         int localNumber;
         bool longDistance;
    };
    
    //function definitions for each of the public member functions go here.
    The input function may be quite variable depending how you obtain input: from a file, user input, a single string input, three int inputs and one boolean input, etc. Presumably the instructions provided by the instructor gave you how the input will be obtained.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Rational Numbers (C++)
    By cloudjc in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2008, 05:03 PM
  2. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 09:45 PM
  3. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 08:26 PM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 04:49 AM
  5. Replies: 4
    Last Post: 03-03-2003, 03:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21