Intrade 33 Junior Poster

It seems that you already had the functions getLength() and getWidth() defined in your class. You can actually delete the duplicate functions defined outside of class scope, so these functions you should completely remove from your code--

float Rectangle::getWidth()
{
	return W;//Is this right?
}

float Rectangle::getLength()
{
	return L;
}

-- because your class already has them defined and double-defining is illegal.

My apologies for not catching this the first time. I immediately assumed you followed the header/source file format for classes within one file. What I mean is I assumed this--

// file data.h

struct data{

   void p();

}
// file data.cpp

#include <iostream>

using std::cout;
using std::endl;

void data::p(){
    
   cout << "data:p()" << endl;
}

-where the class functions are not yet defined until later in the same file or in a different file. That is the usual format for classes, but you don't really have to follow it.

Alright, another thing. About rectangles. What is needed to define the perimeter and area of the rectangle? A rectangle is nothing more than a shape that is surrounded with 4 lines enclosing the shape with four 90 degree angles and each set of parallel sides have the same length as its parallel side (but it isn't restricted to not being the same length of its perpendicular side, so a rectangle can be a square... but a square cant be a rectangle). You only need 1 length and 1 width to determine the perimeter …

Ancient Dragon commented: ++ for good advice +34
Intrade 33 Junior Poster

You forgot to prefix the functions with your classname... right now the compiler sees getWidth() and getLength() as functions declared/defined outside of your class that are independant of your class, so the variables W and L are searched for in global scope and not found--

//...

// prefix getWidth with classname
float getWidth()
{
	return W;//Is this right?
}

//...
// prefix getLength with class name
float getLength()
{
	return L;
}

//...

-- And your function --

void Rectangle::get(float L, float W)
{



}

-- wasn't declared in your class. This is easily remedied by declaring it in your class--

class Rectangle{

 public:
   //...
   void get(float L, float W);
   //...

}

--

// You only have on colon specified between Rectangle and perimeter versus ::
double Rectangle:perimeter(float L, float W)

-- check the comment above area --

class Rectangle // Class Rectangle
{
public:
	Rectangle(float L, float W); // Constructor
	float getLength(){return length;}
	void setLength(float L);
	float getWidth(){return width;}
	void setWidth(float W);
	double perimeter(void){return (length*2 + width*2);} // Perimeter function

        // notice area no longer accepts void but instead desired parameter
	double area(float length, float width) {return (length*width);} // Area funcion

-- Be sure to spell out Rectangle exactly the way your class has the name spelled out --

int main() // main() I'm sure something is wrong here. 
// I understand the main function, but when I use classes I get confused...
{
Rectangle MyRectangle;

-- if you want to shorthand spelling …

Intrade 33 Junior Poster

This pseudocode is much more intuitive. Please forgive me for the previous mistake(s).

//This vector is a vector where {2, 4} is the largest reoccurring sequence
//{1, 8, 3, 2, 4, 5, 7, 2, 4, 5, 8, 9, 2, 4}

//I'm not that good with Pseudocode, but how about this?

// returns the length of the string
function length(string[0... n-1]);

// Input: a map with string keys and int values
// Output: 2 values - the size of the largest sequence and
// a string with the values of the largest sequence
function FindLargestSequence(map[0... n-1])

	largestValue = 0
	largestSequence = ""

	for each key k value v in map

		if v >= largestValue && length(k) > length(largestSequence)
			
			largestValue = v
			largestSequence = k
		end
	end

	return largestValue, largestSequence
end

// Input: a vector of length n
// Output: 2 values - the size of the largest sequence, and 
// a string with the values of the largest sequence
function VectorSequence(vector[0... n-1])

	s = ""

	for largestSequence = 1, largestSequence <= n, largestSequence = largestSequence + 1

		for i = 0, i < n, i = i + largestSequence

			for j = 0, j < largestSequence, j = j + 1

				s = s + vector[i+j]

				if j != largestSequence - 1
					s = s + ","
			end

			if occurrenceMap[s] == NULL

				occurrenceMap[s] = 0
			else

				occurrenceMap[s] = occurrenceMap[s] + 1
			end

			s = ""
		end

		
	end

	return FindLargestSequence(occurrenceMap)
end
Intrade 33 Junior Poster

I am not that great with pseudocode, but this is a possible process. Basically you can use a map with string keys and int values to keep track of each sequence and if the same sequence is run into on the map, increment the value by 1--

// Input: a map with string keys and int values
// Output: 2 values - the size of the largest sequence
function FindLargestSequence(map[0... n-1])

	largestValue = 0
	largestSequence = ""

	for each key k value v in map

		if v < largestValue
			
			largestValue = v
			largestSequence = k
		end
	end

	return largestValue, largestSequence
end

// Input: a vector of length n
// Output: 2 values - the size of the largest sequence, and 
// a string with the values of the largest sequence
function VectorSequence(vector[0... n-1])

	largestSequence = 1
	s = ""

	for h = 0, h < n, h++

		for i = 0, i < n, i = i + largestSequence

			for j = 0, j < largestSequence AND i + largestSequence < n, j++

				s = s + vector[i+j]

				if j != largestSequence - 1
					s = s + ","
			end

			if occurrenceMap[s] != 0

				occurrenceMap[s] = 0
			else

				occurrenceMap[s] = occurrenceMap[s] + 1
			end

			s = ""
		end

		largestSequence = largestSequence + 1
	end

	return FindLargestSequence(occurrenceMap)
end
Intrade 33 Junior Poster

I'm really curious about this, but where do you initialize the size of m_vParentPop2 (your DNA vector)?

Just glancing at the code, I can only see that as the problem. I don't see anywhere where you've pushed DNA pointers into the vector before accessing its [] operator.

I'm using TextPad Search function and only see two occurrences of the use of m_vParentPop2 and each time it's used it's being accessed via [] operator... no initialization spotted.

Intrade 33 Junior Poster

hello..

What do we mean by binary search and how we can do it using C++

thanks..

1) http://en.wikipedia.org/wiki/Binary_search_algorithm

2) http://www.fredosaurus.com/notes-cpp/algorithms/searching/binarysearch.html

I found these sources off of google. I really don't mean to sound mean, but before asking a question on a forum try exhausting other easy means of answering your question to save you the wait time ;p

Intrade 33 Junior Poster

Maybe something like this will work?

class a;
class b;

class a
{
b* bpointer;
};

class b
{
a* apointer
};
miturian commented: friendly and helpful +1
Intrade 33 Junior Poster

Sweet deal. At least you managed to figure it out!

Oh and no I have nothing to do with that website ;p

Jsplinter commented: thanks +1
Intrade 33 Junior Poster
struct PhoneTones
{
   int rowTone,   // Frequencies of the tones generated by a key press
       colTone;
};

// Function prototype

PhoneTones keyToTones ( char key );

//--------------------------------------------------------------------

int main()
{
    char inputKey;         // Input key
    PhoneTones keyFreqs;   // Frequencies of the corresponding tones

    // Read in a series of keys and output the corresponding tones.

    cout << endl << "Enter key pressed (0-9, *, or #): ";
    cin >> inputKey;
    keyFreqs = keyToTones(inputKey);
    cout << "Tones produced at " << keyFreqs.rowTone << " and "
         << keyFreqs.colTone << " Hz" << endl;
    system("pause");
	return 0;
}

//--------------------------------------------------------------------
// Insert your keyToTones function here.
//--------------------------------------------------------------------

PhoneTones keyToTones ( char key )
{
    PhoneTones Freqs;

    switch (key)
    {
      case '1': case '2': case '3': Freqs.rowTone = 697; break;
      case '4': case '5': case '6': Freqs.rowTone = 770; break;
      case '7': case '8': case '9': Freqs.rowTone = 852; break;
      case '*': case '0': case '#': Freqs.rowTone = 941; break;
    }
    
    switch (key)
    {
    case '1': case '4': case '7': case '*': Freqs.colTone = 1209; break;
    case '2': case '5': case '8': case '0': Freqs.colTone = 1336; break;
    case '3': case '6': case '9': case '#': Freqs.colTone = 1477; break;
    }
}

Notice that in your function you declare a PhoneTones Freqs local to that function, but it isn't used anywhere else.

Why not pass your keyFreqs by reference to the function and modify it?

struct PhoneTones
{
   int rowTone,   // Frequencies of the tones generated by a key press
       colTone; …