Help computer science? I tried all day and night.

Click For Summary

Discussion Overview

The discussion revolves around a homework problem related to a C++ program intended to simulate an acceleration field created by stars. The participant seeks help in identifying issues within their code, particularly focusing on error messages and function definitions.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • The initial poster shares their code and expresses frustration over not being able to identify the problem.
  • One participant suggests that the poster should provide specific error messages to facilitate assistance.
  • The poster mentions receiving an "undefined reference to draw_vector" error.
  • Another participant questions whether the prototype, usage, and definition of the draw_vector function match in terms of parameters.
  • The poster asserts that the prototypes and definitions are visible in the shared code.
  • A participant indicates that there is a mismatch in the expected parameter types, noting that an int is expected while a double is being passed.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the specific issue with the code. There is disagreement regarding the matching of function prototypes and definitions, with some participants suggesting that discrepancies exist while the poster maintains that they do not.

Contextual Notes

Participants have not fully resolved the issue, and the discussion remains focused on identifying the source of the error without a definitive conclusion.

PRAJOL
Messages
5
Reaction score
0

Homework Statement



What's wrong with code below? I tried all day and night...don't know what's wrong and how to change the code. Help anyone. I have uploaded picture of map which I have to make

http://www.portmain.com/intro/hw/hw05-field.html

Homework Equations


The Attempt at a Solution



//File: orbit.cxx
//Written by Suroj Lamichhane(suroj.lamichhane@colorado.edu)
//This program opens a large graphics window which simulates the
//the map of acceleration field created by 3 stars.

//Directives
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <graphics.h>

using namespace std;

//Named Constants
double const wmax= 2.5*pow(10.0,11.0);
double const G=6.67*pow(10.0, -11.0);
int const S=500;

// Prototypes
//These functions creates stars at a fixed locations and creates
// grids. It also changes world coordinates to pixel coordinate
// and makes vectors in acceleration field.
void draw_star(double wx,double wy,double radius,int color);
void draw_vector(double x, double y,double yellow_x,double
yellow_y,double yellow_m,
double blue_x,double blue_y,double blue_m,double red_x
,double red_y,double red_m);
int pixel(double wx, double w0, double w1, int p0, int p1);

double accx(double x, double y, double sx, double sy, double m);

double accy(double x, double y, double sx, double sy, double m);
int pixel(double wx, double w0, double w1, int p0, int p1);

//Function definitions:
//------------------------------------------------------------------------------
int main()

{
double x, y,yellow_x,yellow_y,yellow_m,
blue_x,blue_y,blue_m,red_x,red_y,red_m,wx,wy,radius,color;



initwindow(S,S,"Field of Dreams");
setfillstyle(SOLID_FILL, WHITE);
for (y=-wmax; y<wmax; y=y+(wmax/6))
{
for(x=-wmax;x<wmax;x=x+(wmax/6))
{

draw_vector(x, y,3.0*pow(10.0,10.0),-7.5*pow(10.0,10.0),2.5*pow(10.0,30.0),
-4.5*pow(10.0,10.0),3.0*pow(10.0,10.0),9.5*pow(10.0,30.0),4.5*pow(10.0,10.0),9.0*pow(10.0,10.0),1.5*pow(10.0,31.0));
//(3.0e10, -7.5e10)
//(-4.5e10, +3.0e10)
//(+4.5e10, +9.0e10)



}
draw_star(3.0*pow(10.0,10.0),-7.5*pow(10.0,10.0),5,14);
draw_star(-4.5*pow(10.0,10.0),3.0*pow(10.0,10.0),7,1);
draw_star(4.5*pow(10.0,10.0),9.0*pow(10.0,10.0),9,4);
}


delay(60000);

}
//------------------------------------------------------------------------------
void draw_star(double wx,double wy,double radius,int color)
{
int px=pixel( wx,-1.5, +1.5,0,S);
int py=pixel( wy,-1.5, +1.5,0,S);
setfillstyle(SOLID_FILL,color);
fillellipse(int(px),int(py), int(radius),int(radius));
setcolor(color);

}
//------------------------------------------------------------------------------

void draw_vector(int x, int y,double yellow_x,
double yellow_y,double yellow_m,
double blue_x,double blue_y,double blue_m,
double red_x,double red_y,double red_m)
{
double sx,sy;
yellow_x=accx(x,y,sx,sy,yellow_m);
blue_x =accx(x,y,sx,sy,blue_m);
red_x =accx(x,y,sx,sy,red_m);
yellow_y=accy(x,y,sx,sy,yellow_m);
blue_y =accy(x,y,sx,sy,blue_m);
red_y =accy(x,y,sx,sy,red_m);

int x1=int (yellow_x+blue_x+red_x);
int y1=int (yellow_y+blue_y+red_y);



double length=sqrt((((5.0*pow(10.0,10.0))*x1)*((5.0*pow(10.0,10.0))*x1))
+(((5.0*pow(10.0,10.0))*y1)*((5.0*pow(10.0,10.0))*y1)));
if (length<wmax/(7.07107))
{

line(x,y,x1,y1);
setfillstyle(SOLID_FILL,15);
fillellipse(x,y,2,2);

}}
//------------------------------------------------------------------------------
int pixel(double wx, double w0, double w1, int p0, int p1)
{
double px;



px=p0+((wx-w0)*(p1-p0)/(w1-w0));

return (int(px));
}
//------------------------------------------------------------------------------
double accx(double x, double y, double sx, double sy, double m)
{
double dx = (sx - x);
double dy = (sy - y);
double denominator = pow(dx*dx + dy*dy, 1.5);
return G*m*dx/denominator;
}
//------------------------------------------------------------------------------
double accy(double x, double y, double sx, double sy, double m)
{
double dx = (sx - x);
double dy = (sy - y);
double denominator = pow(dx*dx + dy*dy, 1.5);

return G*m*dy/denominator;

Homework Statement


Homework Equations


The Attempt at a Solution

 
Last edited by a moderator:
Physics news on Phys.org
Hi PRAJOL! [PLAIN]http://img96.imageshack.us/img96/5725/red5e5etimes5e5e45e5e25.gif

Perhaps you should point out what error messages you are generating, or what the program is or isn't doing, otherwise how is anyone to know what part to examine to help you https://www.physicsforums.com/images/icons/icon5.gif
 
Last edited by a moderator:
It says undefined reference to draw_vector.
 
Do your prototype, usage, and definition of draw_vector() match?
That is, do they all have the same parameters?
 
yes...you can see above
 
I'm afraid they don't...

Perhaps you should copy/paste them below each other to see the difference.
 
Where it expects an int you are passing a double.