C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 4th, 2007, 01:25 AM
lino lino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 lino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 17 sec
Reputation Power: 0
Urgent Help Costas if your there

Hi,

Help assignment

Last edited by lino : May 8th, 2007 at 05:15 AM. Reason: Wrong

Reply With Quote
  #2  
Old May 4th, 2007, 02:53 AM
nosale nosale is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 110 nosale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 23 m 10 sec
Reputation Power: 11
Here's a quick and dirty (non "modular") solution... It doesn't quite do everything you need it to, but it should give you a good idea of what to do. I trust you wont use this code for you assignment as it is considered plagiarism and academic misconduct (i.e. pls don't just submit this code).

Code:
#include <iostream>
#include <math.h>
using namespace std;

#define BUFF_X 50
#define BUFF_Y 25
#define MAX_X 1050.0
#define MAX_Y 525.0

int main() {

  const double g = 9.81;
  double projX, projY;   //projectile's current position
  double vX, vY;         //projectile's current velocity
  double dt = 1.0/100.0; //time step
  double velocity;
  double angle;
  double hangTime;
  int nSteps;            //number of time steps needed
  char imgBuffer[BUFF_X][BUFF_Y];
  for(int i = 0; i < BUFF_X; i++)
    for(int j = 0; j < BUFF_Y; j++) 
      imgBuffer[i][j] = '~';

  cout << "Enter initial velocity: ";
  cin >> velocity;
  cout << "Enter launch angle: ";
  cin >> angle;

  angle = angle*M_PI/180.0;  //convert degrees to radians
  vX = velocity*cos(angle);
  vY = velocity*sin(angle);
  hangTime = 2*vY/g;         //the time that the projectile will spend in the air.
  nSteps = (int)(hangTime/dt+0.5);

  for(int i = 0; i < nSteps; i++) {
    projX += vX*dt;
    projY += vY*dt;
    vY -= g*dt;
    if(!(i%100)) {
      cout << projX << "   "<< projY << endl;
      imgBuffer[(int)((projX/MAX_X)*BUFF_X)][(int)((projY/MAX_Y)*BUFF_Y)] = '*';
    }
  }
  for(int j = BUFF_Y-1; j >= 0; j--) {
    for(int i = 0; i < BUFF_X; i++) 
      cout << imgBuffer[i][j];
    cout << endl;
  }
}

Reply With Quote
  #3  
Old May 4th, 2007, 06:19 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
hey Lino... i'm really flattered.... i'm looking at it now... i'll inform you as soon as i find something...
__________________
www.tosc.gr - Greek site with free programs to make your life easier
www.friendgr.gr - new torrent tracker - supports english...
Costas

Reply With Quote
  #4  
Old May 4th, 2007, 08:40 AM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
well, i've done something.... here it is...
C++ Code:
Original - C++ Code
  1.  
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. double v, vx, vy, t, x, y, tol;
  7. const double g = 9.8;
  8. double angle;
  9. const double pi = 3.141592653589793238462643383279502884197169399375  10;
  10.  
  11. int calculate(double time);
  12.  
  13. int main()
  14. {
  15.     cout<<"Give me the velocity: ";
  16.     cin>>v;
  17.     cout<<"Give me the angle: ";
  18.     cin>>angle;
  19.     angle = angle*pi/180.0; //convert angle from degrees to radians
  20.     vx = v*cos(angle); //calculate the vx speed which doesn't change
  21.     vy = v*sin(angle); //calculate the vy speed
  22.     x=0;
  23.     y=0;
  24.     tol = vy/g; //calculate total time of movement
  25.     //cout<<tol<<endl<<endl;
  26.     //cout<<2*pow(vy,2.0)/(2*g)<<endl;
  27.     //cout<<vx<<" "<<vy<<" "<<tol<<endl<<endl;
  28.     for(double i=0.0;i<tol;i+=0.001)
  29.     {
  30.         calculate(0.001); //update for 0.001 sec
  31.     }
  32.     //cout<<"x: "<<x<<" y: "<<y<<endl;
  33.     cin>>y;
  34.     return(0);
  35. }
  36.  
  37. int calculate(double time)
  38. {
  39.     x += vx*time; //calculate x pos
  40.     vy -= g*time; //calculate vy
  41.     y = vy*time - g*pow(time,2.0)/2; //find the new y pos
  42.     return(0);
  43. }


this prog calculates the x and y position of the mass moving and its vy velocity for each time part (0.001 sec)... hope I helped... i haven't written an output function... try it yourself... i'll try it too... hope I helped...

oh and it works for me... I mean if the functions you gave are right it works just fine(you know the vx, vy and how to calculate them..)...

Last edited by costas : May 4th, 2007 at 08:43 AM.

Reply With Quote
  #5  
Old May 4th, 2007, 11:43 AM
nosale nosale is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 110 nosale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 23 m 10 sec
Reputation Power: 11
Hey Costas,

Our solutions look pretty similar except for two differences. I'll justify my reasons for doing what I did, and maybe you can do the same so that we can make sure we get the right solution.

1) hangTime or tol for you is half of what I have. The equation for the height at time t is given by h = ut - 0.5gt^2 (which is the correct formula). So, when h = 0, we have the time that the object spent in the air:

=> 0 = ut - 0.5gt^2
=> 0 = t(u - 0.5gt)
=> t = 0, u - 0.5gt = 0 => t = 2u/g


the first solution t = 0 is the trivial one (at time zero, the height is obviously zero) and the second is the time it takes for the object to return back to the ground.

2) When calculating the y position, I simply used
Code:
projY += vy*dt;

The other forumla (h = ut- 0.5gt^2) is used for computing the height of the object at time t given an initial upward velocity u, where u does not change. I added this line inside the for loop of my code to verify the fact:
Code:
 double calcY = velocity*sin(angle)*(i*dt) - 0.5*g*(i*i*dt*dt);

and compared calcY with projY (which agree).

Other than that, the rest looks the same Lemme know if you think i'm wrong.

EZ-E

Reply With Quote
  #6  
Old May 4th, 2007, 12:59 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
well as for the 1st one... you're wrong... and I'll tell you why... in school (yes i'm going in high school) we have a teacher who's the best in town and he's told us that when we have a movement with the velocity decreasing steadily by a power the time to stop is: tol = v0/g where v0 is the velocity at time=0.... and here's how it is:
v = v0 - at (v = velocity, v0 = the first velocity, a = acceleration) <=>
0 = v0 - at <=>
at = v0 <=>
t = v0/a


now as for the 2nd... i think we're both correct.... well i mean that with the y variable i had i wanted to calculate the height.... and with the ProjY you had you wanted to calculate the y position....

that was it....

Reply With Quote
  #7  
Old May 4th, 2007, 01:19 PM
lino lino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 lino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 17 sec
Reputation Power: 0
Confused

costas..

Your out put screens are nothing like what I am supposed to get... Please forward your e mail address so I can send you the outputs that are expected..

Reply With Quote
  #8  
Old May 4th, 2007, 01:29 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
ok.......

Reply With Quote
  #9  
Old May 4th, 2007, 02:03 PM
lino lino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 lino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 17 sec
Reputation Power: 0
Quote:
Originally Posted by costas
ok.......


I cant forward you the screen setting..
Can you please set up an e mail address for me to send you the copy of screen layout.

Reply With Quote
  #10  
Old May 4th, 2007, 02:06 PM
nosale nosale is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 110 nosale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 23 m 10 sec
Reputation Power: 11
Lino and Costas:

Well, I was trying to be civil bout this one... but since the gloves are off....
Quote:
Your out put screens are nothing like what I am supposed to get... Please forward your e mail address so I can send you the outputs that are expected..

That is because Costas solution is incorrect. Having a "little bit" more than a high school education, I think i may know a thing or two...
Quote:
v = v0 - at (v = velocity, v0 = the first velocity, a = acceleration) <=>
0 = v0 - at <=>
at = v0 <=>
t = v0/a

is correct... except you are calculating when your velocity is zero. When is the velocity zero? At the apex of the trajectory (i.e. at the highest point of the path of travel). That is where the velocity goes from positive (upward motion) to negative (downward motion). So if it takes v0/a time to get to that point, then it must take 2*v0/a to make it back to the ground. You don't have to take my word for it...
Reference: http://en.wikibooks.org/wiki/High_s...ojectile_motion

Secondly, what you did to compute the vertical height and what I did are completely different. The equations for computing the position:
x = vx*dt
y = vy*dt

are clearly first order linear approximations the actual equations of motion (calculus, which you may have learned already). As I said earlier, the equation
h = ut - 0.5*gt^2
computes the height of the projectile at time t for given initial (FIXED) vertical velocity u. So, if you want to use this equation for computing the height of the projectile, you can not modify u (your vertical velocity)... which you do. It is evident that the point of this exercise is to demonstrate numerical simulations of real life events, and accordingly you should be using the approximation to calculate the vertical height (see my code).

Finally,
Quote:
well as for the 1st one... you're wrong... and I'll tell you why... in school (yes i'm going in high school) we have a teacher who's the best in town and he's told us that when we have a movement with the velocity decreasing steadily by a power the time to stop is: tol = v0/g where v0 is the velocity at time=0.... and here's how it is:

Civility is key to getting anywhere in life. Well, I guess if you're always right then you don't have to be civil. I don't doubt that your teacher is amongst the best in the world. However, your application of the things you learned from your teacher was wrong - knowing something and using it properly are two entirely different things. Hope you take something away from this.

EZ-E

Reply With Quote
  #11  
Old May 4th, 2007, 02:32 PM
lino lino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 lino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 17 sec
Reputation Power: 0
Help

Hi

Cant you please just help someone in need... Please assist me in this assignment...

I need the program written correctly with the specified screens..

If you pass on an e mail address I can send you all instructions.. Please I am not good at this as you can see,

Please respond.

Reply With Quote
  #12  
Old May 4th, 2007, 02:34 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
you're just right man.... sorry for being selfish.... i'll try to think first a little more before answering or saying something... oh and be sure that i took MUCH away from your post... thnx....

oh and our teacher is the best... i'm the one being stupid....

Reply With Quote
  #13  
Old May 4th, 2007, 02:36 PM
lino lino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 lino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 17 sec
Reputation Power: 0
Help

Please someone help me...

Reply With Quote
  #14  
Old May 4th, 2007, 02:38 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
hey lino... try nosale's code.... try to mix mine too.... hey and not expect the program written and ready to hand it over to your teacher... you must do something yourself...

Reply With Quote
  #15  
Old May 4th, 2007, 02:40 PM
lino lino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 lino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 17 sec
Reputation Power: 0
I am getting these errors... And cant fix

C:\Documents and Settings\Lino Crino\Desktop\Cpp1.cpp(23) : error C2086: 'i' : redefinition
C:\Documents and Settings\Lino Crino\Desktop\Cpp1.cpp(38) : error C2086: 'i' : redefinition
C:\Documents and Settings\Lino Crino\Desktop\Cpp1.cpp(52) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.

Reply With Quote
  #16  
Old May 4th, 2007, 02:44 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
oh get rid of the int before the main function and put void....

oh and nosale... i think that the height is given by: h = vyt - 0.5*gt^2... am I right or not??

Last edited by costas : May 4th, 2007 at 02:46 PM.

Reply With Quote
  #17  
Old May 4th, 2007, 02:46 PM
lino lino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 lino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 17 sec
Reputation Power: 0
Can soneone please forward an e mail address so I can send what is expected... I really need this to pass this course..

PLEASE

Reply With Quote
  #18  
Old May 4th, 2007, 02:57 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
i've private sent my email to you...

Last edited by costas : May 4th, 2007 at 03:01 PM.

Reply With Quote
  #19  
Old May 4th, 2007, 03:06 PM
lino lino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 lino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 17 sec
Reputation Power: 0
Costas...

I dont know how to chech the private send...

Please go to hotmia...

User: programing.c@hotmail.com
Password: 123456

All assignment details are there..

Please help me.

Reply With Quote
  #20  
Old May 4th, 2007, 03:08 PM
costas costas is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 407 costas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 3 h 25 m 24 sec
Reputation Power: 12
hey lino.... don't just give us your email and password... my email is chatz_thrilos@hotmail.com...

Reply With Quote
  #21  
Old May 4th, 2007, 10:16 PM
lino lino is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 11 lino User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 17 sec
Reputation Power: 0
Help

Hey,

I have given all details for the assignment... Can you please help,

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Urgent Help Costas if your there


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap