0

そうです.. 私は自分の C++ クラス用に五角形のプロジェクトを書いています。そこで.. Pentagon クラスと Menu クラスを持つペンタゴン プログラムを作成する必要があります。Menu Class の作業は管理しましたが、Pentagon クラスの操作方法がわかりません。とにかく、私が現在必要としているのは、平方根で正しい方程式を作ることです。

五角形の面積を求める式は次のとおりです。

A = s^2 sqrt (of 25 + 10 sqrt (5) ) / (over) 4

では、どうすればいいですか?これは私が現在メニュークラスに持っているものです:

//  ==================
   #include "StdAfx.h"
   #include <string>
   #include <iostream>
   #include <cmath>
//  ==================

//  ================
//  Class Inclusions
//  ================
   #include "MenuClass.h"
   #include "Math.h"
//  ================

//  ====================
    using namespace std;
//  ====================

//  ============
//  Constructors
//  ============

//      ===================
//      Default Constructor
//      ====================
        Menu::Menu( void ) {

            userMenuSelection = Quit;

        } // Constructor Menu
//      =====================

        Menu::~Menu( void ) {

            cout << "====================================" << 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 << "======================================" << endl;
            cout << "             MENU SELECTION           " << endl;
            cout << "======================================" << endl;
            cout << "1: Calculate the Perimeter of Pentagon" << endl;
            cout << "2: Calculate the Area of Pentagon" << endl;
            cout << "3: Quit" << endl;
            cout << "======================================" << endl;
            cout << endl;

        } // Member-Function Display
//      ============================

//      =========================
//      Member-Function QueryUser
//      =========================
        void Menu::QueryUser( ) {

            int selection;

            cout << "Enter Menu Selection: ";
            cin >> selection;

            switch (selection){
                case 1: userMenuSelection = Perimeter;
                    break;

                case 2: userMenuSelection = Area;
                    break;

                case 3: userMenuSelection = Quit;

                default: userMenuSelection = Quit;
            } // switch
//          ===========

            cout << endl;

        } // Method QueryUser()
//      =======================

//      =================
//      Method Continue()
//      ========================
        bool Menu::Continue( ) {

            return userMenuSelection != Quit;

        } // Method Continue
//      ====================

//      ==============================
//      Member-Function ProcessCommand
//      ==============================
        void Menu::ProcessCommand( ) {

            int numberA; // Length of Sides
            int numberB; // Area


            if (userMenuSelection == Quit ){

               cout << "Thank you for using this type of program. Have a nice day!" << endl;
            }

            else if (userMenuSelection != Quit) {

            cout << "Please enter an integer value for the length of the sides: ";
            cin >> numberA;

//              ==============================
                switch ( userMenuSelection ) {

                    case Perimeter:

                        cout << "Perimeter = " << (5 * numberA) << endl;

                        break;

                    case Area:

                        // Equation of Area:
                        // s^2*sqrt(25+10(sqrt(5)))/4

                        // 10*sqrt(5) = 22.36067977

                        double area;
                        area = sqrt(numberA(1+1));

                        return area;

                        ///cout << "Area = " << ((numberA*numberA) * (5 + 22.36067977)) / 4  <<  endl;

                        //int param;
                        //int result;
                        //param = 1;

                        //cout << result = sqrt (param) << endl;


                        break;

                    default: cout << "Warning: error state encountered." << endl;

                }
                cout << endl;
              }    
            }

// ========================

助けてください!

4

1 に答える 1

1

数学の構文をコードに変換することについて混乱しているだけだと思います。

面積の式:

s^2*sqrt(25+10(sqrt(5)))/4

C++ では次のようになります。

double area = s * s * sqrt(25.0 + 10.0 * sqrt(5.0)) / 4.0;

その後、エラーが発生します:

return area;

ProcessCommand関数は です。voidつまり、値を返すことはできません。とにかくそんなことをしても意味がありません。std::coutおそらく、代わりに で出力したいでしょう。

于 2013-10-22T23:46:24.177 に答える