View Single Post
Old 05-11-2005, 02:15 PM   #1 (permalink)
latin_papi
Registered User
 
Join Date: May 2005
Posts: 1
latin_papi is on a distinguished road
Unhappy Get the line class working, it does not calculate for some reason

Hi I previously posted this and recieved help, thanks edward, only have one problem thou.. even though it doesnt show me the error messages anymore, it still does not calcultate the numbers i input. My guessing is because i have not linked x1,y1,x2,y2 in the calculation which are the numbers which are entered by the user... Even though I know this I haven't got a clue on how to do this.. Please help me, the sooner the better thanks alot.

My code is here:

Code:
//line.h
#include <iostream>      //input output library
#include <cmath>        //To do all the mathical equations
#ifndef Line_h        //if the symbol Line_h is not defined then carry on
#define Line_h


using namespace std;

// The domain of all the values whether they are public or private
// Have to mention everything in the cw.cc file, kind of a declaration.


class Line             // Class Line
{
                    //The set of Operators

private:        //Only Private and values are not changed

    int location1;//This is the x location of the city.
    int location2;//This is the y location of the city.

public:            //Accesible to everyone, values can be changed

    Line();            //Default Constractor

    void display();     //Containd the result of the equaliton made to calculate
                    //the line distance, form one place to another.

    int Line::create(int, int); //create function


    double dist(Line &P2);  // calculates the distence between "this" and p2

};

#endif                //Ends process
Code:
//line.cc
#include <iostream>     //Input Output library
#include <cmath>        //Mathematical library
#include <cstdlib>
#include "line.h"       //The header file needs to be inlcuded in this.
                    //so that it takes into caccount its content!

           //This is where all the Functions and variables are gonna be made.
            //Then they will be linked to the header file of cw.cc

Line::Line()            //default constructor of the line
{
    location1 = 0 ;    //starting location
    location2 = 0 ;    //finishing location
}


int Line::create(int, int)
{
}


void Line::display()    //returns the final result, this will be called
                    //in the main menu to display.
{
   cout << location1 << "-" << location2;
}

double Line::dist(Line &P2)
{
 double deltaX = location1 - P2.location1;
 double deltaY = location2 - P2.location2;

 return sqrt(deltaX*deltaX + deltaY*deltaY);
}
Code:
//testclassline.cc
#include "line.h"
#include <iostream>
#include <cmath>

using namespace std;

// This contains the main body where you just call functions from the other file
// to output some kind result or equation onto the screen.

void main()
{

int x1,y1,x2,y2; // declarion of all the coorinates which will be input
Line P1,P2,P3;   // declaration of groupings P1 and P2 contain XY coordinates data,
             // P3 the total score of P1 and P3.

cout << "Please enter the first starting point - X coordinate: ";
cin >> x1; // 1st location X input by user

cout << "Please enter the first starting point - Y coordinate: ";
cin >> y1; // 1st location Y input by user

cout << "Please enter the first destination point - X coordinate: ";
cin >> x2; // 2nd location X input by user

cout << "Please enter the first destination point - Y coordinate: ";
cin >> y2; // 2nd location Y input by user


P1.create(x1,y1); // This could be called location 1
P2.create(x2,y2); // This could be called location 2

P1.display();
cout << " to ";
P2.display();
cout << " = ";
cout << P1.dist(P2) << endl;

}

Last edited by redhead; 05-11-2005 at 11:54 PM. Reason: Please use [code][/code] tags
latin_papi is offline   Reply With Quote