NathanOliver 429 Veteran Poster Featured Poster

you are not assigning the return from s.pop() to anything. also please use code tags

NathanOliver 429 Veteran Poster Featured Poster

because all an array is is a continuing block of data in memory. c/c++ doesn't care if its one or a million. the function only needs to know where the data starts at. you know its an array and can program accordingly for it.

NathanOliver 429 Veteran Poster Featured Poster

the function collision you have for your coord class right now is collision(coord[]). im saying just to make it collision(coord). then in the function re write your if statement to look like

if(this->xx == asteroid.getxx() && this->yy == asteroid.getyy())
NathanOliver 429 Veteran Poster Featured Poster

well what you have isn't quite fulfilling the assignment. you are supposed to read the file in its on function lets say something like ReadFile(). with ReadFile() you will need to pass in the input stream or you could open the file in the function. then you need to read the first line of the file. i would use getline() for this. a link for getline is here: http://www.cplusplus.com/reference/iostream/istream/getline/ . after that you need to go through that line of text and pull out the row and column information. something like this would do that

char array[30]
int row, column;
getline(infile, array);
row = array[0] - '0';
column = array[3] - '0';

then you have to create your array based on that information and then put the rest of the line of text you got from getline into the appropriate place. i would try working on that and see what you get. it best to break up your coding into small little bits instead of trying to program the whole thing and then try to find out what doesn't work.

NathanOliver 429 Veteran Poster Featured Poster

okay so don't pass in an array of objects but pass in a single object. modify your coord class to just take in a single cord object in the collision function also changing the code to not use [] in your if statemnt. then in your main function just call asteroid[i].collision(asteroid[i+1]);

NathanOliver 429 Veteran Poster Featured Poster

why exactly are you passing an array to your collision method? wouldn't you just want to pass one object or are you trying to see if everything in that array will collide with the calling object?

NathanOliver 429 Veteran Poster Featured Poster

alright just to be sure. you have one function that is supposed to read the first 2 number in the line of the txt file and then create a 2d array based on those values and then you are to populate that array with the rest of the data in that line. then you have to have another function that will print out that data right?

NathanOliver 429 Veteran Poster Featured Poster

alright to use functions to read in the data and to print out the data you have to declare the array in your main function and then pass that array to the read and print functions. in your read function you will have to use the getline() function to read in the entire line of text and then parse through it to get the data you need. in your print function you just need to parse through the array and display it in the correct format. as i said earlier both of these functions will require 2 for loops do this. the first for loop will control what row you are in and the second for loop will control what column your in.

NathanOliver 429 Veteran Poster Featured Poster

the problem is you are using gets() for your input and when you enter more than 10 elements the function gets() writes pass the end of the array and is casing your problem. you can make s bigger then see if s is larger than 10 and if it is than reset s to 10. a better function would be fgets() where you tell the function the max amount of characters to be read. http://www.opengroup.org/onlinepubs/009695399/functions/fgets.html

^^^ oops walt bet me to it

NathanOliver 429 Veteran Poster Featured Poster

first to read in a 2d array you need to use t2 for loops. one for the row and one for the column. also is this the file syntax

2 4ABCDEFG
// or is it
2 4 ABCDEFG

this will determine on how you would have to extract the data from the file.

NathanOliver 429 Veteran Poster Featured Poster

then how would you return a value by reference if it is going out of scope or should you return by value if the variable is going out of scope?

NathanOliver 429 Veteran Poster Featured Poster

i bow before your compiler then ;). seriously i would use the standard operators since i doubt it would work on older compilers.

NathanOliver 429 Veteran Poster Featured Poster

do you have any code so far?

NathanOliver 429 Veteran Poster Featured Poster

you could use a simple for loop in your main function and do a brute force method like your functions do or you could use the Sieve of Eratosthenes method which works very well. http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

also on line 13 in your code you are using or which is incorrect in c++. || = or and && = and in c++

NathanOliver 429 Veteran Poster Featured Poster

