• Welcome to Valhalla Legends Archive.
 

can any 1 help me

Started by whitewidow, December 16, 2003, 05:29 AM

Previous topic - Next topic

whitewidow

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

iago

That's fairly easy.. what exactly are you having a problem with?
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


whitewidow

#2
the program its self
i cant do it.


whitewidow

is there no one that can help me with it


please some one help me

Kp

I don't make a habit of downloading random people's .doc files.  Perhaps you should post it in a more accessible format?
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Telos

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

whitewidow

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....

Telos

Create a multidimensional array


float PointArray[2][10];


Store points in it


PointArray[0][PointCount] = x;
PointArray[1][PointCount] = y;

whitewidow

telos where do i have to put the arrays cause when i put this in i got errors.

Telos


#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.

whitewidow

#10
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

K

#11
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.

Telos

"or" is not a valid comparison operator.  You will want to say


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


&& = comparitive AND
|| = comparitive OR

wut

would have worked if he'd compiled it with gcc :-P

whitewidow

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