Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:49:47+00:00 2026-06-11T03:49:47+00:00

I’m a new programmer trying to teach myself C++ and OOP. Right now I’m

  • 0

I’m a new programmer trying to teach myself C++ and OOP. Right now I’m working on a project with multiple states, and it’s my first attempt at a bigger programming task/challenge. Right now I’m trying to work on a simple menu state class, but I’m not sure how to go about designing it to do what I want. Specifically, I’m a beginner programmer, and I’m not sure what data types or templates to use.

Here’s a brief description of the type of menu screen that I want to make:

I’m trying to make a simple menu screen that has multiple ‘menu elements’ listed. Each ‘menu element’ contains a string (which is used to display the name of the element or item) and a function (to change states, screens, do a task, etc.). — The other ‘feature’ of the menu system that I want to have is the ability for selection to wrap around. For example, if the menu has 3 items, I want the user to be able to press up and down to switch the currently selected element, and if the user is on the last element (#3) and presses down again, they wrap back around to element #1. (and vice versa..)

Now, I ~think~ that this will require me to make a new class called ‘MenuElement’, and a class called ‘MenuState’ which contains and allows the user to switch between and select a specific element.

As a new, self-taught C++ programmer, I have limited experience with some of the more advanced containers and I’m much more familiar with simple c-style arrays. I have a little bit of experience with vectors, and I know a little bit about linked lists, maps, and trees, but I’m not sure which container type to use for this situation. I’ve seen examples of using pointers to create a circular linked list before, but the example was in C and it seemed a little bit clumsy. Is there a specific type of contain that bests fits my problem? Or am I over-thinking it, and I should just pick one and run with it?

I think I could eventually get this system up and running using an array of MenuElements with a series of conditional statements. However, I’m really interested in actually learning how to improve my programming and design, not only so that my code runs faster, but also so that my code is clean and logically constructed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:49:49+00:00Added an answer on June 11, 2026 at 3:49 am

    Wrap-around can be done with modulo arithmetic, i.e. given a private member index variable named idx_ of the active cursor into the array of menu elements, you could do have a member functions page_down() and page_up() like this

    void CompositeMenu::page_down()
    {
        // idx_ will always remain in the interval [0, num_elements() )
        // when idx_ equals num_elements() - 1, page_down() will yield 0 (i.e. wrap-around)
        idx_ = (idx_ + 1) % num_elements(); 
    }
    
    void CompositeMenu::page_up()
    {
        // idx_ will always remain in the interval [0, num_elements() )
        // when idx_ equals 0, page_up() will yield num_elements() - 1 (i.e. wrap-around) 
        idx_ = (idx_ - 1 + num_elements() ) % num_elements() ;
    }
    

    where num_elements() is the size of the current menu.

    For your general design question, a sketch of your class hierarchy would use the Composite Design Pattern (Wikipedia). This defines an abstract menu interface called IMenu and derives both CompositeMenu and a LeafMenu as concrete classes. This allows arbitrary levels of nested submenus.

    class IMenu
    {
    public:
        virtual void SomeOperation() = 0;
    };
    
    class CompositeMenu
    :
        public IMenu
    {
    public:
        virtual void SomeOperation() 
        { 
            // your implementation 
        }
    
        void page_down();  // use implementation above      
        void page_up();    // use implementation above
        int num_elements { return subMenus_.size(); }
    
    private:
        std::vector<IMenu*> subMenus_; // list of subMenus, which can also have nested menus themselves
        int idx_; // active menu element
    };
    
    class LeafMenu
    :
        public IMenu
    {
    public:
        virtual void SomeOperation()
        {
            // your implementation
        }
    };
    

    Note that since num_elements() is a member function that allows for dynamic updates on the subMenus (i.e. it would allow drag-and-drop of menu items).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.