the problem is when you pass an array to a function the actual thing that gets passed is a pointer to the first element of the array. the function doesn't know its an array so it doesn't know that he address after the pointer are part of the array. there are to ways to go about this dilemma. first you could pass the size of the array to the function so it knows hat the upper bound is.

int size = 0;
cout << "please enter the number of employees you want to enter: ";
cin >> size;
char * employees = new char[size]; // create a dynamic array
sort(employees, size);
//...

or you could use a sentinel value at the end of the array and check for it while parsing through the array.

//in function for sorting
void sort(char temp[]);
{
       int i = 0;
       while (temp[i] != '/0')
       {
              // your code here
       }
}

i prefer to use the first case becuase it is much easier for int arrays then using a sentinel.

NathanOliver 429 Veteran Poster Featured Poster

i would take a closer look at your variable names.

NathanOliver 429 Veteran Poster Featured Poster

functions return a reference so that there is less overhead in the function return. whatever value you store the return into will hold that value and it doesn't matter that the variable that was returned goes out of scope.

// non reference return
int foo()
{
       int a = 20;
       return a;
}
// reference return
int & foo()
{
       int a = 20;
       return a;
}

as you can see there is no difference between the code except how the return value is returned. it will still get assigned to the variable you have receiving the return.

NathanOliver 429 Veteran Poster Featured Poster

lines 7 and 17-20 need to be looked at again. there is where some of your errors are coming from.

NathanOliver 429 Veteran Poster Featured Poster

a lexer is a program that runs through text and converts it into something you can use in your program an example would be a program that lets you input something like 5x^5 - 3x^3 + 20x^2 +5x -15. it would convert all of those into tokens that your program can use to output a solution. at least this is what i believe it is.

NathanOliver 429 Veteran Poster Featured Poster

Well here is my attempt at a solution. Any feedback is welcome.

#ifndef NATURAL_COMPARE_H
#define NATURAL_COMPARE_H

#include <cmath>
#include <locale>

typedef unsigned int uint;

bool IsStringANumber(std::string);

