gpt4 book ai didi

c++ - C++ 中的五角大楼项目

转载 作者:行者123 更新时间:2023-11-28 07:20:35 24 4
gpt4 key购买 nike

Soo.. 我正在为我的 c++ 类(class)编写一个五边形项目,老实说,由于工作和其他类(class),我现在做得并不好。所以..我们需要制作一个五角大楼程序,其中包含五角大楼类和菜单类。我管理了工作菜单类,但我不确定如何使用五角大楼类。无论如何,我目前需要的是 - 制作一个带平方根的正确方程式。

求五边形面积的公式是:

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;
}
}

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

请帮忙!

最佳答案

我认为您只是对将数学语法转换为代码感到困惑。

你的面积方程:

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 输出它。

关于c++ - C++ 中的五角大楼项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19530225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com