Hi everyone, I've got this assignment that I been stuck on for days. I've already tried to google some answers and asking friends but that haven't helped. Please help me, even one line is helpful.
The assignment:
One part of a bigger game is that the player should roll out balls at a certain speed from one
trampoline. When the ball leaves the trampoline, it continues at the same speed in
horizontal axis (x-axis) while, due to gravity, it accelerates downwards
(Y-axis). This results in the ball describing a path called a parable.
You can totally ignore the air resistance to which the ball is exposed.
For example, to see a clip describing the movement, you can look at, fast forward too 3:47 in th clip
https://www.youtube.com/watch?v=EulXDXc73QE
The horizontal velocity, for example, is unchanged throughout the movement.
The vertical speed view is accelerated downward and the speed at a certain time
is given by
vy = 9.82 * time
The total velocity is the result of vx and view. Use Pythagoras rate.
The time is specified in seconds and the speed in meters per second.
Class Ball
Through this system there should be the opportunity to create a ball by entering the horizontal speed of the ball's center is just has when it leaves the trampoline.
Furthermore, for a ball it should be possible to:
• Obtain the horizontal speed
• Obtain vertical speed for a certain time after leaving the trampoline
• Obtain total speed for a certain time after leaving the trampoline
• Obtain a string containing horizontal velocity, vertical velocity as well
total speed a certain time after leaving the trampoline
• Compare with another ball using the > operator.
In this case > the horizontal speed is bigger
• Compare with another ball using the == operator.
In this case == mean that the horizontal speed is equal
Requirements for implementation of the Ball class:
1. The class Ball should be divided into a header (.h) and a definition file (.cpp).
There must be no function definitions in the header file
2. Inclusion of the header, containing the declaration of the class for Ball, shall
work even if this happens from "multiple directions"
3. Hard encapsulation should be used
4. Member functions that may be constant should be constant
5. Parameters that should be constant should be constant
The test program
In the test program (TestBall.cpp), the following must be done in turn (not menu-driven):
1. Create a dynamically assigned array containing 4 "default" balls
2. Add 4 "real" balls to positions 0 to 3 in the array above.
The values for the horizontal speeds are read from a text file (balls.txt)
which you have created
3. Expand the 3-position array
4. Add another ball. Check is made that the same ball is not entered
more than once using the == operator.
Test by adding a ball already, partly by adding a ball that is not already available
5. Show horizontal, vertical and total speed for all non-default balls
6. Remove a ball of user-entered values at horizontal speed. If the ball is not available, this should be announced
7. Show horizontal, vertical and total speed for all non-default balls
8. View the total speed of all non-default balls at one of the users entered time
9. Sort all "non-default" balls falling based on the balls horizontal speed. Here's is the usage of the > operator
10. Show horizontal, vertical and total speed for all non-default balls
Test Program Requirements:
1. Variables may not be declared out of function
2. Any constants are declared globally advantageous
3. Separate subproblems are handled in separate functions
• Add balls from text file
• Add a ball "manually"
• Show all balls
• Remove a ball
• View the total speed of all balls at a certain time
• Sort
• Expand the array can, but must not, be done in a separate function
The above functions should be divided into prototype and definition
4. The solution should contain relevant examples of both implicit and explicit call-by-reference as well as call-by-value
5. There must be no "cavities" in the array after removal, ie all
ball objects that are registered must always be located from position 0 and forward
6. The sorting should be implemented by you, ie you may not use
finished sorting features. No input or output may be performed in this function
7. The program must not generate memory leaks
Other information:
You can assume that no incorrect entries are made, such as that the user is feeding
in a string at integer input
You can't use break (except in connection with switch/case),
continuous, multiple return or goto in the solution!
You must submit the following files:
* Ball.h
* Ball.cpp
* TestBall.cpp
* balls.txt
my codes so far, P.S there's a lot of unfinished coding
The header file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#pragma once
#include <string>
using namespace std;
class Ball
{
private:
int speedX;
int speedY;
public:
Ball(int speedX, int speedY);
Ball();
int getSpeedX();
int getSpeedY();
/*{
this->x = x;
this->y = y;
}*/
};
|
The test cpp. file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include "Ball.h"
using namespace std;
const double vy = 9.82;
int main()
{
int capacity = -1;
Ball = ballArray = nullptr;
ballArray = now Ball[capacity];
int nrOfBalls = 0;
int time = 0;
fillBallDef(ballArray, nrOfBalls, capacity);
for (int i = 0; i < capacity; i++)
{
cout << ballArray[i].toString(time) << endl;
}
cout << "How long time has the balls been traveling?: " << endl;
cin >> time;
cin.ignore();
showAll(ballArray, nrOfBalls, capacity, time);
capacity = capacity + 3;
Balls = tempBallArray = new Balls[capacity];
for (int i = 0; i < nrOfBalls; i++)
{
tempBallArray[i] = ballArray[i];
}
delete[] ballArray;
ballArray = tempBallArray;
system("pause");
return 0;
}
|
The cpp. file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include "Ball.h"
#include <cmath>
Ball::Ball(double speedX)
{
this->speedX = speedX;
}
Ball::Ball()
{
this->speedX = -1;
}
int Ball::getSpeedX() const
{
return this->speedX;
}
double Ball::getSpeedY(int travelTime+acceleration)
{
return travelTime+acceleration;
}
double Ball::get
{
return
}
|
thank you for your time!