int natural_compare(std::string first, std::string second)
{
	size_t firstLength = first.length();
	size_t secondLength = second.length();
	size_t count = 0;
	uint firstSpaces = 0, secondSpaces = 0;
	//////////////////////////////////////////////////////////////////////////////
	//  testing for testing null strings
	if (firstLength == 0 && secondLength != 0)
		return -1;
	if (secondLength == 0 && firstLength != 0)
		return 1;
	if (firstLength == 0 && secondLength == 0)
		return 0;
	/////////////////////////////////////////////////////////////////////////////////
	//  eating trialing whitespaces.  no data is modified just the size
	//  of the string to compare is changed.
	while(firstLength > 0 && first[firstLength - 1] == ' ')
	{
		firstSpaces++;
		firstLength--;
	}
	while(secondLength > 0 && second[secondLength - 1] == ' ')
	{
		secondSpaces++;
		secondLength--;
	}
	//////////////////////////////////////////////////////////////////////////////////
	//  testing of numbers.  all numbers come first so if one
	//  string is a number it will be less than the other string
	if (!IsStringANumber(first) && !IsStringANumber(second))
	{
		if (first[0] > second[0])
			return 1;
		if (first[0] < second[0])
			return -1;
	}
	if (IsStringANumber(first) && !IsStringANumber(second))
		return -1;
	if (!IsStringANumber(first) && IsStringANumber(second))
		return 1;
	////////////////////////////////////////////////////////////////////////////////////
	//  testing the length.  if the string is shorter and satisfies the other
	//  conditions than it is smaller
	if (firstLength > secondLength)
		return 1;
	if (firstLength < secondLength)
		return -1;
	/////////////////////////////////////////////////////////////////////////////////////
	//  this block checks equality over same length strings.
	while (count < firstLength)
	{
		if (first[count] == second[count])
		{
			count++;
			continue;
		}
		if (first[count] > …
NathanOliver 429 Veteran Poster Featured Poster

question about the other comparisons. you said it should be

b 5  abc
b  5 abcd
b   5 abc

but shouldn't it be?

b 5  abc
b   5 abc
b  5 abcd

since at position # 4 in the middle string it is a ' ' and in last string it is a 5.

NathanOliver 429 Veteran Poster Featured Poster

I'm sorry I didn't see the checks that were in place. My eyes were faster then my brains. This code is fine i though I saw something different.

NathanOliver 429 Veteran Poster Featured Poster

To jBat and invisi I would reconsider your input methods. you are using cin >> val; which will cause an infinite loop to occur if if something other than a char is entered. I would suggest the use of get(cin, val); instead and then convert if necessary. here is a good link on this. http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.2

NathanOliver 429 Veteran Poster Featured Poster

maybe if you could elaborate.

NathanOliver 429 Veteran Poster Featured Poster

If you already know what files you are going to use than i would just use

ofstream outFile("Data.txt");  
ifstream inFile("Maze.txt");
NathanOliver 429 Veteran Poster Featured Poster

to dived you use / not \. also i(...) is not valid. if you want to multiply i by that quantity you have to do i * (1.0 / i) . Also please use code tags. the link to explian them is http://www.daniweb.com/forums/announcement8-3.html

NathanOliver 429 Veteran Poster Featured Poster
#include statements

using statements

global vars ie 
ofstream fout;
or
ifstream fin;

function prototypes

int main()
{ //...

this is the style i use

NathanOliver 429 Veteran Poster Featured Poster

if (answer!=df1/df2) Very scary. You should not compare floating point numbers this way because it will not always work. here is a good link on why. http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.17

NathanOliver 429 Veteran Poster Featured Poster

To EngSara and gertails please read this http://www.daniweb.com/forums/announcement8-2.html . This forum is designed to help people find answers not to give them to them. This was assigned as homework for a reason. People must show effort otherwise the learning process does not happen as it should.

jonsca commented: Preach it :) +2
Salem commented: Damn straight! +19
NathanOliver 429 Veteran Poster Featured Poster

well since some one already kicked the dead horse ill join in. the guy is looking for the cubed root of a number. lets say its 27. the answer would be 3. now lets say its -27. it would be imaginary right? wrong it exist. if you take -3 and multiply it by -3 you get 9 and then you multiply by -3 again and presto you get -27. you are correct if it is the square root of a negative number but for cube roots there are real answers. FYI all odd roots you can have negative numbers and all even roots you cant.

NathanOliver 429 Veteran Poster Featured Poster

you are getting a overflow and that is what the return value becomes. your call to pow when k=10 for instance returns 1.5556504132421497887188538979512e+174 but the max value for a float is 3.40282e+038. i would try using type double which has a max of 1.79769e+308.

NathanOliver 429 Veteran Poster Featured Poster

thanks for that jonsca. i thought my rand call looked a little light. also thanks for correcting my spelling. i can never get that one right and Ive used it a few times. just doesn't stick right in my head.

NathanOliver 429 Veteran Poster Featured Poster

where are you getting the isblank() function from?

NathanOliver 429 Veteran Poster Featured Poster

srand() seeds the rand() function. a good way to get a random seed is to use the time function because it changes every time you use it. it should be used as follows for general uses

//...
srand(time(NULL));
value = rand() % 365 + 1;
//...

you will need to include ctime in order to do this. for better and and more reliable random number generators i would search Google. a good one is the mesner twister.

NathanOliver 429 Veteran Poster Featured Poster

well first of your calling getline twice. once after your for statement and once after your if statement. also you should not use eof() while reading to the end of the file. you can search around and find some good links about that. i would get rid of the for loop and just use a while loop like

while (getline(ifs1, s1) && getline(ifs2, s1))
{
       // your code here
       i++;  //  this will increment i so you don't need the for loop.
}
NathanOliver 429 Veteran Poster Featured Poster

i believe i have a solution to your problem but there are more values in your sorted results than in the text file with the information to sort. for example there are two "b5"'s in your sorted results but only one in the text file. please let me know because i am interested to see if my code is correct.

NathanOliver 429 Veteran Poster Featured Poster

yeah your setting a pointer equal to another. classes don't need an operator=() function for that its handled by the compiler.

NathanOliver 429 Veteran Poster Featured Poster

I'm not sure about making it a void pointer but you should be able to make a weapons class that is the bass for all of your specific classes and then make a pointer of the base class and re assign it with your specialized class pointer. this would be more inline with c++ OOP style.

class Weapon
{
       // all standard functions and variables.
}

class Flamethrower : public Weapon
{
       //  overide all functions from wepon that are specific to a flamethrower.
}

int main()
{
       Weapon * weapon;
       // later on
       Flamethrower * temp = new Flamethrower;
       weapon = temp;
       // ...
}

this will require the use of virtual functions and may be a little more than you are looking for but i believe this will work.

NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

the faster the data can enter and leave the the ram the better your computer will perform. i.e. a 3ghz processor with 400mhz ram will run slower putting information into the ram than a 1ghz processor with 1ghz ram

NathanOliver 429 Veteran Poster Featured Poster

glad to help

NathanOliver 429 Veteran Poster Featured Poster

i have seen this in my debugger and have no idea what causes it. it might be that there there is a limit on how far the debugger goes to drill down the information of a variable. also under the watch list it has tabs for local, auto witch might also change what is shown.

also my signature doesn't apply to your code. its just to explain to people if they have using namespace std; later in there code they don't need to write std::cout.

NathanOliver 429 Veteran Poster Featured Poster

are you actually getting compiler errors or is it just not letting you see the values of some of the objects/variables while debugging?

NathanOliver 429 Veteran Poster Featured Poster

alright the problem is you are using endl after each name so it wil display each name on a seperate line. if you want to displa it as Last, First then this should work well for you.

void showArray( string names[], int NUM_NAMES )
{
     for(int count= 0; count<NUM_NAMES; count+=2)
     {
          cout << names[count] << ", " << names[count +1] << endl;
     }
     cin.get();  // <-  use this instead of system("pause")
}
NathanOliver 429 Veteran Poster Featured Poster

In the state of the economy right now what is the least amount of education a programmer should have before even trying to find a job. I have been working on computers since I was 13. I started programing in basic that comes on graphing calculators and worked up to visual basics and now I'm teaching myself c++. My father is a robotic engineer in a medicinal robot manufacturing firm and he has been very impressed with my level of detail in my code and the different approaches i take to solving problems. I haven't had any formal education in c++ but was thinking of trying to find a very low entry level job. any suggestions?

NathanOliver 429 Veteran Poster Featured Poster

could you post an example of the code you are having problems with?

NathanOliver 429 Veteran Poster Featured Poster

could you please post your code for your showArray() function. it looks like the problem will be in there.

NathanOliver 429 Veteran Poster Featured Poster

why are you randomly accessing the file? if you are going to use the whole file i believe it would be faster to read the whole file into an array and then access the array at random points.

string array[256];  //  just a guess use whatever number you need to fit all of the words;
int i = 0;
fstream fin("test.txt"); // <-  this line opens the file
if (fin.fail())
{
       cout << "unable to open file.";
       return 0;
}
while (getline(fin, array[i]))
       i++;
fin.close()

with this you just access the array with your random number instead of accessing the file every time. also i don't see you opening the file associated with openWP so that is probably your problem

NathanOliver 429 Veteran Poster Featured Poster

sorry missed that little tid bit. i guess ill go back and try it agian.

NathanOliver 429 Veteran Poster Featured Poster

Hey all. I have written a quine and I was wondering if I have the jist of it right. I'm not sure if the code needs to be longer or this would be a suitable answer. Here is what I have. btw driver.cpp is the file name for my source code for this program.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;


int main()
{
	string temp;
	cout << "this is a simple quine program";
	cout << "\nthe sourece code for this program is a follow:\n";
	ifstream fin("driver.cpp");
	while (getline(fin, temp))
	{
		cout << temp << "\n";
	}
	cin.get();
	return 0;
}