Okay, so I need to create a Pentagon Project and I'm kind of Confused here. I mean, it works great but I'm missing one class that must have some code in it.
Assignment is:
Write a program and call it PentagonProject. Besides the file containing the main() funct. there should be two other classes, each in its own pair of files (.h; .cpp). One of the classes should be class MenuClass, and the other should be called Pentagon. There should be a user loop in main() that invokes MenuClass member-function DisplayMenu and so forth. The menu should allow the user to specify, as well as change, the dimensions of the instance of the Pentagon class, also known as an object. A pentagon shall be a regular (all sides are the same). A pentagon has five sides. We shall denote the length of the sides by s. Then perimeter, P, and area, A, of a pentagon are as follows.
Equations:
P = 5s
A = s^2 sqrt ( of 25 + 10 sqrt (5) ) / (over) 4
The menu should allow the user to calculate the perimeter and the area of an instance of the Pentagon Class. Your program should have a single Pentagon Object.
So, that's being said, the program works great, but what I didn't get is what exactly and how exactly should I code in Pentagon Class.
My PentagonProject (or main):
// PentagonProject.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "MenuClass.h"
using namespace std;
int main()
{
Menu menu;
do
{
menu.Display();
menu.QueryUser();
menu.ProcessCommand();
}
while(menu.Continue());
return 0;
}
This is how my MenuClass looks like:
// ==================
#include "StdAfx.h"
#include <string>
#include <iostream>
// ==================
// ================
// 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
double area; // 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:
cout << "Area = " << numberA * numberA * sqrt(25.0 + 10.0 * sqrt(5.0)) / 4.0;
break;
default:
cout << "Warning: error state encountered." << endl;
}
cout << endl;
}
}
// ========================
So.. how can you see the program works without Pentagon Class.. and my questions is what should I do in order to let this project work with both classes at a time