2013-10-22 35 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