Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Standard C, C++

Reply
 
LinkBack Thread Tools Display Modes
Old 05-11-2005, 01: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 10:54 PM. Reason: Please use [code][/code] tags
latin_papi is offline   Reply With Quote
Old 05-11-2005, 10:57 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
The error is in your line.cc
Code:
int Line::create(int, int)
{
}
should be something like:
Code:
int Line::create(int x, int y)
{
    location1 = x; //This is the x location of the city.
    location2 = y; //This is the y location of the city.
    return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class using a specific instance of another class? is this possible? abs Standard C, C++ 5 02-08-2005 03:12 PM
Working with an encrypted password in a class. sde Program Design and Methods 3 07-06-2004 01:31 PM
cgi script Henry PHP 25 12-30-2002 06:54 AM


All times are GMT -8. The time now is 12:35 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting