Hi everyone,
I'm new to C++/Object Oriented Programming and would like some guidance. I am currently working on a program that will solve physics problems using the kinematic equations.
I'm having issues sorting out the OOP part. i currently have acceleration, velocity, displacement, and time in their own individual classes. i also have a kinematics class which is where i thought i'd put the equations that will perform the calculations and return unknown variable(s). I'm not sure if this is how OOP works though.
As far as i know, OOP focus is on data and operations on the data. In the past i had a class and member functions that operate on that piece of data. now I'm not sure how to write my program :/
I was also thinking that maybe i could list my equations as friend functions.
(FORGIVE MY IGNORANCE, THIS IS MY FIRST MONTH WITH C++,OOP).
here are some snippets of header files to give everyone an idea of what i had in mind.
Code:
#ifndef Velocity_hpp
#define Velocity_hpp
#include <iostream>
using namespace std;
class Velocity
{
double velocity;
public:
//constructors
Velocity();
Velocity(double v);
//deconstructor
~Velocity();
//mutator functions
void setVelocity(double v);
//accessor functions
double getVelocity();
//friend
friend ostream& operator<<(ostream& out_stream, const Velocity &velocity);
};
#endif
Code:
#ifndef Time_hpp
#define Time_hpp
#include <iostream>
using namespace std;
class Time
{
double time;
public:
//constructors
Time();
Time(double t);
//deconstructor
~Time();
//mutator functions
void setTime(double t);
//accessor functions
double getTime();
//friend
friend ostream& operator<<(ostream& out_stream, const Time &time);
};
#endif
Code:
#ifndef Displacement_hpp
#define Displacement_hpp
#include <iostream>
using namespace std;
class Displacement
{
double displacement;
public:
//constructors
Displacement();
Displacement(double s);
//deconstructor
~Displacement();
//mutator functions
void setDisplacement(double s);
//accessor functions
double getDisplacement();
//friend
friend ostream& operator<<(ostream& out_stream, const Displacement &displacement);
};
#endif
Code:
#ifndef Acceleration_hpp
#define Acceleration_hpp
#include <iostream>
using namespace std;
class Acceleration
{
double acceleration;
static const double gravity = 9.83;
public:
//constructors
Acceleration();
Acceleration(double a);
//deconstructor
~Acceleration();
//mutator functions
void setAcceleration(double a);
//accessor functions
double getAcceleration();
double getGravity();
//friend
friend ostream& operator<<(ostream& out_stream, const Acceleration &acceleration);
};
#endif
Code:
#ifndef Kinematics_hpp
#define Kinematics_hpp
#include <iostream>
#include "mainprj.hpp"
#include "Acceleration.hpp"
#include "Displacement.hpp"
#include "Kinematics.hpp"
#include "Time.hpp"
using namespace std;
#endif
as you can see i have no functions in my kinematics class yet.. this is because I'm not so sure this is how i should implement my program. some requirements for this program are that it must be OOP, have function overrides, overloads, and other C++ material that could not be done in C.
ANY HELP/ADVICE WOULD BE GREATLY APPRECIATED.