Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: whitewidow on December 16, 2003, 05:29 AM

Title: can any 1 help me
Post by: whitewidow on December 16, 2003, 05:29 AM
can any 1 help me with a c++ program that i need for a module that i am studying.

this is a link to get the excercise.

http://www.brunel.ac.uk/~eestcjb/EE1063/Exercise4.doc

thank u
Title: Re:can any 1 help me
Post by: iago on December 16, 2003, 05:33 AM
That's fairly easy.. what exactly are you having a problem with?
Title: Re:can any 1 help me
Post by: whitewidow on December 16, 2003, 05:45 AM
the program its self
i cant do it.

Title: Re:can any 1 help me
Post by: whitewidow on December 16, 2003, 07:06 AM
is there no one that can help me with it


please some one help me
Title: Re:can any 1 help me
Post by: Kp on December 16, 2003, 07:09 AM
I don't make a habit of downloading random people's .doc files.  Perhaps you should post it in a more accessible format?
Title: Re:can any 1 help me
Post by: Telos on December 16, 2003, 08:16 AM
Pseudo program flow
- Ask user for number of points to enter
- Ask user for N points
- Store each point in the multidimensional array
- Iterate through the array calculating the distance between points n and n + 1
- Display answer
Title: Re:can any 1 help me
Post by: whitewidow on December 16, 2003, 08:21 AM
this is how my program looks like...
but it is not how it should be, cause i am not sure how to include arrays..

#include <iostream.h>
#include <iomanip.h>
#include <math.h>


int main()
{
double a=0.0;
double b=0.0;
int x=0;
int y=0;
int w=0;
int z=0;
int d=0;
int n=0;

cout<<"Jamie Clack. Exercise 4"<<endl;
cout<<"Length of a line Programme"<<endl;
cout<<"Please enter the number of points on the line"<<endl;
cin>>n;
cout<<"Please enter the number of coordinates"<<endl;
cout<<"The coordinates should be in the form x,y"<<endl;
cout<<"please enter the value of x"<<endl;
cin>>x;
cout<<"Please enter the value of y"<<endl;
cin>>y;
cout<<"Please enter the 2nd value of x"<<endl;
cin>>z;
cout<<"Please enter the 2nd value of y"<<endl;
cin>>w;
if(n>10)
{
return 0;
}
a=(x-z)*(x-z)+(w-y)*(w-y);
b=sqrt(a)*n;
cout<<"Length ="<<b<<endl;

return 0;
}



what do i have to do....
Title: Re:can any 1 help me
Post by: Telos on December 16, 2003, 08:54 AM
Create a multidimensional array


float PointArray[2][10];


Store points in it


PointArray[0][PointCount] = x;
PointArray[1][PointCount] = y;
Title: Re:can any 1 help me
Post by: whitewidow on December 16, 2003, 09:50 AM
telos where do i have to put the arrays cause when i put this in i got errors.
Title: Re:can any 1 help me
Post by: Telos on December 16, 2003, 11:43 AM

#include <iostream.h>

int main()
{
   double   PointArray[2][10];
   int      NumItems;

   cout << "Enter the number of points: ";
   cin >> NumItems;

   for( int i = 0; i < NumItems; i++ )
   {
      cout << "X-Coordinate: ";
      cin >> PointArray[0][i];
      cout << "Y-Coordinate: ";
      cin >> PointArray[1][i];
   }

   return 0;
}


You should be able to figure the rest out based on this simple framework.
Title: Re:can any 1 help me
Post by: whitewidow on December 16, 2003, 11:58 AM
telos should the program be codeed like this


#include <iostream>
#include <iomanip>
#include <math.h>
#include <stdlib.h>

#define MaxPoints = 10;

struct test {
int x;
int y;
}xypoints[10];

double FindOneLength(int x1, int y1, int x2, int y2)
{
double passvalue = 0.0;
int sqx = 0, sqy = 0;
sqx = (x2-x1);
sqx *= sqx;
sqy = (y2-y1);
sqy *= sqy;
passvalue = sqx + sqy;
passvalue = sqrt(passvalue);
return passvalue;
}

int main()
{
int NumberOfPoints=0;
int counter=0;
char close;
double LengthOfSegment = 0.0;

std::cout<<"\t\t\t Jamie Clack. Exercise 4\n";
std::cout<<"\t\t\tLength of a line Programme\n\n\n";
do {
std::cout<<"Please enter the number of points on the line(Min=2,Max=10)\n";
std::cin>>NumberOfPoints;
}while((NumberOfPoints > 10)or(NumberOfPoints<2));

std::cout<<"Please enter the values of x and y\n";
std::cout<<"The coordinates should be in the form x y\n\n\n";
do {
std::cout<<"Point "<<counter+1<<"\n";
std::cout<<"x: ";
std::cin>>xypoints[counter].x;
std::cout<<"y: ";
std::cin>>xypoints[counter].y;
std::cout<<"\n\n";
counter++;
} while (counter<NumberOfPoints);


counter = 0;
do {
LengthOfSegment += FindOneLength(xypoints[counter].x, xypoints[counter].y,xypoints[counter+1].x,xypoints[counter+1].y );
counter++;
}while(counter<NumberOfPoints-1);

std::cout<<"Length of Segment = " <<LengthOfSegment<<"\n";

//This is just to pause the program so that compiler does not close window
std::cout<<"Type a char and then press enter to close window\n";
std::cin>>close;
return 0;
}


but there is a error on the first while statement

Edit: use code tags
Title: Re:can any 1 help me
Post by: K on December 16, 2003, 12:05 PM
the logical OR operator in C++ is ||.  This will fix your error.  I also suggest:

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>

using namespace std;


which will clean your code up by letting you take out all the std::s.  I also suggest using [ code ] [ /code ] tags.
Title: Re:can any 1 help me
Post by: Telos on December 16, 2003, 12:06 PM
"or" is not a valid comparison operator.  You will want to say


} while ( (NumberOfPoints > 10) || (NumberOfPoints < 2) )


&& = comparitive AND
|| = comparitive OR
Title: Re:can any 1 help me
Post by: wut on December 16, 2003, 03:07 PM
would have worked if he'd compiled it with gcc :-P
Title: Re:can any 1 help me
Post by: whitewidow on December 16, 2003, 03:14 PM
can any 1 tell me y the program loops until 5th point, i only want it to be 2 points and then i want the answer
Title: Re:can any 1 help me
Post by: Skywing on December 16, 2003, 03:22 PM
Quote from: wut on December 16, 2003, 03:07 PM
would have worked if he'd compiled it with gcc :-P
That doesn't make it valid C++.
Title: Re:can any 1 help me
Post by: iago on December 16, 2003, 06:05 PM
Why are you taking a course, yet have no idea how to do the material?