d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > ~* Iso Programming Hw Help *~ > Will Pay Fg For Help
Add Reply New Topic New Poll
Member
Posts: 9,330
Joined: Oct 2 2006
Gold: 0.00
Sep 25 2013 02:20pm
I have plenty fg wil pay for good help thanks
ill take any help I can get and pm if u can do it all lol

This is a programming in C class

This is my assignment
Description:

Create a C program that reads in a stream of integer pairs,
each representing an (x,y) pair in the cartesian coordinate
system. For each successive pair of integers, display the
distance and direction traveled from one pair to the next.

You can assume that in each successive pair only one value
changes, so that travel is always right, left, up, or down.

{This would be like the locations displayed in the tracker.c
example from the "Conditional Statements" section in
Polzin's online notes (the x, y values.) }

Also, keep a running total of the distance between each pair
of points and determine the distance between the
initial/starting point and the final/finish point.

This is what I got so far.


#include <stdio.h>
#include <stdlib.h>
int main ()
{
int x, y;
int b=2;
int a;
printf(" How many different Coordinates: ");
scanf("%d",&a);
int array[a][b];
for(y = 0; y <= a-1; y++)
{
printf("Enter points: ");
for(x = 0; x <= b-1; x++)
scanf("%d", &array[x][y]);
}
printf("\n");
for(x = 0; x <= b-1; x++)
{
for(y = 0; y <= a-1; y++)
printf("[%d][%d]=%2d ", x, y, array[x][y]); //Just to show what the array is holding.
printf("\n");
}

So basically I have the array but now how do I use the array to calculate the distance between points and keep a running total??
Banned
Posts: 4,377
Joined: Dec 25 2012
Gold: 13,953.01
Warn: 10%
Sep 25 2013 02:57pm
declare distanceTotal (a double) in the beginning of main

create a distance method

double distance(int x1, int y1, int x2, int y2 )
{
return abs(x1-x2) + abs(y1-y2) //since only x or y is changing
}


create a direction method (or you can make one method for both functions where the distance and direction are returned into pointers passed as parameters

(idk what type you want this to return) direction(int x1, int y1, int x2, int y2)
{
if x1 == x2
{
if y2 > y1
return //something for up
return //something for down
}
if x2 > x1
return //something for right
return soething for left
}


}


Call distance in a loop in your main that loops through all the points shy of the last one like so

distanceTotal += distance(parameters)
also call direction

then call distance(firstPoint, lastPoint) for the final distance
Member
Posts: 17,861
Joined: Apr 4 2012
Gold: 59.31
Sep 29 2013 07:15pm
good luck on finding your answer.!!!
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Sep 30 2013 06:55am
Code
from math import sqrt

User_Entered_Coords = []

def GetUserCoords():
temp_coords = raw_input('Type your coordinates in the form: x,y then press ENTER, to quit press ENTER on blank line\n')
if temp_coords=="":
return False
coords = temp_coords.split(",")
User_Entered_Coords.append([int(coords[0]), int(coords[1])])
return True

def TotalDistance():
distance = 0
for i,entry in enumerate(User_Entered_Coords):
if i == 0:
pass
else:
distance += sqrt((User_Entered_Coords[i-1][0]-User_Entered_Coords[i][0])**2 + (User_Entered_Coords[i-1][1]-User_Entered_Coords[i][1])**2)
return str(distance)

while True:
if GetUserCoords() == False:
break
print "You have travelled " + TotalDistance() +"\n--------------------"

print "--------------------\n--------------------\nYour TOTAL distance travelled was " + TotalDistance() +"\n--------------------\n--------------------"


a quick and dirty example I wrote in python
Banned
Posts: 4,377
Joined: Dec 25 2012
Gold: 13,953.01
Warn: 10%
Sep 30 2013 07:48am
I think he finished this already. Not sure why imp bumped.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 30 2013 05:05pm
Quote (zackill4 @ Sep 30 2013 09:48am)
I think he finished this already. Not sure why imp bumped.


he's just spamming to get his post count up. he did it to dozens of other topics
Go Back To Homework Help Topic List
Add Reply New Topic New Poll