Falling parachuter

This is my first time using classes so I am having a bit of trouble. I don't know what these error messages I'm getting are trying to say. I have cleaned up a lot of my earlier errors, these few I'm just unsure about. I have got the program working one way. But we are supposed to use less lines of code in the main() part of the program. So I have tried to give the class more to do. I am really stuck so any little bit would help. I imagine there are still bugs to work out, I just want to figure out these error messages for now.

This is a screen shot of how it should work.
http://i27.photobucket.com/albums/c163/TaylorSanchez/cplusplus/parachuter.png
My errors are:
g++ parachutist_5.cpp -o para5 ccc_x11.cpp ccc_shap.cpp -L /usr/X11R6/lib -lX11
parachutist_5.cpp: In constructor ‘Parachutist::Parachutist(int, int, int)’:
parachutist_5.cpp:46: error: ‘speed’ was not declared in this scope
parachutist_5.cpp:47: error: invalid use of member (did you forget the ‘&’ ?)
parachutist_5.cpp: In member function ‘void Parachutist::move_closed(int, int)’:
parachutist_5.cpp:55: error: ‘speed’ was not declared in this scope
parachutist_5.cpp: In member function ‘void Parachutist::display()’:
parachutist_5.cpp:79: error: invalid use of member (did you forget the ‘&’ ?)
parachutist_5.cpp:82: error: invalid use of member (did you forget the ‘&’ ?)
ccc_x11.cpp: In function ‘int main(int, char**)’:
ccc_x11.cpp:429: warning: deprecated conversion from string constant to ‘char*’
ccc_x11.cpp:498: warning: deprecated conversion from string constant to ‘char*’

I figure a few are interconnected. Like the speed that reappears. I thought it was declared correctly, but I don't understand classes completely. We were given a skeleton to build from, which I trashed most of it since I didn't like the layout.

My code is:
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//Parachutist
//Taylor Sanchez
//This should be a class that you input speed of a plane and how many seconds to wait until pulling
// a parachute, from there it will simulate from there.

//Upon closer inspection of the directions, I think I need to change what type of inputs come from the main program.

#include "ccc_win.h"
using namespace std;
class Parachutist 
{
public:
  Parachutist();
  Parachutist(int, int, int);  
  void pull();      
  void move(int dx, int dy);
  void display();
private:
  Point man;
  int seconds;
  int y;
  int x;
  int dy;
  int dx;
  int r;
  void move_closed(int, int);
  void display_closed();
  void move_open(int,int);
  void display_open();
};
Parachutist::Parachutist()
{
    int pull = 6;           //seconds until parachute pulled
    int speed = 150;        //speed of plane jumped from
    int seconds = 0;  //constant              //seconds falling in program
    int dy = 0;       //constant              //change in y   (acceleration/deceleration to ground)
    int dx = 0;       //constant              //change in x   (drag factor)
    int x = 100;    
    int y = 950;
    man= Point (x,y);
    int r=10;
  
}
Parachutist::Parachutist(int s, int p, int height)
{
    speed = s;  //refer to main() currently is 150 ft/sec
    pull = p;   //refer to main() currently is after 8 sec
    y = height;
}

void Parachutist::move_closed(int dx, int dy)
{
      //p.move(dx,dy);
      dy = 32 * seconds;
      dx = speed;
                //line for if slowing down after jump, we assume he isnt //dx = dx - 5*seconds;
      if(dy > 174) {dy = 174;}
      y = y - dy;
      Message xy(Point (x,y), dx);
      cwin<<xy;   
      x = x + dx;
      seconds = seconds + 1;
}
void Parachutist::move_open(int dx, int dy)
{     
      dy = dy - (100 * seconds);
      dx = dx - 20;
      if(dx <= 0) {dx = 0;}
      if(dy <= 17) {dy = 17;}
      y = y - dy;
      Message xy(Point (x,y), dx);
      cwin<<xy;   
      x = x + dx;
      seconds = seconds + 1;
}

void Parachutist::display()
{
  if (seconds<pull)
    void move_closed(int,int);
    display_closed();
  if (seconds>=pull)
    void move_open(int,int);
    display_open();
}

void Parachutist::display_closed()
  {
  Point h(x,y);       //Center Point  //h for head
  Circle c(h,r);      //circle p
  cwin << c;
  //body 
  Point b1(x,y-r);                  //neck connection
  Point b2(x,y-(4*r));              //end of body  Body and head will be same size?
  cwin << Line(b1,b2);  
  //Legs
  Point l1(x+((0.5)*r),y-(5.5*r)); //trying to make proportional, again may need to do math seperately
  Point l2(x-((0.5)*r),y-(5.5*r)); //
  cwin << Line(b2,l1) << Line(b2,l2);  
  //Arms
  Point c1(x,y-(3*r));              // midpoint to connect arms
  Point a1(x+(r),y-(1.5*r));        //arm
  Point a2(x-(r),y-(1.5*r));        //arm
  cwin << Line (c1,a1) << Line (c1,a2);
  if (y>0){Parachutist::display();}
  }
void Parachutist::display_open()
  {
  Point h(x,y);       //Center Point  //h for head
  Circle c(h,r);      //circle p
  cwin << c;
  //body 
  Point b1(x,y-r);                  //neck connection
  Point b2(x,y-(4*r));              //end of body  Body and head will be same size?
  cwin << Line(b1,b2);
  //Legs
  Point l1(x+((0.5)*r),y-(5.5*r)); //trying to make proportional, again may need to do math seperately
  Point l2(x-((0.5)*r),y-(5.5*r)); //
  cwin << Line(b2,l1) << Line(b2,l2);
  //Arms
  Point c1(x,y-(3*r));              // midpoint to connect arms
  Point a1(x+(r),y-(1.5*r));        //arm
  Point a2(x-(r),y-(1.5*r));        //arm
  cwin << Line (c1,a1) << Line (c1,a2);
  //parachute
  Point c2(x,y-(2*r));                   //connection point for parachute
  Point s1(x-(3*r),y+(3*r));             //string
  Point s2(x+(3*r),y+(3*r));             //string
  Point p3(x+(2*r),y+(4*r));
  Point p2(x,y+(5*r));
  Point p1(x-(2*r),y+(4*r));
  //connect the dots
  cwin << Line(c2,s1) << Line (c2,s2) << Line(s1,s2) << Line(s1,p1) << Line(s2,p3) <<Line(p1,p2) <<Line  (p3,p2);
  if (y>0){Parachutist::display();}
  }


int ccc_win_main(){

    cwin.coord(0,1000,1000,0);
    Parachutist person1(150, 8,1000);  //speed of plane, seconds to pull chute, height of plane
    person1.display();
    
  return 1;
}
You are having scope problems and with functions
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
Parachutist::Parachutist() //this does nothing
{
    int pull = 6; //local variables
    int speed = 150;
    int seconds = 0; 
    int dy = 0; 
    int dx = 0; 
    int x = 100;    
    int y = 950;

}//local variables die
Parachutist::Parachutist(int s, int p, int height)
{
    speed = s;  //what is speed? 
    pull = p;    //the only pull that exists is a function, not an integer
    y = height;
}
void Parachutist::display()
{
  if (seconds<pull) //pull is a function that returns void so I don't understand what do you want
    void move_closed(int,int); //declaring a function?
    display_closed(); //this is actually outside the if 
  if (seconds>=pull)
    void move_open(int,int);
    display_open();
}

Ya lot of the syntax wasn't explained in my class. They expected us to know a lot of this, problem is last semester my teacher didn't speak English well so I didn't know half of what he said.

The if statements I tried to copy what is going on in this rocket program that we had for an example. I understand more of what I'm doing wrong, I should be able to piece more together.

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// File: rocket.cpp

#include "ccc_win.h"
using namespace std;
class Rocket
{
public:
  Rocket();  
  Rocket(Point loc);      
  void display() const; 
  void move(int dx, int dy);  
  void set_direction(string newdirection);  
private:
  Point llc; 
  string direction; 
  void displayup() const; 
  void displaydown() const; 
  void displayright()const; 
  void displayleft()const; 
};

Rocket::Rocket()
{
  llc = Point(0,0);
  direction="up";
}

Rocket::Rocket(Point loc)
{
  llc=loc;
  direction="up";
}

void Rocket:: move(int dx, int dy)
{
  llc.move(dx,dy);
}

void Rocket::set_direction(string newdirection)
{
  direction=newdirection;
}

void Rocket::display() const
{

  if (direction == "up")
    displayup();
  if (direction == "down")
    displaydown();
  if (direction == "right")
    displayright();
  if (direction == "left")
    displayleft();
}

void Rocket::displayup() const
{
Point p1(llc.get_x()+0,llc.get_y()+100);
Point p2(llc.get_x()+20,llc.get_y()+150);
Point p3(llc.get_x()+40,llc.get_y()+100);
Point p4(llc.get_x()+40,llc.get_y()+0);
cwin<<Line(llc,p1)<<Line(p1,p2)<<Line(p2,p3)<<Line(p3,p4)<<Line(p4,llc);
}


void Rocket::displaydown() const
{
Point p1(llc.get_x()+0,llc.get_y()-100);
Point p2(llc.get_x()+20,llc.get_y()-150);
Point p3(llc.get_x()+40,llc.get_y()-100);
Point p4(llc.get_x()+40,llc.get_y()+0);
cwin<<Line(llc,p1)<<Line(p1,p2)<<Line(p2,p3)<<Line(p3,p4)<<Line(p4,llc);
}

void Rocket::displayright() const
{
Point p1(llc.get_x()+0,llc.get_y()+40);
Point p2(llc.get_x()+100,llc.get_y()+40);
Point p3(llc.get_x()+150,llc.get_y()+20);
Point p4(llc.get_x()+100,llc.get_y()+0);
cwin<<Line(llc,p1)<<Line(p1,p2)<<Line(p2,p3)<<Line(p3,p4)<<Line(p4,llc);
}

void Rocket::displayleft() const
{
Point p1(llc.get_x()+0,llc.get_y()-40);
Point p2(llc.get_x()-100,llc.get_y()-40);
Point p3(llc.get_x()-150,llc.get_y()-20);
Point p4(llc.get_x()-100,llc.get_y()+0);
cwin<<Line(llc,p1)<<Line(p1,p2)<<Line(p2,p3)<<Line(p3,p4)<<Line(p4,llc);
}


int ccc_win_main()
{
   cwin.coord(0,4000,4000,0);
   Rocket usa1(Point(1000,10));
   usa1.display();
   usa2.display();

  for (int i = 0; i <= 4000; i+=500)
  {
 
      if (i>=1750)
      { 
          usa1.set_direction("left");       //Parachute person1(int speed, int pull)
          usa2.set_direction("right");
          usa1.move(-200,200);
          usa2.move(200,100);
      }
      else {
          usa1.move(0,i);
          usa2.move(0,i);
      }
      usa1.display();
      usa2.display();
  }
      
 

  return 1;
}






Below is the program that works btw. Just I shouldn't have so much under the int ccc_win_main()
I was attempting to integrate more of it into the class itself. I'm not too surprised that I did it way wrong. :) thanks for the tips.
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//Parachutist

#include "ccc_win.h"
using namespace std;
class Parachutist
{
public:
  Parachutist();  
  Parachutist(Point loc);      
  void display() const; 
  void move(int dx, int dy);
  void set_parachute(string newParachute);  
private:
  Point p;
  string parachute; 
  void noParachute() const;
  void Parachute() const;
};

Parachutist::Parachutist()
{
  p = Point(0,0);
  parachute= "no parachute";
}

Parachutist::Parachutist(Point loc)
{
  p=loc;
  parachute= "no parachute";
}

void Parachutist:: move(int dx, int dy)
{
  p.move(dx,dy);
}

void Parachutist::set_parachute(string newParachute)
{
  parachute=newParachute;
}

void Parachutist::display() const
{

  if (parachute == "no parachute")
    noParachute();
  if (parachute == "parachute")
    Parachute();
}

void Parachutist::noParachute() const{
  Point h1(p.get_x()+0,p.get_y()+0);
  Point b1(p.get_x()+0,p.get_y()-10);
  Point b2(p.get_x()+0,p.get_y()-(4*10));
  Point l1(p.get_x()+((0.5)*10),p.get_y()-(5.5*10));
  Point l2(p.get_x()-((0.5)*10),p.get_y()-(5.5*10));
  Point c1(p.get_x()+0,p.get_y()-(3*10));
  Point a1(p.get_x()+(10),p.get_y()-(1.5*10));
  Point a2(p.get_x()-(10),p.get_y()-(1.5*10));

  cwin << Circle(h1,10) << Line(b1,b2) << Line(b2,l1) << Line(b2,l2) << Line (c1,a1) << Line (c1,a2);
}

void Parachutist::Parachute() const{
  Point h1(p.get_x()+0,p.get_y()+0);
  Point b1(p.get_x()+0,p.get_y()-10);
  Point b2(p.get_x()+0,p.get_y()-(4*10));
  Point l1(p.get_x()+((0.5)*10),p.get_y()-(5.5*10));
  Point l2(p.get_x()-((0.5)*10),p.get_y()-(5.5*10));
  Point c1(p.get_x()+0,p.get_y()-(3*10));
  Point a1(p.get_x()+(10),p.get_y()-(1.5*10));
  Point a2(p.get_x()-(10),p.get_y()-(1.5*10));
  Point c2(p.get_x()+0,p.get_y()-(2*10));
  Point s1(p.get_x()-(3*10),p.get_y()+(3*10));
  Point s2(p.get_x()+(3*10),p.get_y()+(3*10));
  Point p3(p.get_x()+(2*10),p.get_y()+(4*10));
  Point p2(p.get_x()+0,p.get_y()+(5*10));
  Point p1(p.get_x()-(2*10),p.get_y()+(4*10));

  cwin << Circle(h1,10) << Line(b1,b2) << Line(b2,l1) << Line(b2,l2) << Line (c1,a1) << Line (c1,a2) << Line(c2,s1) << Line (c2,s2) << Line(s1,s2) << Line(s1,p1) << Line(s2,p3) <<Line(p1,p2) <<Line(p3,p2);
}



int ccc_win_main(){
  cwin.coord(0,1000,1000,0);
  
  
  int velocity = 0;
  int altitude = 950;
  int speed = 100;
  int drag = 0;
  int horizontal = 100;
  int seconds = 0; 
  
  while(altitude >= 0){

    Parachutist fall(Point(horizontal,altitude));
    

    seconds = seconds + 1;

    if(seconds <= 6){
      velocity = 32 * seconds;
      drag = speed;
      if(velocity > 174){
        velocity = 174;}
    }
    else if(seconds >= 7){
          
     fall.set_parachute("parachute");
      velocity = velocity - (100 * seconds);
      drag = drag - 20;
      if(drag <= 0){
        drag = 0;}
      if(velocity <= 17){
        velocity = 17;}
    }   

    altitude = altitude - velocity;
    horizontal = horizontal + drag;
    
    fall.display();
  }
  
  
  return 1;
}



I wish I could spoiler some of the above, so dang long. Just thought what I'm trying to do might make more sense.

I didn't mean to have a void pull();. I got rid of that.

I don't understand where I am supposed to declare my values for the whole class to be able to use them.

I thought this:
1
2
3
Parachutist::Parachutist() //this does nothing
{
    int pull = 6; //local variables  
Was my default constructor that declared values for rest of the class. Guess I misunderstood that part.

The whole part was supposed to be in the if statement, my bad. Problem with skeleton setups is I forget to add in syntax sometimes. I just declared a function there because the compiler seemed to want that, kept complaining about it, I got rid of the void now.
1
2
    void move_closed(int,int); //declaring a function?
    display_closed(); //this is actually outside the if   


The if statement is supposed to decide when they have pulled the shoot or not.
http://www.cplusplus.com/doc/tutorial/classes/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Parachutist 
{
public:
  Parachutist();
  Parachutist(int, int, int);  
  void pull();      
  void move(int dx, int dy);
  void display();
private:
  Point man; //here you declare the members of your class 
  int seconds; //you are saying that every Parachutist has got these variables (they are its state)
  int y;
  int x;
  int dy;
  int dx;
  int r;
  void move_closed(int, int);
  void display_closed();
  void move_open(int,int);
  void display_open();
};
Cool, that is actually where I moved them to. I don't get where I set the values though. I tried a line like
int seconds (void){return 0;}
Because I saw them do it this tutorial. Under overloading constructors. http://www.cplusplus.com/doc/tutorial/classes/
Would it be in this area that I set them?
1
2
3
Parachutist::Parachutist()
{
}



Edit{ Figured it out, (int dx, int dy) only needed to be (dx,dy). I don't know exactly why but I found it online. Now just to set my values so something happens. :) }
They did this in the rocket program I have for reference, so I don't understand why this doesn't work:
1
2
3
4
5
6
7
8
9
10
11
12
13
void Parachutist::display()
{
  if (seconds<pull)
    {
    void move_closed(int dx,int dy);
    display_closed();
    }
  if (seconds>=pull)
    {
    void move_open(int dx,int dy);
    display_open();
    }
}


It gives me an error of:
84: error: expected primary-expression before 'int'
84: error: expected primary-expression before 'int'
89: error: expected primary-expression before 'int'
89: error: expected primary-expression before 'int'

Those are actually the only errors I have left in my program. Hopefully it will compile if I fix those. Bugs expected and greeted atm, I just want this thing to compile.


... I know I'll look back on this and laugh that I didn't understand this. I'm not one who likes asking for help, I like to try and figure it out on my own. What you have helped with is very appreciated though.
Last edited on
Finished my code successfully. Probably looks a lot different in the way it functions. I pretty much trashed what I was doing and then just took pieces as I needed them.
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//Parachutist
//Taylor Sanchez
//Homework_1

//The stick figure is contructed from the center point for the head, and scaled off the radius. 
//if the size is changed the while statement must be changed to have him land directly on his feet. It should be radius*5
//default is a radius of 20. Which *6 gets me 120. Make sure to edit both r's under noParachute() and yesParachute()

#include "ccc_win.h"
using namespace std;
class Parachutist
{
public:
  Parachutist();                            //constructors
  Parachutist(Point loc);      
  void move(double pull, double speed);     //mutator
private:
  double changey;// = 0;       //deceleration factor   //change in y each second, due to gravity and parachute
  double changex;// = 0;       //drag factor           //change in x each second, due to drag
  double speed;
  double sec;
  double r;
  double x;
  double y;
  Point llc;
  void noParachute() const;                 //accessors
  void yesParachute() const;
};
Parachutist::Parachutist()
{
  llc = Point(0,0);
}
Parachutist::Parachutist(Point loc)
{
  llc=loc;
}

void Parachutist:: move(double pull, double speed)
{
  while (llc.get_y()>=120)          //it is so high because the scale of the person had to be large to look decent on the display. I wanted his feet to touch the ground, not his head which the point is based off of.
  {
  if(sec <pull)
    {
      sec++;
      noParachute();
      changey = 32*sec;                     //acceleration of falling object
      changex = speed;
      if(changey > 174) {changey = 174;}    //doesn't go over terminal velocity
      llc.move(changex,-changey);                      //change y's position  //change x's position
    }
    else if(sec >= pull)
    {
      sec++;
      yesParachute();
      changey = changey-(100 * sec);
      changex = changex-20;                 
      if(changex <= 0)  {changex = 0;}      //don't want them going backwards
      if(changey <= 17) {changey = 17;}     //Slowest parachute will slow them down.
      llc.move(changex,-changey);                      //change y's position  //change x's position
        
    }   
  } 
}
void Parachutist::noParachute() const{
    double r=20;
    double x=llc.get_x();
    double y=llc.get_y();
    //head
  Point h1(x+0,y+0);
    //body
  Point b1(x+0,y-r);
  Point b2(x+0,y-(4*r));
    //legs
  Point l1(x+((0.5)*r),y-(6*r));
  Point l2(x-((0.5)*r),y-(6*r));
    //arms
  Point c1(x+0,y-(2.0*r));
  Point a1(x+(r),y-(1.5*r));
  Point a2(x-(r),y-(1.5*r));
    //connect the dots
  cwin << Circle(h1,r) << Line(b1,b2) << Line(b2,l1) << Line(b2,l2) << Line (c1,a1) << Line (c1,a2);
}
void Parachutist::yesParachute() const{
    double r=20;
    double x=llc.get_x();
    double y=llc.get_y();
    //head
  Point h1(x+0,y+0);
    //body
  Point b1(x+0,y-r);
  Point b2(x+0,y-(4*r));
    //legs
  Point l1(x+(0.5*r),y-(6*r));
  Point l2(x-(0.5*r),y-(6*r));
    //arms
  Point c1(x+0,y-(3*r));
  Point a1(x+(r),y-(1.5*r));
  Point a2(x-(r),y-(1.5*r));
    //parachute
  Point c2(x+0,y-(2*r));
  Point s1(x-(3*r),y+(3*r));
  Point s2(x+(3*r),y+(3*r));
  Point s3(x+0,y+(3*r));
  Point p3(x+(2*r),y+(4*r));
  Point p2(x+0,y+(5*r));
  Point p1(x-(2*r),y+(4*r));
  
    //connect the dots
  cwin << Circle(h1,r) << Line(b1,b2) << Line(b2,l1) << Line(b2,l2) << Line (c1,a1) << Line (c1,a2) << Line(c2,s1) << Line (c2,s2) << Line(s1,s2) << Line(s1,p1) << Line(s2,p3) <<Line(p1,p2) <<Line(p3,p2) << Line(s3,p3) <<Line(s3,p2) <<Line(s3,p1);
}
int ccc_win_main(){
  double x = 50;            //starting point x coordinate
  double y = 1000;          //starting point y coordinate
  double speed = 100;       //plane speed
  double freefall = 6;      //seconds at which chute pulled (or freefall time)
  cwin.coord(0,1000,1200,-200);  
  {
    Parachutist man(Point(x,y));
    man.move(freefall,speed);
  }  
  Point g1(0,0);            //ground
  Point g2(10000,0);        //ground   
  cwin << Line(g1,g2);      // 
return 1;
}

Topic archived. No new replies allowed.