//Projectile.h
#include<iostream>
#include<string>
using namespace std;
#pragma once
class Projectile
{
public:
Projectile();
Projectile(float m_x, float m_y);
string m_name;
float m_x, m_y, m_angle, m_speed;
void setName(string n);
string getName();
void setX(float x);
float getX();
void setY(float y);
float getY();
void setAngle(float angle);
void updatePosition(int time);
void setSpeed(float speed);
}
//mainprog.cpp
#include<iostream>
#include "Projectile.h"
#include "math.h"
using namespace std;
void main()
{
Projectile p[3];
float angle, speed;
int i;
string n;
for(i = 0; i < 3; i++)
{
cout << "\nEnter name of Projectile " << i+1 << ": " << endl;
cin >> n;
p.setName(n);
cout << "\nEnter Angle of Projectile " << i+1 << ": " << endl;
cin >> angle;
p.setAngle(angle);
cout << "\nEnter initial speed of Projectile " << i+1 << ": " << endl;
cin >> speed;
p.setSpeed(speed);
}
}
//Projectile.cpp
#include<iostream>
#include<string>
#include "Projectile.h"
void Projectile:setName(string n){
m_name = n;
};
string Projectile::getName(){
return m_name;
};
void Projectile::setX(float x){
m_x = x;
};
float Projectile::getX(){
return m_x;
};
void Projectile::setY(float y){
m_y = y;
};
float Projectile::getY(){
return m_y;
};
void Projectile::setAngle(float angle){
m_angle = angle*3.14159/180;
};
void Projectile::updatePosition(int time){
m_x = cos(m_angle)*m_speed*time;
m_y = sin(m_angle)*m_speed*time-0.5*9.81*time*time;
};
void Projectile::setSpeed(float speed){
m_speed = speed;
};
Hi,
I am trying to get this Projectile Motion thing working for some work I have to do. I have another piece of work coming up that requires that this be finished so if I don't get this working then I am screwed
The code above keeps spitting out error C2628: 'Projectile' followed by 'void' is illegal (did you forget a ';'?) for projectile.cpp Line 8 and error C2556: 'Projectile Projectile::setName(std::string)' : overloaded function differs only by return type from 'void Projectile::setName(std::string)' for projectile.cpp Line 8.
I have been staring at it for a while and I am still not seeing the problem (It;s 7:44 am o.o).
Any help would be appreciated.
Cheers,
Chris