Hi, i need help with my c.w i know this is not the right place to ask but i have no other choice ! I had a friend who was suppose to help me to do this but went to holiday and now i have till 3rd april to submit this or i'll fail :(( :(( :((

Please Pleasee pleaseeee i'm not good at c++ i've been trying to find a way to do this for 2weeks now but i couldn't i've never felt this dumb in my life !!! :((

Please send me anything that you think will help me out :((

Requirements
Develop a class specification for the class Point (the data members and the prototypes for the member functions) in the file point.h.
Develop the implementation of the member functions in the file point.cc and test them with a suitable test program.
For example:

``````//pointTest.cc
int main()
{
Point P1;
P1.create(24,16); // create a point with coordinates {24,16}
P1.display(); // display the {X,Y} coordinates of P1
.....
}``````

Develop a class specification for the class Line (the data members and the prototypes for the member functions) in the file line.h.
Develop the implementation of the member functions in the file line.cc and test them with a suitable test program.
For example:

``````//lineTest.cc
int main()
{
Point P1;
P1.create(24,16); // create a point with coordinates {24,16}
Point P2;
P2.create(33,42); // create a point with coordinates {33,42}
Line L1;
L1.create(P1,P2); // create a line using points P1 and P2
cout << L1.length() << endl; // display the length of line L1
Line L2;
L2.create(12,30,28,16); // create a line using coordinates {12,30}, {28,16}
L2.display(); // display the coordinates of both points
.....
}``````

Application
We wish to determine the length of the boundary of an irregular polygon.
The polygon may have between 3 and 9 sides.
The user should be prompted to enter the number of sides and the coordinates of each vertex point.
The program should then calculate and display the total length of the boundary.
You should write a main function to implement this using your Point and Line classes and test the program thoroughly.

What you should hand in
The following should be submitted to the Campus office in hard-copy form:

* A listing of the files point.h, point.cc, the class test program and results.
* A listing of the files line.h, line.cc, the class test program and results.
* The application test program and results.

3
Contributors
8
Replies
9
Views
10 Years
Discussion Span
Last Post by VernonDozier

So what have you done for the past two weeks other than stare at the requiremeents in disbelief ? Have you actually attempted to write those two classes ? Have you studied your textbook and listened to your teacher's lectures? I know that every textbook ever written about c++ will teach you how to write a c++ class.

Hi, i missed 5weeks of my lectures because i had to go back to cyprus and see my family and since i've come back, i researched and read my notes but because i don't know the basic stuff i can't do much, i've found so many diffren examples but i'm not able to change them. And C++ is very diffrent from what i've done before with vb and data bases :(( believe me if i wasn't desperate i wouldn't ask for your help, and i'm not a lazy student its just programming is my weakest point and this past couple of months instead of being able to study i had to sort out a family crisis.

Well I can't give it to you, but maybe I can point you in the right direction. Let's look at what the end result is and work backwards:

What you should hand in
The following should be submitted to the Campus office in hard-copy form:

* A listing of the files point.h, point.cc, the class test program and results.
* A listing of the files line.h, line.cc, the class test program and results.
* The application test program and results.

So that is five files that you have to program:
point.h
point.cc
line.h
line.cc
main.cc

Absent is a file called "makefile", which leads me to believe you don't need to write one, which leads me to believe that you are using an IDE like NetBeans or Visual C++ or Dev C++ that writes one for you and figures out how to combine all the files, etc. So that's good. You will, however, need to tell Dev C++ (I'm just going to call the IDE Dev C++. They all work similarly) which files need which other files. You do this with what is called a #include directive. So you need to decide which classes need which other classes to work right. Now a line has two Points, right? So the Line class needs the Point class to do its job. See this function in the Line class:

``L1.create(P1,P2); // create a line using points P1 and P2``

Clearly the Line class needs the Point class. So near the top of the line.h file (line 2), you'll need this:

``````// Filename : line.h
#include "point.h"

// code

class line
{
private:
// code
public:
// code
};``````

Generally you'll also see three other lines in all of your .h files too (lines 1, 2, 15):

``````#ifndef LINE_H
#define LINE_H

// Filename : line.h
#include "point.h"

// code

class line
{
private:
// code
public:
// code
};
#endif``````

Make everything upper case and make the letters before the '_' character the name of your class.

You'll have a very similar file called "point.h". Decide whether the point class needs the line class to do its job correctly. If it does, add a #include directive at the top to the point.h file. For the .cc files, you will have a #include of the ".h" file. So here is a VERY rough skeleton of five files:

``````#ifndef LINE_H
#define LINE_H

// Filename : line.h
#include "point.h"

// code

class line
{
private:
// code
public:
// code
};
#endif``````
``````// Filename : line.cc
#include "line.h"

// code``````
``````#ifndef POINT_H
#define POINT_H

// Filename : point.h

// code

class point
{
private:
// code
public:
// code
};
#endif``````
``````// Filename : point.cc
#include "point.h"

// code``````

Finally, main.cc. You need to include your two classes here. You'll include the two .h files to do that:

``````// Filename : main.cc
// code

#include "point.h"
#include "line.h"

// code

int main ()
{
// code
return 0;
}

// code for non-class functions``````

There are lots of threads on making classes on Daniweb and online that go into a lot more detail. This may save you some time as far as the very basic low-level skeleton of how your files can be set up.

Hi, thanks for helping me out, i've almost learned how to create a class in this two weeks , i mean i learned the structure. But i don't know what to put in point.h or line.h. I mean in point.h how can you get 3-9 coordinates ? or how can you create the lines using those points in line.h ? :(

We don't know what you know and what you don't know and it sounded like you didn't know anything about classes at all, so I started from the bottom. O.K., so you know the basic structure of a class and the syntax and public versus private, how to call class members, etc.? You need help on designing the class (data members and member functions).

I'd start with data members. Figure out the functions you need from the data members (and what your professor provided). Point is the simplest. Assuming this is a two dimensional setup, a point has a horizontal component (x) and a vertical component (y). That's it. So the Point class will have two data members (x and y). Make them integers or doubles. Looks like they are treated as integers to me from the code you provided.

Two Points make a Line, so again, there are your data members. Just two of them, both of type Point. So there are two data members of type Point in the Line class.

As far as polygons go, you have a choice. You can create a THIRD class of type Polygon, but it doesn't look like your teacher wants that. So don't make a Polygon class. Polygons will all be in main.cc. I guess if I couldn't make it a class, I would make a Polygon struct and have it in main.cc. A Polygon is a collection of Lines, with each line representing a side of the Polygon. So I guess have a struct called Polygon, which would have as data elements an integer representing the number of Lines and an array or vector of that many Lines.

I would do this one step at a time. Take a small skeleton. Don't implement any functions at all. Stick the data members in your classes. See if it compiles. If not, try to fix it (the compiler may demand at least one constructor before it will compile, or it may not). Have main do nothing but return 0. Then add some constructors. Compile again. Then have a call to the constructors from main. Compile again. Add one line at a time from the main skeleton you were given by your teacher and compile and run every time. Fix the errors before moving on. When you get all of your classes working and the CALLS to your classes working, THEN worry about the Polygon. And don't have Polygon anywhere in either the Point or Line class. Don't have Line anywhere in the Point class.

Hi again, i managed to do a little bit of coding with help of one of my friends but i's not compiling for some reason i'll put them here please have a look at it and let me know what you think:

point.h

``````#include<iostream>
using namespace std;
// Reference Bressenhams line routine

// point.h by Mahdi march 2008
struct
{
int a,b,c,d,p,i,u,s;

}
void init (point&);
int sgn (long p)
{
if (p > 0) return +1;
else if (p < 0) return -1;
else return 0;
}``````

point.cc

``````//point.cc
// implementation file
// Reference Bressenhams line routine

#include<cstdlib>
#include "point.h"

void init( point& t)
{
cin >> t.a;
if(!cin)
{
cerr << "You have entered an invalid input!\n"
}
else
{
cout << "X1 is = " << t.a << endl;
}
cin >> t.b;
if(!cin)
{
cerr << "You have entered an invalid input!\n"
}
else
{
cout << "Y1 is = " << t.b << endl;
}

cin >> t.c;
if(!cin)
{
cerr << "You have entered an invalid input!\n"
}
else
{
cout << "X2 is = " << t.c << endl;
}
cin >> t.d;
if(!cin)
{
cerr << "You have entered an invalid input!\n"
}
else
{
cout << "Y2 is = " << t.d << endl;
}
t.u = abs(t.c-t.a);	// store the change in X and Y of the line endpoints
t.s = abs(t.d-t.b);

int Xincr, Yincr;
if (t.a > t.c) // which direction in X?
{
Xincr=-1;
}
else
{
Xincr=1;
}
if (t.b > t.d) // which direction in Y?
{
Yincr=-1;
}
else
{
Yincr=1;
}

}``````

many thanks

You don't normally put executable code in *.h files because it will cause lots of link problem. So move the function starting in line 12 of the point.h into the *.cpp file then convert line 12 to a prototype like you did at line 11.

Hi again, i managed to do a little bit of coding with help of one of my friends but i's not compiling for some reason i'll put them here please have a look at it and let me know what you think:

point.h

``````#include<iostream>
using namespace std;
// Reference Bressenhams line routine

// point.h by Mahdi march 2008
struct
{
int a,b,c,d,p,i,u,s;

}
void init (point&);
int sgn (long p)
{
if (p > 0) return +1;
else if (p < 0) return -1;
else return 0;
}``````

point.cc

``````//point.cc
// implementation file
// Reference Bressenhams line routine

#include<cstdlib>
#include "point.h"

void init( point& t)
{
cin >> t.a;
if(!cin)
{
cerr << "You have entered an invalid input!\n"
}
else
{
cout << "X1 is = " << t.a << endl;
}
cin >> t.b;
if(!cin)
{
cerr << "You have entered an invalid input!\n"
}
else
{
cout << "Y1 is = " << t.b << endl;
}

cin >> t.c;
if(!cin)
{
cerr << "You have entered an invalid input!\n"
}
else
{
cout << "X2 is = " << t.c << endl;
}
cin >> t.d;
if(!cin)
{
cerr << "You have entered an invalid input!\n"
}
else
{
cout << "Y2 is = " << t.d << endl;
}
t.u = abs(t.c-t.a);	// store the change in X and Y of the line endpoints
t.s = abs(t.d-t.b);

int Xincr, Yincr;
if (t.a > t.c) // which direction in X?
{
Xincr=-1;
}
else
{
Xincr=1;
}
if (t.b > t.d) // which direction in Y?
{
Yincr=-1;
}
else
{
Yincr=1;
}

}``````

many thanks

You really shouldn't have much (if any) implementation code in your .h files. Leave that in you .cc files.

point.h - see my earlier post. Near the top should be the keyword "class", followed by brackets:

``````// code (mostly #define and #include statements)

class point
{
private:
// list private data members and private functions
//  only available WITHIN the class.
public:
// list data members/functions that you want to be
// called/accessed from main.cc and line.cc
};``````

point.cc
Is this a member function of the point class?

``void init( point& t)``

If so, you should add the declaration point:: like this:

``void point::init( point& t)``

This tells the compiler that the function is a member of the point class. Again, as I mentioned in my prior post, consider waiting to code the actual implementation of the functions until AFTER you get the skeleton right.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.