Author | Message | Time |
---|---|---|
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 | December 16, 2003, 11:29 AM |
iago | That's fairly easy.. what exactly are you having a problem with? | December 16, 2003, 11:33 AM |
whitewidow | the program its self i cant do it. | December 16, 2003, 11:45 AM |
whitewidow | is there no one that can help me with it please some one help me | December 16, 2003, 1:06 PM |
Kp | I don't make a habit of downloading random people's .doc files. Perhaps you should post it in a more accessible format? | December 16, 2003, 1:09 PM |
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 | December 16, 2003, 2:16 PM |
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.... | December 16, 2003, 2:21 PM |
Telos | Create a multidimensional array [code] float PointArray[2][10]; [/code] Store points in it [code] PointArray[0][PointCount] = x; PointArray[1][PointCount] = y; [/code] | December 16, 2003, 2:54 PM |
whitewidow | telos where do i have to put the arrays cause when i put this in i got errors. | December 16, 2003, 3:50 PM |
Telos | [code] #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; } [/code] You should be able to figure the rest out based on this simple framework. | December 16, 2003, 5:43 PM |
whitewidow | telos should the program be codeed like this [code] #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; } [/code] but there is a error on the first while statement Edit: use code tags | December 16, 2003, 5:58 PM |
K | the logical OR operator in C++ is ||. This will fix your error. I also suggest: [code] #include <iostream> #include <iomanip> #include <cmath> #include <cstdlib> using namespace std; [/code] which will clean your code up by letting you take out all the std::s. I also suggest using [ code ] [ /code ] tags. | December 16, 2003, 6:05 PM |
Telos | "or" is not a valid comparison operator. You will want to say [code] } while ( (NumberOfPoints > 10) || (NumberOfPoints < 2) ) [/code] && = comparitive AND || = comparitive OR | December 16, 2003, 6:06 PM |
wut | would have worked if he'd compiled it with gcc :-P | December 16, 2003, 9:07 PM |
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 | December 16, 2003, 9:14 PM |
Skywing | [quote author=wut link=board=30;threadid=4276;start=0#msg35767 date=1071608871] would have worked if he'd compiled it with gcc :-P [/quote] That doesn't make it valid C++. | December 16, 2003, 9:22 PM |
iago | Why are you taking a course, yet have no idea how to do the material? | December 17, 2003, 12:05 AM |