C++ C++;使用getArea()并访问数组计算圆的面积

C++ C++;使用getArea()并访问数组计算圆的面积,c++,arrays,visual-studio-2010,geometry,member-functions,C++,Arrays,Visual Studio 2010,Geometry,Member Functions,我需要一些关于以下问题的帮助,即使用getArea()方法计算数组中每个圆的面积。如何访问数组,然后使用circle::getArea()成员函数计算圆的面积 Main.cpp文件 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; #include "Circle.h" #include "Random.h" int main() { // Ar

我需要一些关于以下问题的帮助,即使用getArea()方法计算数组中每个圆的面积。如何访问数组,然后使用circle::getArea()成员函数计算圆的面积

Main.cpp文件

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

#include "Circle.h"
#include "Random.h"

int main()
{
    // Array 1, below section is to populate the array with random 
    // radius number within lower and upper range
    int CircleArrayOne [5];
    const int NUM = 5;

    srand(time(NULL));

    for(int x = 0; x < NUM; ++x)
    {
        CircleArrayOne[x] = Random::random(1, 40); // assumed 0 and 40 as the bounds
    }

    // output the radius of each circle
    cout << "Below is the radius each of the five circles in the second array. " << endl;

    // below is to output the radius in the array
    for(int i = 0; i < NUM; ++i) 
    {
        cout << CircleArrayOne[i] << endl;
    }

    // Here I want to access the array to work out the area using 
    // float Circl::getArea()

    system("PAUSE");
    return 0;
}

float Circle::getArea()
{
    double PI = 3.14;
    return (PI * (Radius*Radius));
}

float Circle::getRadius()
{
    return Radius;
}

int Random::random(int lower, int upper)
{
    int range = upper - lower + 1;
    return (rand() % range + lower);
}
#包括
#包括
#包括
使用名称空间std;
#包括“Circle.h”
#包括“Random.h”
int main()
{
//数组1,下面的部分是用随机变量填充数组
//上下限范围内的半径数
int-CircleArrayOne[5];
常数int NUM=5;
srand(时间(空));
对于(int x=0;xcout到目前为止,您只有圆的随机半径,但没有圆
对象。因此,首先创建圆对象

Circle obj[5];   // Create 5 objects default constructed.

现在,使用
setRadius
设置每个对象的半径,并调用每个对象上的区域。

您没有任何
s可调用
getArea()你想知道哪个领域?我完全理解你是C++新手,你在寻求帮助,但是我认为坐下来阅读C++的工作原理是一个很好的观点。你需要学习一个类是什么,以及如何调用方法,这样你就可以理解这里发生了什么。这个问题没有提供足够的关于如何回答的信息。
Circle obj[5];   // Create 5 objects default constructed.