A
AJ
AJ
Hey Everybody I am in a bit of jam. I am new programming so please can
help will be appreciated.
Thanks In Advance
I have two header files and i am trying to call a function from ball.h
in ballpit.h, but get this error
error: request for member ‘GetX’ in ‘ball’, which is of non-class type
‘Ball ()()’
here ball.h
#########################################################################################
#ifndef CSCI135P5_BALL_H
#define CSCI135P5_BALL_H
#include "csci135canvas.h"
class Ball
{
public:
Ball(double x, double y, double vx, double vy, double radius);
Ball();
void Step();
void Draw(Canvas &canvas);
//double Distance(Ball &ball);
double GetX();
double GetY();
double GetVX();
double GetVY();
double GetRadius();
void SetX(double new_x);
void SetY(double new_y);
void SetVX(double new_VX);
void SetVY(double new_VY);
void SetRadius(double new_Radius);
private:
double X_position;
double Y_position;
double X_velocity;
double Y_velocity;
double Ball_Radius;
};
#endif
##################################################################################
here is ball.cpp
##################################################################################
#include "csci135p5ball.h"
#include "csci135canvas.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Ball::Ball(double x, double y, double vx, double vy, double radius)
{
X_position = x;
Y_position = y;
X_velocity = vx;
Y_velocity = vy;
Ball_Radius = radius;
}
Ball::Ball()
{
srand ( time(NULL) );
double x_rand = rand() % 500;
double y_rand = rand() % 500;
double vx_rand = rand() % 5 + -5;
double vy_rand = rand() % 5 + -5;
double radius_rand = rand() % 12 + 2;
Ball(x_rand, y_rand, vx_rand, vy_rand, radius_rand);
}
void Ball::Step()
{
if (X_position == 0)
X_velocity = -(X_velocity);
else if (X_position == 500)
X_velocity = -(X_velocity);
else if (Y_position == 0)
Y_velocity = -(Y_velocity);
else if (Y_position == 500)
Y_velocity = -(Y_velocity);
X_position = X_position + X_velocity;
Y_position = Y_position + Y_velocity;
}
void Ball:raw(Canvas &canvas)
{
canvas.DrawCircle(X_position, Y_position, Ball_Radius);
}
/*
double Ball:istance(Ball &ball);
{
}
*/
double Ball::GetX()
{
return X_position;
}
double Ball::GetY()
{
return Y_position;
}
double Ball::GetVX()
{
return X_velocity;
}
double Ball::GetVY()
{
return Y_velocity;
}
double Ball::GetRadius()
{
return Ball_Radius;
}
void Ball::SetX(double new_x)
{
X_position = new_x;
}
void Ball::SetY(double new_y)
{
Y_position = new_y;
}
void Ball::SetVX(double new_VX)
{
X_velocity = new_VX;
}
void Ball::SetVY(double new_VY)
{
Y_velocity = new_VY;
}
void Ball::SetRadius(double new_Radius)
{
Ball_Radius = new_Radius;
}
##################################################################################
here is ballpit.h
##################################################################################
#ifndef CSCI135P5_BALLPIT_H
#define CSCI135P5_BALLPIT_H
#include "csci135canvas.h"
#include <vector>
using std::vector;
class BallPit
{
public:
BallPit(int ball_number);
void step();
void draw(Canvas &canvas);
private:
int ballpit;
double x_spot;
double y_spot;
double xv_spot;
double yv_spot;
double radius_spot;
vector<double> initial_x;
vector<double> initial_y;
vector<double> initial_xv;
vector<double> initial_yv;
vector<double> initial_radius;
};
#endif
###################################################################################
here is ballpit.cpp
####################################################################################
#include "csci135p5ballpit.h"
#include "csci135p5ball.h"
#include "csci135canvas.h"
#include <vector>
using std::vector;
BallPit::BallPit(unsigned int ball_number)
{
ballpit = ball_number;
for(unsigned int i = 0; i < ball_number; i++)
{
Ball ball();
x_spot = ball.GetX();
y_spot = ball.GetY();
xv_spot = ball.GetXV();
yv_spot = ball.GetYV();
radius_spot = ball.GetRadius();
initial_x.push_back(x_spot);
initial_y.push_back(y_spot);
initial_xv.push_back(xv_spot);
initial_yv.push_back(yv_spot);
initial_radius.push_back(radius_spot);
ball.Draw(Canvas &Bcanvas);
}
}
void BallPit::step()
{
for(unsigned int x = 0; x < ballpit; x++)
{
ball.SetX(initial_x[x]);
ball.SetY(initial_y[x]);
ball.SetVX(initial_xv[x]);
ball.SetVY(initial_xy[x]);
ball.SetRadius(initial_radius[x]);
ball.Step();
x_spot = ball.GetX();
y_spot = ball.GetY();
xv_spot = ball.GetVX);
yv_spot = ball.GetVY);
radius_spot = ball.GetRadius();
initial_x[x] = x_spot;
initial_y[x] = y_spot;
initial_xv[x] = xv_spot;
initial_yv[x] = yv_spot;
initial_radius[x] = radius_spot;
}
}
double BallPit::draw(Canvas &canvas)
{
for(unsigned int y = 0; y < ballpit; y++)
{
ball.SetX(initial_x[y]);
ball.SetY(initial_y[y]);
ball.SetVX(initial_xv[y]);
ball.SetVY(initial_xy[y]);
ball.SetRadius(initial_radius[y]);
ball.Draw(Canvas &canvas);
}
}
##################################################################################
Thank you in advance for any help.
AJ
Hey Everybody I am in a bit of jam. I am new programming so please can
help will be appreciated.
Thanks In Advance
I have two header files and i am trying to call a function from ball.h
in ballpit.h, but get this error
error: request for member ‘GetX’ in ‘ball’, which is of non-class type
‘Ball ()()’
here ball.h
#########################################################################################
#ifndef CSCI135P5_BALL_H
#define CSCI135P5_BALL_H
#include "csci135canvas.h"
class Ball
{
public:
Ball(double x, double y, double vx, double vy, double radius);
Ball();
void Step();
void Draw(Canvas &canvas);
//double Distance(Ball &ball);
double GetX();
double GetY();
double GetVX();
double GetVY();
double GetRadius();
void SetX(double new_x);
void SetY(double new_y);
void SetVX(double new_VX);
void SetVY(double new_VY);
void SetRadius(double new_Radius);
private:
double X_position;
double Y_position;
double X_velocity;
double Y_velocity;
double Ball_Radius;
};
#endif
##################################################################################
here is ball.cpp
##################################################################################
#include "csci135p5ball.h"
#include "csci135canvas.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Ball::Ball(double x, double y, double vx, double vy, double radius)
{
X_position = x;
Y_position = y;
X_velocity = vx;
Y_velocity = vy;
Ball_Radius = radius;
}
Ball::Ball()
{
srand ( time(NULL) );
double x_rand = rand() % 500;
double y_rand = rand() % 500;
double vx_rand = rand() % 5 + -5;
double vy_rand = rand() % 5 + -5;
double radius_rand = rand() % 12 + 2;
Ball(x_rand, y_rand, vx_rand, vy_rand, radius_rand);
}
void Ball::Step()
{
if (X_position == 0)
X_velocity = -(X_velocity);
else if (X_position == 500)
X_velocity = -(X_velocity);
else if (Y_position == 0)
Y_velocity = -(Y_velocity);
else if (Y_position == 500)
Y_velocity = -(Y_velocity);
X_position = X_position + X_velocity;
Y_position = Y_position + Y_velocity;
}
void Ball:raw(Canvas &canvas)
{
canvas.DrawCircle(X_position, Y_position, Ball_Radius);
}
/*
double Ball:istance(Ball &ball);
{
}
*/
double Ball::GetX()
{
return X_position;
}
double Ball::GetY()
{
return Y_position;
}
double Ball::GetVX()
{
return X_velocity;
}
double Ball::GetVY()
{
return Y_velocity;
}
double Ball::GetRadius()
{
return Ball_Radius;
}
void Ball::SetX(double new_x)
{
X_position = new_x;
}
void Ball::SetY(double new_y)
{
Y_position = new_y;
}
void Ball::SetVX(double new_VX)
{
X_velocity = new_VX;
}
void Ball::SetVY(double new_VY)
{
Y_velocity = new_VY;
}
void Ball::SetRadius(double new_Radius)
{
Ball_Radius = new_Radius;
}
##################################################################################
here is ballpit.h
##################################################################################
#ifndef CSCI135P5_BALLPIT_H
#define CSCI135P5_BALLPIT_H
#include "csci135canvas.h"
#include <vector>
using std::vector;
class BallPit
{
public:
BallPit(int ball_number);
void step();
void draw(Canvas &canvas);
private:
int ballpit;
double x_spot;
double y_spot;
double xv_spot;
double yv_spot;
double radius_spot;
vector<double> initial_x;
vector<double> initial_y;
vector<double> initial_xv;
vector<double> initial_yv;
vector<double> initial_radius;
};
#endif
###################################################################################
here is ballpit.cpp
####################################################################################
#include "csci135p5ballpit.h"
#include "csci135p5ball.h"
#include "csci135canvas.h"
#include <vector>
using std::vector;
BallPit::BallPit(unsigned int ball_number)
{
ballpit = ball_number;
for(unsigned int i = 0; i < ball_number; i++)
{
Ball ball();
x_spot = ball.GetX();
y_spot = ball.GetY();
xv_spot = ball.GetXV();
yv_spot = ball.GetYV();
radius_spot = ball.GetRadius();
initial_x.push_back(x_spot);
initial_y.push_back(y_spot);
initial_xv.push_back(xv_spot);
initial_yv.push_back(yv_spot);
initial_radius.push_back(radius_spot);
ball.Draw(Canvas &Bcanvas);
}
}
void BallPit::step()
{
for(unsigned int x = 0; x < ballpit; x++)
{
ball.SetX(initial_x[x]);
ball.SetY(initial_y[x]);
ball.SetVX(initial_xv[x]);
ball.SetVY(initial_xy[x]);
ball.SetRadius(initial_radius[x]);
ball.Step();
x_spot = ball.GetX();
y_spot = ball.GetY();
xv_spot = ball.GetVX);
yv_spot = ball.GetVY);
radius_spot = ball.GetRadius();
initial_x[x] = x_spot;
initial_y[x] = y_spot;
initial_xv[x] = xv_spot;
initial_yv[x] = yv_spot;
initial_radius[x] = radius_spot;
}
}
double BallPit::draw(Canvas &canvas)
{
for(unsigned int y = 0; y < ballpit; y++)
{
ball.SetX(initial_x[y]);
ball.SetY(initial_y[y]);
ball.SetVX(initial_xv[y]);
ball.SetVY(initial_xy[y]);
ball.SetRadius(initial_radius[y]);
ball.Draw(Canvas &canvas);
}
}
##################################################################################
Thank you in advance for any help.
AJ