2013-10-22 63 views
0

Soo ..我正在爲我的C++類寫一個五角大樓項目,說實話,我現在並沒有因爲工作和其他課程而做得很好。所以......我們需要製作一個五角大樓程序,該程序將具有五角大樓課程和菜單課程。我管理工作菜單類,但我不知道如何與五角大樓類。無論如何,我目前需要的是 - 用平方根做出正確的方程。C++中的五角大樓項目

方程尋找五邊形的區域是:

A = S^2的sqrt(25 + 10的sqrt(5))/(過)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

這個問題聽起來像是你在爲美國政府工作。 –

+0

@GiulioFranco Lol。好的。 – papi

+1

在我看來,如果你在做五角大樓項目,你應該使用Ada。 –

回答

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來代替輸出。

+0

你是天才!非常感謝你! @稻田 – papi