Thread: Program using classes

  1. #1
    LMurphy
    Guest

    Program using classes

    I am taking a C++ programming class on the internet and I am having trouble grasping the concept of classes.
    I need to write a program that takes input from a menu as binary, decimal, hexadecimal, or octal. And it must have 5 classes. One class will store an entered number. The other four will be for binary, decimal and so on. The member functions of these classes enter and display the number I.E. The binary class enters and displays the number in binary. Then it will convert and display the entered number in all numeric bases.

    The class for a numeric base cannot store the entered number and the code must use public methods for each numeric base class.

    I do not understand where to begin on this. Can anyone help me???

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You are splitting data from views of that data. You will have a class that stores a number. You will then have 4 other classes that present different views of an object of the data class. So in these view classes store an object of the data class and have a view method that prints the data in the required format. Use the public interface of the stored object to feed its value to the view class.
    Code:
    class data
    {
         int num;
    
       public:
         int getnum() const
         { return num;}
    };
    
    class octalview
    {
       data obj;
    
       public:
         void view() const
         { std::cout<<std::oct<<obj.getnum();}
    };
    or similar....
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    In fact on rereading this what you want is not to store an object in your view classes but rather a reference or better still a pointer to an object of class data. That way especially with the pointer approach you can easily switch the underlying data that the view is viewing.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need the code of few programs in c++.plzzzzz help...plzzz
    By NAVINKR20 in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2009, 09:13 AM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM