mrnutty 761 Senior Poster

>>can someone show me an example of how you would initiate a variable.

int variable = 0; //declare and initialize the variables

>>how you would fix a undeclaired identifiers.

an undeclaried identifier means that you used a variables that has not
been declared. For example :

int n = 1;
int m = 2;
sum = n + m; //error indeclared identifier

The way to solve this problem is to declare the variable. In the above
code, you need to declare the variable sum. So the correct code should be :

int n = 1;
int m = 2;
int sum = n + m; //notice the "int sum" part. Thats the declaring the variable part.
mrnutty 761 Senior Poster

Yep, I think you need to include sstream as well. stringstream is
defined in the sstream header file.

caffeine commented: Thank you for being patient with my dumb question! +1
mrnutty 761 Senior Poster

Do something like this :

#include <iostream>
#include <ctime> //needed for time

int main(){
 srand( time(0) ); //seed random number generator
 string name[3] = { "luke" , "tony", "robert" };
 string randomName = rand() % 3; //return a number from [0,3)
}
mrnutty 761 Senior Poster

Just imagine a ball falling in an uneven ground. Before the ball hits
the ground, you have to know some information. Its (x,y) position. Its
velocity vector. Its mass. And so on depending how detail the object is represented. As suggested, if the ball falls vertically, then you just take
its x position. This x position of where the ball is at time t, when falling
will be the same as the point of impact. Thus as suggested, you can just
get the terrain's height from the x position of the ball. Now all you
have to do is calculate the new velocity vector of the ball after the point
of impact. If the ball is falling from any angle, then it will be almost be
the same solution. You use the ball.x position. The calculation for the
velocity vector after the point of impact will be a little different.

mrnutty 761 Senior Poster

>>If I erase the nodes from the list (using list::erase) will this delete the actual objects themselves, or just the pointers on the list.

It will delete the object, you don't need to worry about freeing the memory any longer.

mrnutty 761 Senior Poster

If yor wan't to sort it based on its z-values then use this predicate:

template<typename Object>
struct PointerComp{
 bool operator()(const Object* lhs, const Object* rhs)const{
  return lhs->getZ() < rhs->getZ();
}
};
mrnutty 761 Senior Poster

Dude, I practically gave you the answer. Try something like this :

~DLList()
{        //Type is any data type
 	ListNode<Type> *temp = head;
	  while(temp != NULL){
  	  head = head->next;
	  delete temp;
                  temp = head;
	}
	length = 0;
}
mrnutty 761 Senior Poster

Use binary predicate :

template<typename Object>
struct PointerComp{
 bool operator()(const Object* lhs, const Object* rhs)const{
  return *lhs < *rhs;
 }
};
//....
std::vector<game_object*> objects;
//...
std::sort(objects.begin(),object.end(),PointerComp<game_object>());
mrnutty 761 Senior Poster

This is not java, setting head and tail to NULL will not free the memory. Thus you have a memory leak. Try something like this :

void destroy(){
 Node *pos = _head;
 while(pos != NULL){
   increment(_head); //make head point to next element
   release(pos); //delete the memory pointed by pos.
   pos = _head; 
 }
}
mrnutty 761 Senior Poster

What is the signature of this function? glColor3f is this a function you have specified yourself? If so it seems as though the function is expecting an int where you have provided an array. Did you forget a '*'?

nope. glColor3f is the API's function. He needs to show more code.

mrnutty 761 Senior Poster

I am assuming you mean the first word that starts with 'w'.

If its a structural sentence, then find the first 'w' Then check if the character before it is a space. If so then its what you are looking for. Be sure to watch out, if w is found at index 0. Then thats your answer.

mrnutty 761 Senior Poster

Lets examine this for a second :

while(!isEmpty()){
	ListNode<char *> *temp = head;
	head = head->next;
	head->previous = NULL;
	delete temp;
}

Assume that the list contains, A,B,C. Where A-C can be anything.
Now your delete function will do this :

//Iteration # 1

1) while(!isEmpty()) is true go the code block will get executed.
2) ListNode<Type> *temp = head; Now Type is any data type. Now temp points to the head which points to A.
3) head = head->next; now head points to B
4) head->previous = NULL; now head->previous points to A right? So you are setting A to null. Remember temp points to A, so temp now is null. This is called a memory leak.
5) delete temp; now you delete a null, which does nothing.

//Iteration # 2
//now the list is {null B C }, where null means it does not exist
1) while(!isEmpty()) this is true so the block of code gets executed
2) ListNode<Type> *temp = head; Now temp points to the head which points to B.
3) head = head->next; now head points to C
4) head->previous = NULL; now head->previous points to B right? So you are setting B to null. Remember temp points to B, so temp now is null. This is called a memory leak.
5) delete temp; Now you delete a null, which does nothing.

