Thread: Phone Class

  1. #1
    Unregistered
    Guest

    Phone Class

    I really need help with classes, I do not know if its actually the classes or functions. But I need help with my project for my class. The problems is to design a program for a phone system. The system consists of 10 phones numbered 0-9. Each phone submits requests to the control box that attempts to execute the request. We need to write a control Box software and the phone software to manage the calls requests come into the control box.
    DL<from><to> - This request attempts to dial <from> one phone <to> another.
    HU<phone> - This request hangs up a phone. When two people are talking and one hangs up the other phone automatically hangs up.
    CM<phone> - This request starts someones personal phone messages and should give callers a busy signal.
    ST - This request reports the number of times a person has listened to their messages and how many internal phone calls have been made.
    The program will read from a data file
    example:
    DL 4 6 //complete call
    DL 1 4 //should get busy signal
    CM 9 //phone 9 checking their messages
    HU 9 //9 hangs up from checking messages
    HU 4 // 4 hangs up from 6 and 6 should automatically hang up


    I know this is kind of long but I really need help. The last programming class I took was two years ago, so please keep the negative comments away and help if you can. Thanks


    This is what I came up with so far.

    #include <fstream.h>
    #include <stdlib.h>
    #include <string.h>


    class phone{
    private:
    int nCompcalls; //count number of completed calls
    int nCheckmess; //count number of checked messages
    int Talking; // phone availability
    public:
    phone();
    };

    phone:hone()
    {
    nCompcalls = 0;
    Talking = -1; // Talking = -1 when line is available and = the number of person talking to when talking
    ncheckmess = 0;
    }

    class controlbox{
    private:
    phone system[10];

    int CM; // checking messages
    int HU; // hang up
    int busy; // line busy
    int status; // number times checked phone messages and internal calls
    public:
    void Dial(int,int);
    void Checkmess(int);
    void Hangup(int);

    };

    void Dial(int from, int to)
    {
    if (to == -1) // if to is -1 or available
    {
    to = from; // make to equal to from
    cout << "Completed Call \n"
    }

    else{
    cout << " Unable to complete call \n";
    }
    }

    void Checkmess(int CM)
    {
    CM = 1;
    cout << " Line is busy \n";

    }

    //missing functions


    void main(void)

    {
    ifstream tfile;
    ofstream ofile;

    tfile.open("Project3Data.txt");
    ofile.open("output.txt");

    if(tfile.fail ())
    {
    cout << " Unable to open file.";
    exit(1);
    }

    //missing information in main

    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Well, a lot of people get a little ticked off if you don't use <code> tags, so get ready for some of those negative comments..... I don't know why it matters..... all it does is indent it.... Anyway - for starters - there'll be problems with people getting your code because one of the class names (or part of it) was turned into a smiley. Other than that, what exactly IS your question?

  3. #3
    Unregistered
    Guest
    sorry, I do not know what code tags are or how to use them. Please explain if you don't mind.

    My main concern in my program is the member functions. I can not seem to put them into the program. For instance, the Void Dial(int, int) and Void Checkmess(int), I know what needs to be done in the program but just can not code it. I really do not know how to create the member functions. If you can help me create better member function I think I can precede. right now I am stuck. Thanks

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    [c o d e]

    [/c o d e]

    without the spaces will give code tags.

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    23
    Originally posted by Unregistered
    sorry, I do not know what code tags are or how to use them. Please explain if you don't mind.

    My main concern in my program is the member functions. I can not seem to put them into the program. For instance, the Void Dial(int, int) and Void Checkmess(int), I know what needs to be done in the program but just can not code it. I really do not know how to create the member functions. If you can help me create better member function I think I can precede. right now I am stuck. Thanks
    Well its almost the same as the constructor for example:
    Code:
    class controlbox{ 
      private: 
      phone system[10]; 
    
      int CM; // checking messages 
      int HU; // hang up 
      int busy; // line busy 
      int status;  
    
      public: 
        void Dial(int,int); 
        void Checkmess(int);  
        void Hangup(int); 
    }; 
    
    void controlbox::Dial(int from, int to)  { 
      if (to == -1) // if to is -1 or available 
      { 
        to = from; // make to equal to from 
        cout << "Completed Call \n" 
      } 
    }//end Dial(int,int)
    I think that is what you wanted..

    [edit]the smiley face is ": D" without the space...its a smiley face if you put them together on these boards..[/edit]

    -Dennis

  6. #6
    Unregistered
    Guest
    Ok I see... I guess you have to put the return type, the class name, the object, then the parameters. Like the function checkmess, I would put
    void controlbox::Checkmess(int CM)
    {
    CM = 1;
    cout << " Line is busy \n";
    }



    But does the functions work for the Dial command and checkmess? Also how can I create member functions for HU<phone> to hang up a phone and automatically hung up the other persons phone?

    -Nicky

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM