C ++中的五角大楼项目 [英] Pentagon Project in c++
问题描述
Soo ..我正在为我的c ++类编写一个pentagon项目,老实说,我现在由于应聘的工作和其他班级的表现还不是很好.因此..我们需要制作一个具有五角大楼类和菜单类的五边形程序.我管理过菜单类,但是不确定如何使用五角大楼类.无论如何,我目前需要的是-求一个具有平方根的正确方程.
Soo.. I'm writing a pentagon project for my c++ class, and to be honest I'm not really doing well right now due job and other classes. So.. we need to make a pentagon program that will have Pentagon class and Menu Class. I managed working Menu Class but I'm not sure how to work with Pentagon class. anyways, what I currently need is - to make a right equation with square roots.
寻找五边形面积的公式为:
Equation for finding a Area of pentagon is:
A = s ^ 2 sqrt(of 25 + 10 sqrt(5))/(over)4
A = s^2 sqrt ( of 25 + 10 sqrt (5) ) / (over) 4
那我该怎么做呢?这是我当前在菜单类中所拥有的:
So how do I do that? This is what I currently have in my Menu Class:
// ==================
#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;
}
}
// ========================
请帮助!
推荐答案
我认为您只是对将数学语法转换为代码感到困惑.
I take it that you're just confused about translating math syntax into code.
您的面积方程:
s^2*sqrt(25+10(sqrt(5)))/4
在C ++中是这样的:
Goes like this in C++:
double area = s * s * sqrt(25.0 + 10.0 * sqrt(5.0)) / 4.0;
在那之后,您有一个错误:
After that, you have an error:
return area;
ProcessCommand
函数是void
,这意味着您无法返回值.无论如何,这样做是没有意义的.也许您想改为使用std::cout
来输出它.
The ProcessCommand
function is void
, which means you can't return a value. It wouldn't make sense to do so anyway. Perhaps you want to output it with std::cout
instead.
这篇关于C ++中的五角大楼项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!