//Iteration # 3
//now the list …

sid78669 commented: Simply Marvelous! +2
mrnutty 761 Senior Poster

There is a lot to learn. As most things, it will take time and practice. So don't expect it get it soon. There are many comprehensible tutorials about them over the net, so go search them. And maybe come back with a more specific question.

mrnutty 761 Senior Poster

Is there another variable named "b" ? Show more code.

mrnutty 761 Senior Poster

Hint : check your set functions, specifically, check the name of the parameter.

mrnutty 761 Senior Poster

>>i != '\0'

BAD idea!

mrnutty 761 Senior Poster
void NewCustInfo(CustData &cust)
{
	cout << "Customer Name: ";
	getline(cin, cust.name);

}

CustData is a structure that is declared, and the name data member of that struct is of type string. For some reason when I call this function(there are no compile errors), it displays the cout statement, but then completely skips over the getline function. Any ideas?

Thanks

Its probably most likely that there is a new line character in the stream. This happens when you read in a number. As suggested,
place cin.ignore() as the first statement in the function. Then go
on normally.

mrnutty 761 Senior Poster

Seems like your mixing java and C++. This code is wrong :

#include "Hotel.h"

using namespace std;

int main()
{
	Hotel *hotels = new Hotel[5];

	hotels[0] = new Hotel("Hershey");
	hotels[1] = new Hotel("Milton");
	hotels[2] = new Hotel("Sheraton");
	hotels[3] = new Hotel("BestWestern");
	hotels[4] = new Hotel("DaysInn");

	for(int i = 0; i < 5; i++)
		hotels[i].print();

	return 0;	
}

1) You have a memory leak. If you use the keyword new, then when your done, make sure you use the keyword delete on the object that was allocated by new.
2) You do not need to use the keyword new. C++ has something called
memory on stack. That means you do not need to use the keyword new
every time. You can simply just do this :

Hotels hotels[5] ; // create an array of 5 hotels
hotels[0] = Hotels("Hersey");
...so on
mrnutty 761 Senior Poster

Try something like this :

#include <vector>
#include <particle.h>

using std::vector;

int main() {
vector <particle*> vec;
vec.push_back(new particle());
vec.front()->move(); //option 1
vec[0]->move(); //option 2
}
mrnutty 761 Senior Poster

Also as most times, there is a function for this in algorithm library, in the algorithm header..

mrnutty 761 Senior Poster

I read your post, but I'm still confused a little. Can you explain a little more?

mrnutty 761 Senior Poster

First pick a library, maybe some of these search results. Read up on some and see which one fits you best. After
you have picked a library you will need to install the library into visual studio. You will need to add some directories into visual studio. First
pick a library then worry about installing it.

mrnutty 761 Senior Poster

if Array is of type string, then the correct declaration would be :

ifstream readFile(Array[5].c_str()];
mrnutty 761 Senior Poster

Did you define them? Also why does ThreeDimensionalShape only store 2
values. Also there is some serious problems with your inheritance diagram.
Take another look at the shape class. Look at what it stores. Look at
what you need for each class.

mrnutty 761 Senior Poster

I assume the problem you are having is to install the library into your IDE.
What compiler are you using ?

mrnutty 761 Senior Poster

>> if((number!=3) || (number!=5) || (number!=7) || (number!=9))

Change the OR(||) to AND(&&).

>>
while((number==3) || (number==5) || (number==7) || (number==9))

Change the "==" to != and change the || to &&.

And most of all, inside your do while loop, GET THE INPUT from the console!

EDIT: I just got ninja'd

mrnutty 761 Senior Poster

>>static bool not_isOdd(const int &i)

A better name would be , isEven(...);

Work with 2 copies, of the vector and transform then into even and odd
vectors like so :

int A[9] = {1,2,3,4,5,6,7,8,9};
	std::vector<int> numbers = std::vector<int>(A,A+9);
	std::vector<int> evenNumbers = numbers;
	std::vector<int> oddNumbers = numbers;
	std::vector<int>::iterator vecItr;

	
	vecItr = std::remove_if(evenNumbers.begin(),evenNumbers.end(),isOdd);
	evenNumbers.resize(vecItr - evenNumbers.begin());

	vecItr = std::remove_if(oddNumbers.begin(),oddNumbers.end(),isEven);
	oddNumbers.resize(vecItr - oddNumbers.begin());
mrnutty 761 Senior Poster
int funcReturn() {
    int a[3] = {33, 44, 55};
    for( int i = 0; i < 3; i++) {
        return a[i];
    }
}

This is not doing what you think it is. After it hits the return statement
it returns. And every time you call this function, the "i" will be always 0.

Try using static like so( warning not a good way )

int funcReturn() {
   static int index = -1;
   index = (index+1) % 3;
    int a[3] = {33, 44, 55};
    for(;i < 3; i++) {
        return a[i];
    }
}

A better way is to pass an array to function. Also you are missing the
"int" part in "int main()". main has to be declared int by def.

mrnutty 761 Senior Poster

Very nice. Now if we can only get what the problem is, then it would be nice of you.

mrnutty 761 Senior Poster

My code I included only works out the bottom 10 digits so
9559449000
Guess you probably didn't need any help after all :)

I don't know if you wanted a broader approach to say calculating...

the last 128 digits from the sum of 1000 numbers to a random power I can go through method two if it will help.

I would recommend a computing approach over the mathematical sequences as it is difficult to format maths without paper and pencil.

My signature is an exercise for the people willing to give it a try.
I just write it in a weird way. Anyway, nice job for the solution.

mrnutty 761 Senior Poster

What does it supposed to do, make the user specify the shape of the
function? For example, is the input supposed to be something like this :

#####
#   #
#   #
#####

Should the user input a hallow box?

jonsca commented: Rep for this monster thread +2
mrnutty 761 Senior Poster

Do something like this :

//mainSrc is the source where the secondarySrc will compare from
//function returns the percentage of matching words
float checkList(const  std::vector<string>& mainSrc, const std::vector<string> secondarySrc){
  size_t matchingWords = 0;
  //for each word in secondarySrc, check if mainSrc has the secondarySrc[i]. If so then increment matchingWords, else move forward
  //return matchingWords/mainSrc.size();
}
mrnutty 761 Senior Poster

Well not to be mean but think about it for a second. If I only use one step for the functions its going to go down then go back to the beginning then go left and back to the beginning.

The function fills the bottom row first, until it hits the wall.
When it hits the wall it fills the top row, then again when it hits the wall it fills the
left column, and then it fills the right column. When you subtract or
add by two, you might have invalid memory access. If it bothers you
that much, you can always change the orientation of how the
recursive function is called, for example you can call it like so :

fillArray(shape,row+1,column);//down
 fillArray(shape,row,column-1);//left
 fillArray(shape,row-2,column);//up
 fillArray(shape,row,column+2);//right

As for your getShape function, I cannot help you because
I don't know what the requirements are.

mrnutty 761 Senior Poster

I'm not sure what your answer, but here is what I believe is the answer :

1^1 % 10e10 = 1
3^3 % 10e10 = 27
5^5 % 10e10 = 3125
7^7 % 10e10 = 823543
9^9 % 10e10 = 387420489
11^11 % 10e10 = 85311670611
13^13 % 10e10 = 75106592253
15^15 % 10e10 = 90380859375
17^17 % 10e10 = 86336764177
19^19 % 10e10 = 13589123979
21^21 % 10e10 = 21381124421
23^23 % 10e10 = 55032910567
25^25 % 10e10 = 33447265625
27^27 % 10e10 = 19149892803
29^29 % 10e10 = 16126483469
31^31 % 10e10 = 56044734431
33^33 % 10e10 = 37183380513
35^35 % 10e10 = 96435546875
37^37 % 10e10 = 70199442517
39^39 % 10e10 = 17009951959
41^41 % 10e10 = 25137953641
43^43 % 10e10 = 67198995507
45^45 % 10e10 = 28173828125
47^47 % 10e10 = 96385062863
49^49 % 10e10 = 29325062449
51^51 % 10e10 = 8231315051
53^53 % 10e10 = 1256150373
55^55 % 10e10 = 99365234375
57^57 % 10e10 = 4855688057
59^59 % 10e10 = 99552427939
61^61 % 10e10 = 48560431661
63^63 % 10e10 = 79138342847
65^65 % 10e10 = 83837890625
67^67 % 10e10 = 50052277723
69^69 % 10e10 = 92201741429
71^71 % 10e10 = 65129996471
73^73 % 10e10 = 90062013833
75^75 % 10e10 = 83544921875
77^77 % 10e10 = 42530996797
79^79 % 10e10 = 51339775919
81^81 % 10e10 = 31371782481
83^83 % 10e10 = 47212640587
85^85 % 10e10 = 84814453125
87^87 % 10e10 = 18054601383
89^89 % 10e10 = 36592384409
91^91 % 10e10 = 29136642691
93^93 % 10e10 …
mrnutty 761 Senior Poster

This is wrong :

void getshape(char shape[MAX_ROW][MAX_COL])
{
     char end='.';
     printf("Enter a shape and when your done enter '.'\n");
     while ((end=getchar()) != '.')
     {
           shape[MAX_ROW][MAX_COL]=getchar();
     }
     return;
}

shape[MAX_ROW][MAX_COL] is invalid memory access.
This is also wrong :

void fillArray(char shape[MAX_ROW][MAX_COL], int row, int column)
{
    if (shape[row][column] == '*' || shape[row][column] == '#') return;
    else
    {
     shape[row][column] = '*';
 
	 fillArray(shape,row+1,column);//down
	 fillArray(shape,row-2,column);//up
	 fillArray(shape,row,column-1);//left
	 fillArray(shape,row,column+2);//right
  }
}

I don't know why you are moving column-2 or column+2. Move only
1 step.

mrnutty 761 Senior Poster

These are wrong :

double calcFwt (double wkPay, double fwt);
       {
               return fwt = 0.20 * wkPay;
       }
 
double calcFica (double wkPay, double fica);
       {
                return fica = 0.08 * wkPay;
       }
 
double calcNetPay (double wkPay, double fwt, double fica, double netPay);
       {
                  return netPay = wkPay - (fica + fwt);
       }

There are at least 2 things wrong with each function. Try to find out that
it is.

mrnutty 761 Senior Poster

This is wrong right of the back, "while (found=false && first<=last)".

This is also wrong :

else if(searchValue>array[midpoint])
    last=midpoint-1;
else 
   first=midpoint+1;

Any clue why?

mrnutty 761 Senior Poster

Because as of right now you have to include the definition of the template class in the same file as the template header. If your compiler supports the
keyword export, then you can separate them.

mrnutty 761 Senior Poster

In recursion there are 2 main things :

1) basis :
2) Induction.

In you recursive, you have provided the Induction, namely
f() = f(), but you have not provided a basis case.

Here is an example of a recursion function. Again, a recursion function
has a basis and the Induction.

//example of recursion
void printXTimes(int printWhat, int howMany){
    if( howMany == 0) return; //our basis...

    cout << printWhat; //print whatever is passed in
    printXTimes(printWhat, howMany-1); //our Induction
}

As you can see we reduce howMany by 1 in ever recursive call.

The above function is a recursive function because it has a basis case
and an Induction. It is defined as follows :

Our function is defined as, F : N --> empty , where empty means it
returns nothing. Then our basis and induction are :

Basis : n = 0
Induction : F(x,n) = F(x,n-1)

MrYrm commented: thx for the info +0
mrnutty 761 Senior Poster

>>For more info, check out the tutorial on Narue's website.

Is he the founder?

mrnutty 761 Senior Poster

Use cout and cin instead of the C function printf and scanf, after all this
is C++.

Using rand, you have the correct idea, but you also have to seed it.
Insert this code : srand( time(0) ) at the very beginning of your main.
That code seeds the rand function so that it spits out seemingly random
numbers. You will have to import ctime header file to use time(0);

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

Inside your fill function, check if row and col is out of bounds.

mrnutty 761 Senior Poster

Cross platform, I would say openGL is your best bet.

mrnutty 761 Senior Poster

>> shape[MAX_ROW][MAX_COL] = '*';

That is wrong. Using MAX_ROW and MAX_COL is wrong. It is 1 passed the
index, and does not contain any valid data. Just leave that code out.

mrnutty 761 Senior Poster

>>However, the flamethrower works in a totally differentmanner, ie. calling my particle engine, while my MachineGunClass, simply calls a glPoint.

Yes I also mentioned that here in my previous post, "The point here is that, they do differ internally, but not so much externally".

class WeaponMasterClass
{
virtual Shoot();
virtual Reload();
virtual BulletsLeftInClip();
virtual IsReloading();
// virtual vars I need, ect.
};

>>And then calling this, with it set equal to some other weaponobject, lets say the flamethrower, would make it use the flamethrowers shoot, instead, since it's virtual?

Yes, if the flamethrower object is derived from that base class.
Not exactly, you will need its return type as well.

>>P.S.: Virtual, vs. Pure Virtual

Virtual and not Pure Virtual.

mrnutty 761 Senior Poster

>>Anyways you should be able to fix the problem you have by declaring pBeam in a global scope (by declaring it outside of functions at the top of your file).

You should but that is not a good solution. Don't start of learning bad practices. It will only come back to haunt you. I can't look at your code right now, but I might get back at this later.

mrnutty 761 Senior Poster

ok

Make sure that you check if startX and startY is within the boundaries
of the array, and also that its not equal to the wall.

mrnutty 761 Senior Poster

Put that code inside your main, before calling the fillArray function.
Then pass that onto the fill Array function like so :

int main(){
  //....
  cin >> startX >> startY
  fillArray(Array,startX,startY);
  //...
}
mrnutty 761 Senior Poster

this is your problem :

fillArray[r][c] = '*';

that should be

shape[r][c] = '*';