User Profile

Collapse

Profile Sidebar

Collapse
blackx
blackx
Last Activity: Oct 13 '07, 08:08 PM
Joined: Sep 18 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • blackx
    replied to destructor being called for the * operator
    in C
    do you mean something like this?

    Code:
    //copy constructor
    Polynomial::Polynomial (const Polynomial & p) {
    	Polynomial newP;
    
    	newP.numTerms = p.numTerms;
    	this->numTerms = newP.numTerms;
    
    	newP.head = p.head;
    	this->head = newP.head;
    }
    Using this resulted to runtime errors again :(
    See more | Go to post

    Leave a comment:


  • blackx
    replied to destructor being called for the * operator
    in C
    what I did is this, changing the copy constructor and the = operator:

    Code:
    //copy constructor
    Polynomial::Polynomial (const Polynomial & p) {
    	int newNumTerms;
    	Term * newHead;
    
    	newNumTerms = p.numTerms;
    	this->numTerms = newNumTerms;
    
    	newHead = p.head;
    	this->head = newHead;
    }
    Code:
    //Polynomial assignment operator
    ...
    See more | Go to post

    Leave a comment:


  • blackx
    replied to destructor being called for the * operator
    in C
    thanks for the reply. I understand what you meant by the memory leak. I have to clean up my code now.

    Thanks again.
    See more | Go to post

    Leave a comment:


  • blackx
    replied to destructor being called for the * operator
    in C
    I solved the problem.

    I created a pointer for newPoly instead.

    Code:
    Polynomial Polynomial::operator*(const Polynomial &p) {
    	//the newPoly polynomial will be the product of our two polynomials
    	Polynomial * newPoly = new Polynomial;  
    
    	Term * temp1 = this->head;
    	Term * temp2 = p.head;
    
    	double c = 0;
    	int d = 0;
    
    	//we first multiply the
    ...
    See more | Go to post

    Leave a comment:


  • blackx
    replied to destructor being called for the * operator
    in C
    how should I solve this if I want to have a destructor in my code? I'm thinking the destructor is called because the scope of the function ended.

    Should I be using something like static or const?

    help please.
    See more | Go to post

    Leave a comment:


  • blackx
    replied to destructor being called for the * operator
    in C
    if I removed the destructor from my code, I get the answer that I wanted.

    Code:
    //destructor
    Polynomial::~Polynomial () {
    	while (this->head != 0) {
    		del();
    	}
    	
    	this->numTerms = 0;
    }
    See more | Go to post

    Leave a comment:


  • blackx
    started a topic destructor being called for the * operator
    in C

    destructor being called for the * operator

    I overloaded the * operator function as follows:

    Code:
    Polynomial Polynomial::operator*(const Polynomial &p) {
    	Polynomial newPoly;
    	Term * temp1 = this->head;
    	Term * temp2 = p.head;
    	double c = 0;
    	int d = 0;
    
    	for (int i = 0; i < this->numTerms; i++) {
    		for(int j = 0; j < p.numTerms; j++) {
    			c = temp1->coeff * temp2->coeff;
    			d = temp1->deg
    ...
    See more | Go to post

  • blackx
    replied to bubble sort
    in C
    I got my code to work now, hooray!...
    See more | Go to post

    Leave a comment:


  • blackx
    started a topic bubble sort
    in C

    bubble sort

    related to my earlier post, I have a linked list of polynomials and I am trying to do a bubble sort to arrange the polynomials in descending order based on the degree.

    Here's the code I have:

    Code:
    void Polynomial::orderDescending(){
    	Polynomial newPoly;
    	newPoly.head = this->head;
    
    	Term * temp1 = this->head;
    	Term * temp2 = temp1->next;
    
    
    	for (int
    ...
    See more | Go to post

  • blackx
    replied to help with linked list polynomials
    in C
    please take a look at the operator function * and the function bubble and/or order\descendin g. I also need help with the function combine

    main:
    [code=cpp]
    #include <fstream>
    #include <cstdlib>
    #include <string>
    #include "Polynomial .h"

    using namespace std;

    void main() {
    string filename;
    cout << "Enter name of data...
    See more | Go to post
    Last edited by Ganon11; Oct 12 '07, 05:12 PM. Reason: Changing [CODE] tags to [CODE=cpp] tags.

    Leave a comment:


  • blackx
    replied to help with linked list polynomials
    in C
    thanks for the reply. what do you mean by allocating memory for p? Isn't p a parameter argument?...
    See more | Go to post

    Leave a comment:


  • blackx
    replied to help with linked list polynomials
    in C
    Do you guys want me to post the whole code? I really need some help.
    Thanks.
    See more | Go to post

    Leave a comment:


  • blackx
    started a topic help with linked list polynomials
    in C

    help with linked list polynomials

    I am creating a Polynomial class using linked list.
    My problem is that my code has gotten some run-time errors (not compile or build errors) when I was running the program.

    Specifically, I am having problems with overloading a * operator that multiplies 2 polynomials and with using a function that arranges the polynomial in decreasing order based on their degrees.

    Here's the relevant codes:

    For...
    See more | Go to post

  • blackx
    replied to is my code measuring speed correctly?
    in C
    I did get rid of the one without const.
    Basically, I have only

    Code:
    double closestNumber (double num);
    double closestNumber (const double& num)const;
    that's why I was confused why the error is for ambiguous overloading......
    See more | Go to post

    Leave a comment:


  • blackx
    replied to is my code measuring speed correctly?
    in C
    Hi thanks for the reply.

    I got the code to work...it seems the reason why I always got 0 IS because the array is too small. So what I did was ran a loop for 10000 times to add up all the speed times, only then did I got some solid numbers to differentiate.

    2 related questions:
    1) It seems based on my results that the pass by reference takes longer than pass by value for function calls. This does not seem intuitive...
    See more | Go to post

    Leave a comment:


  • blackx
    replied to is my code measuring speed correctly?
    in C
    okay, I'm back here after reading the thread :)

    I was told to specifically use the clock() function to measure speed. so I couldn't use the info on the other thread.

    Any help would be appreciated. Thanks!
    See more | Go to post

    Leave a comment:


  • blackx
    replied to is my code measuring speed correctly?
    in C
    no I haven't. Thanks for pointing it out! I'll check it and come back here if I have some questions. Thanks again!
    See more | Go to post

    Leave a comment:


  • blackx
    replied to is my code measuring speed correctly?
    in C
    thanks for the reply, yah, I saw that page also. clock() is from the ctime class.

    I kinda got the idea for my code from here:
    http://forums.macrumor s.com/showthread.php? t=360028
    See more | Go to post

    Leave a comment:


  • blackx
    started a topic is my code measuring speed correctly?
    in C

    is my code measuring speed correctly?

    I'm using clock() to measure the speed of my code (testing the speed of passing by value vs passing by reference in function calls). The problem is, the speed returned by my code is always 0.0000000

    Can you check if I'm using the clock() function correctly?

    the function is finding the number in the array that is closest to a number given by the user. Here is the code for the pass by value function.

    Thanks...
    See more | Go to post

  • blackx
    replied to Couldn't understand what my error means
    in C
    that makes sense. Thanks again....
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...