Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get a number from a class? C++
    primarykey
    data
    text
    <p>So, let's say I have a project. This projects uses two classes. First class MenuClass and a second is Pentagon Class.</p> <p>Say I get inputs in Menu class, and I want to move or copy, whatever you say, to Pentagon Class.</p> <p>How do you do that? Here's a piece of code form my MenuClass:</p> <pre><code> Menu::Menu( void ) { userMenuSelection = Quit; } // Constructor Menu // ===================== Menu::~Menu( void ) { cout &lt;&lt; "====================================" &lt;&lt; endl; } // Destructor ~Menu // ===================== // ============================== // Accessor Member-Function Get() // ========================== MenuChoices Menu::Get( ) { return userMenuSelection; } // Accessor Method Get // ======================== // ============================= // Mutator Member-Function Set() // ======================================== void Menu::Set( MenuChoices newValue ) { userMenuSelection = newValue; } // Mutator Method Set // ======================= // ========================== // Member-Function Display( ) // ========================== void Menu::Display( ) { cout &lt;&lt; "======================================" &lt;&lt; endl; cout &lt;&lt; " MENU SELECTION " &lt;&lt; endl; cout &lt;&lt; "======================================" &lt;&lt; endl; cout &lt;&lt; "1: Calculate the Perimeter of Pentagon" &lt;&lt; endl; cout &lt;&lt; "2: Calculate the Area of Pentagon" &lt;&lt; endl; cout &lt;&lt; "3: Quit" &lt;&lt; endl; cout &lt;&lt; "======================================" &lt;&lt; endl; cout &lt;&lt; endl; } // Member-Function Display // ============================ // ========================= // Member-Function QueryUser // ========================= void Menu::QueryUser( ) { int selection; cout &lt;&lt; "Enter Menu Selection: "; cin &gt;&gt; selection; switch (selection){ case 1: userMenuSelection = Perimeter; break; case 2: userMenuSelection = Area; break; case 3: userMenuSelection = Quit; default: userMenuSelection = Quit; } // switch // =========== cout &lt;&lt; endl; } // Method QueryUser() // ======================= // ================= // Method Continue() // ======================== bool Menu::Continue( ) { return userMenuSelection != Quit; } // Method Continue // ==================== // ============================== // Member-Function ProcessCommand // ============================== void Menu::ProcessCommand( ) { int numberA; // Length of Sides if (userMenuSelection == Quit ){ cout &lt;&lt; "Thank you for using this type of program. Have a nice day!" &lt;&lt; endl; } else if (userMenuSelection != Quit) { cout &lt;&lt; "Please enter an integer value for the length of the sides: "; cin &gt;&gt; numberA; </code></pre> <p>So whenever I move/copy these input to Pentagon class I want it to do, for example something like this:</p> <pre><code> void Pentagon::ProcessCommand( ) { int numberA; // Length of Sides if (userMenuSelection == Quit ){ cout &lt;&lt; "Thank you for using this type of program. Have a nice day!" &lt;&lt; endl; } else if (userMenuSelection != Quit) { cout &lt;&lt; "Please enter an integer value for the length of the sides: "; cin &gt;&gt; numberA; // ============================== switch ( userMenuSelection ) { case Perimeter: cout &lt;&lt; "Perimeter = " &lt;&lt; (5 * numberA) &lt;&lt; endl; break; case Area: cout &lt;&lt; "Area = " &lt;&lt; numberA * numberA * sqrt(25.0 + 10.0 * sqrt(5.0)) / 4.0; break; default: cout &lt;&lt; "Warning: error state encountered." &lt;&lt; endl; } cout &lt;&lt; endl; } } </code></pre> <p>And then output this areas and stuff in main();</p> <p>Any ideas? Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload