mrnutty 761 Senior Poster

Post the whole code.

mrnutty 761 Senior Poster

what is link a typedef of ?

(h->N+1)

is N the number of nodes?

mrnutty 761 Senior Poster

template class and its definition has to be on the same file, unless
your compiler supports the keyword export.


and you need a forward declaration :

#ifndef STACK_H
#define STACK_H
#include <iostream>
using namespace std;
template<typename T>
class stack;

template <typename T>
class ListNode
{
public:
  ListNode();	
private:
    T value;
    ListNode<T> *next;
friend class  stack<T>;
    	
};

template <class T>
class stack
{
public:
  stack( ); 
  ~stack( ); 
  void push(T const&);
void makeEmpty();
  bool isEmpty() const;
  void pop();
 T top();
  
 private:
  ListNode<T> *topOfStack;

};
#endif
mrnutty 761 Senior Poster

The errors that I have are:

error C2228: left of '.print' must have class/struct/union

This is from this code :

//prompt customer for savings balance and print the balance out
	savingsAccount.calculateMonthylyInterest().print();

To solve it you can do 2 things :
1) Make calculate return the object
2) or use the call separately like so :

savingsAccount.calculateMonthylyInterest();
savingsAccount.print();

error C2511: 'void Savings_Account::modifyInterestRate(double)' : overloaded member function not found in 'Savings_Account'

That error is related to this.

static double modifyInterestRate(); //prototype
//and its definition 
void Savings_Account::modifyInterestRate(double aI)
{
	if(aI > 0 && aI <1)
	{
		annuallyInterestRate = aI;
	}
	else 
		annuallyInterestRate =0.03;
}

Do you see the difference? Change the prototype to
match its definition. So it should be

void modifyInterestRate(double);
//instead of 
//static double modifyInterestRate();

error C2065: 'aI' : undeclared identifier

This is from this snippet :

double Savings_Account::calculateMonthylyInterest()
{
	double customerSavingsBal;
 
	cout << "Please enter your savings balance: ";
	cin >> savingsBalance;
 
	customerSavingsBal= savingsBalance * aI; //<-- HERE
}

Where is aI declared in there? Did you mean to pass it as a parameter?
If so then you need to change the functions prototype as well.

error C2662: 'Savings_Account::calculateMonthylyInterest' : cannot convert 'this' pointer from 'const Savings_Account' to 'Savings_Account &'

That is probably from the other errors.

1 more this , this code is meaningless,

double Savings_Account::calculateMonthylyInterest()
{
	double customerSavingsBal;
 
	cout << "Please enter your savings balance: ";
	cin >> savingsBalance;
 
	customerSavingsBal= savingsBalance * aI;
}

customerSavingBal goes …

mrnutty 761 Senior Poster

I think I just need to tell the sort function sort by ascending order except when you encounter "a" "e" "i" "o" or "u" but am not sure how. Would it have something to do with the p parameter?

Well if you want to do that, then use a compare function and
pass it to std::sort;

It might look something like this :

bool myComp(char a, char b)
{
  string str = "aeiou";
 if(  str.find(a) != string::npos)
     return true;
 if( str.find(b) != string::npos) 
     return true;
else return a < b;
}
std::sort(something.begin(),something.end(),myComp);
mrnutty 761 Senior Poster

//check out the code snippet, here
int random(int low, int high) {
return
}

//use logic to find the min element
//assign initial min element to A[0];
//search through loop seeing if other element's value are 
//greater than min element value if so the reassign min element
//other wise keep searching
int getMin(int A[], int max) {
  ...
}
//same as min, but use ">" when comparing
int getMax(int A[], int max) {
  ...
}
//create a temp variable and assign it to first
//assign second to first
//assign temp to first
void swap(int &first, int &second) {
  ...
}
mrnutty 761 Senior Poster

std:: unique

mrnutty 761 Senior Poster

How to sort using std

int Array[4] = {4,2,2,1};
std::sort(Array,Array+4); //now array is {1,2,3,4};
for(int i  = 0; i < 4; i++) Array[i] *=2; //now array is {1,4,6,8};
//print out the array.
mrnutty 761 Senior Poster

Its hard to explain well. You will just have to read up on 3d coordinates.

Here are some links that may help : Link1
Link2

Link3

mrnutty 761 Senior Poster

This is a great way to think outside the box, but I do not think it is a better solution because it delegates unnecessary work to the end user. I know I would be frustrated with software that did this to me, and I do not get frustrated easily. :D

Yea, I think he should learn the "art of sorting" as it would provide
him with more knowledge. But what I said was just a suggestion.
Of course in a real software, it should be user friendly as possible.

mrnutty 761 Senior Poster

Iwhen to use a void function verses a bool or int or other type of function.

Whenever you create a function, you need to know what it does
first. Does it sort an array, does it return the square of a number,
does it print a triangle? Whatever, it does, you need to know its
objective. After knowing its objective, you can easily figure out
what type function you need. If it calculate the square of a number
then make it return int, since it make sense to return the square
of number. If it sorts an array, then it should be void function
because array are pointers. If it just prints stuff then make it
void because there is no need to return anything. So analyze what
a function does and then look at the different possibilities, and
pick one that fits the situation.

Also how to know what to call into the Function?

Again this is when you know what you want case. When
you know what a function does and you know what you need
it to do, then passing the required parameters isn't hard.
Also you should have functions that you don't use. The
reason you should create functions is for clarity, mostly.
So if you decide to create a function make sure you use it,
its not too big, and you know what its supposed to do.
After …

mrnutty 761 Senior Poster

What you could do is, since you are getting inputs, you can make sure that
the inputs are greater than the last input.

example run :

Please enter a number  :  3
Please enter a number greater than 3 :  5
Please enter a number greater than 5 : 23
Please enter a number greater than 23 :  -42
<Invalid choice> 
Please enter a number greater than 23 : 45
//and so on

But I don't know if this is allowed for you.

mrnutty 761 Senior Poster

switch(opt)
{
case 1: std::sort(array,array+MAX,sortByID); break;
case 2: std::sort(array,array+MAX,sortByName); break;
case 3: std::sort(array,array+MAX,sortByNationality);break;
}

this part i also not understand
std::sort(array,array+MAX,sortByID)--->what is the purpose for this?? o.0''

You know the function call says a lot there :

case 1:    std::sort(array,array+MAX,sortByID); break;

If the users picks 1 the do the following :

std::sort(array,array+MAX,sortByID); break;

std:: <-- from the standard namespace
sort(...) from the standard namespace use its sort functions

sort(array, array + MAX, sortByID);

- Reads as, sort array from the beginning up until Its end, and
use the compare function that is passed to it, which happens
to sort by id.

Remembers, if Array is an array data_type, then its name
is the first address that it points to, so its element 0.
Similarly, Array + 1, is the first element plus 1 over, which is the
second element, and Array + MAX, is the first element plus the
one-pass-the end element. It is one passed the end element
because the sort function uses '<' operator and not the '<=' operator in its for loop.

The same could be said for the other case in the switch statement.

mrnutty 761 Senior Poster

" Why MAX_SIZE = 2 ? "

Choosing 2 was for demonstrative
purpose, it could have been 1000. It represent the max number of student
allowed.

"Q: 1. From the function above, why sometime he use MAX sometime use MAX_STUDENT and MAX_SIZE?? "

The name does not matter. The function prototype can has its own
arguments with its own unique name.


"Is the function must use "const" / "unsigned int"? Can i just declare like
void display( student array[], int MAX);??"

Yes you can, although you might have to typecast it. The use of
unsigned int is because there will never be a negative students,
just 0 to max number of students.

mrnutty 761 Senior Poster

project -> properties -> libraries -> add jar

Thanks, it worked. Is there a way to make this apply to every project
without doing it manually?

mrnutty 761 Senior Poster

Does anyone know how to correctly add a 3rd party library to
NetBeans?

I have NetBeans 6.7.1

The library is from this site : Link. Its called wheels, and its for my class.

It comes in a zip file.

What I tried was this :

1) Set the zip file into my c drive
2) Start up netbeans
3) Click tools->library
4) Click class Libraries
5) click new Library
6) Called it Wheels
7) Under classPath tab , I set the zip file directory
8) same as 7 for source tab
9) Click OK

10) Try to import it like so : import Wheels.user.*;
and Error occurred.

mrnutty 761 Senior Poster

This thread is hilarious.

mrnutty 761 Senior Poster

So do it in stages, say the spaces up to and including the first hash.

You don't have to write the whole thing just to make progress.

Exactly the idea behind " Divide and conquer " strategy, which
in fact is very intuitive.

mrnutty 761 Senior Poster

Have a left, middle, and end variable. Make middle static.

Move left up 1, move end down 1. If left == mid || right == mid then stop.

mrnutty 761 Senior Poster
bool isPrime(int num)
{
   if(num < 2 ) return false;
   else if(num == 2) return true;

     for(int i = 2; i < ceil ( sqrt(num) ); i++)
             if(num % i == 0) return false;
  return true;
}

void printPrime(const int Max = 100)
{
     for(int i = 2; i  < MAX; i++)
            if( isPrime(i)) cout << i <<" is Prime\n";

}
mrnutty 761 Senior Poster
for (int i = 0; i < strlen (address); i++)

Don't use strlen in a loop condition.

I thought most compiler would optimize it. I'll check to see
if it does with Visual Studio Express 2008.

mrnutty 761 Senior Poster

One way you to solve this is to read char by char. maybe something like
this :

char ch;
string content;
ifstream iFile("file.txt");

while( iFile.get(ch) )
{
      if(ch != ',')
          content += ch;
    else 
     {
          cout<<content<<endl;
          content = "";
     }
}
mrnutty 761 Senior Poster

change this :

template< Base* arr,int size = 10>

to

template<typename Type,int size = 10>
mrnutty 761 Senior Poster

Surely you're joking Mr. firstPerson. STL is for Standard Template Library.

One of the few times someone has called be Mr.
No I know what STL is, my question was with your response

It is about STL?

I didn't quite get your question.

mrnutty 761 Senior Poster

what? I don't really get your question?

You can't define template class ?

template<typename Type = int> //default type is int
class ABC {  };
mrnutty 761 Senior Poster

Here is an example :

#include<iostream>

using namespace std;

template<typename T>
class Base
{
private:
	T* x;
public:
	Base() {
		x = new T[1]; 
		x = false;
		cout<<"Base created\n"; 
	
	}
	Base(T l) {
		cout<<"Base created\n";
		x = new T[1];
		x = l;
	}

	T X() { return x; }
	void X(T y) { x  = y; }

	virtual ~Base(){ delete [] x; cout<<"Base destroyed\n";}
};

template<typename T>
class Derived : public Base<T>
{
private:
	T* y;
public:
	Derived() : Base()
	{
		cout<<"Derived created\n"; 
		y = new T[1];		
	}
	Derived(T x0, T y0) : Base(x0)
	{
		cout<<"Derived created\n";
		y = new T[1];
		y = y0;
	}

	~Derived() { delete [] y;  cout<<"Derived destroyed\n";}
};

int main()
{
	Base<bool> * base1 = new Base<bool>; //baseobj created
	Base<bool> * base2; 
	
	Derived<bool> der1; //derived obj created
	
	//polymorphism
	base2 = &der1; //ordinary

	base2 = dynamic_cast<Base<bool>*>(&der1); //safer
	if(!base2)
		cout<<"cannot convert\n";

	delete [] base1;
}
mrnutty 761 Senior Poster

You must be thinking about polymorphism.

mrnutty 761 Senior Poster

youtube it.

mrnutty 761 Senior Poster

Oh that was easy. Thanks bro.

mrnutty 761 Senior Poster

I haven't ever used CLA so I had to ask.

For simplicity sake, Say I have a program that takes in at most 5
arguments. The arguments from args[1] - args[4] has to be some numbers.

These number will be used for something, say to calculate its
average.

How could I use the cmd, to access the CLA and pass it
args[0] through args[4] and execute the .exe of that c++ program.

I searched for it, but didn't find anything specific.

mrnutty 761 Senior Poster

Dear firstPerson,
It is about STL?

What do you mean?

mrnutty 761 Senior Poster

" num.at(i) "

num is an integer and not an array. This does not work.
I think what you are trying to do is something like this :

int digits[4] = {0};
int num;
cin >> num;
int i  = 0;
while(num)
{
     digits[i] = num%10; //get the last digits
     num /=10; //remove the last digit
}

Although not tested, I think that will extract the digits from num into
an int array. Then you can convert it into char if you want.

mrnutty 761 Senior Poster

Enquiries about printf function is more of a c question don't you think?

mrnutty 761 Senior Poster

To convert string to numeric datatype look here

mrnutty 761 Senior Poster

and um... why win32 api? what use will this be to me?

Its good to know win32, but I think for graphics opengl would
be better to learn.

mrnutty 761 Senior Poster

are you using gluPerspective?

mrnutty 761 Senior Poster

another idea :

read the file until it encounter the word that you are looking for.
If found then stop else continue.

something like below. I am assuming your text file is like the one shown above.

bool findWord(char*Filename, string& find)
{
	ifstream iFile(Filename);
	if(!iFile)
	{
		cerr<<"File not opened!\n";
		return false;
	}

	char c;
	string content;

	while(iFile.get(c) )
	{
		if(c != ',')
		{
			content += c;
		}
		else content = ""; //reset string after flag ',' was found

		if(content == find)
			return true;

	}
	return false;
}

[EDIT] didn't see the "user:" part in your text. You can change it to start 1 after the file pointer reaches ':'. [/EDIT]

mrnutty 761 Senior Poster

1) First create a prime number generator
2) The adjust it accodignly to what you need it.

A prime number is one where its 2>= | n | < MAX, n != even, n is evenly divisible its self and 1 only.

A few primes are 2,3,5,7,11.

5 is a prime because its divisible only by 1 and its self evenly.
5/5 = 1 with 0 remainder
5/1 = 5 with 0 remainder

5 mod 4 != 0
5 mod 3 != 0
5 mod 2 != 0


Some hints. Create a isPrime(int num), function.

bool isPrime(int num)
{
   //if num is equal to 2 then return true;

   //check if num is divisible by anything else other than its self
    for( i = 2; i < num; i++) 
    {
        // if num mod i is equal to 0 then num is not a prime number so return false
     }

//if it passed the loop then it is a prime number so return true
}

Now inside your main use a for loop to check is a number is prime

//inside your main
 for i is equal to 2, until MAX 
  {
          //call isPrime with the argument being i. check if it return true 
          // if it return true then print to screen that it is a prime
          //else do nothing
   }

After you get this working, then change it to what you need it to be.

mrnutty 761 Senior Poster

Your code has a memory leak :

Player* temp;
 
	//create 3 objects in vector
	temp = new Player(300, 300); // You ask for memory for temp
	Players.push_back(temp);
	Players.back()->Load("enemy.bmp");
 
	temp = new Player(400, 300); // You again ask for memory for temp.
       //code removed...
       //...
       //...
	temp = new Player(350, 100); //later on you again ask for memory for temp.
       // So the previous memory allocated is lost. You should delete temp before asking for memory.
mrnutty 761 Senior Poster

How to compute probabilities in slot machine games?

You don't. They're rigged.

They are not rigged. Do research before you answer some question
that you are not 100% sure.

mrnutty 761 Senior Poster

For now, I would suggest openGL, as it is easier to learn. Google
tutorials for it. This link
would help you get opengl installed.

mrnutty 761 Senior Poster

If you want you can replace gotoxy with this windows function :

// Cursor Position //
void gotoxy(short x, short y)
{
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD position = {x, y};
    SetConsoleCursorPosition(handle, position);
}
mrnutty 761 Senior Poster

Ask the Google god. Type your question into Google and all your questions
shall be answered.


Note: Not reliable for everything.

majestic0110 commented: lol :) +5
mrnutty 761 Senior Poster

take out stdafx completely.

mrnutty 761 Senior Poster

Maybe you found a counterexample.

If its at me then, for what?

@OP : you are way over complicating your code. Start fresh. Look
at the c++ code, convert it using for loops in java if you want.

mrnutty 761 Senior Poster

let me start you off. This snippet generates prime up to 100. Fill in the
conditions. Its in java...hehe. So you need to understand the logic and convert it. Then you can fill in the needed requirements.

package helloworld;
 

public class Main
{
    static boolean isPrime(int num)
    {
        if(num < 2) return false;

        if(num == 2)
            return true;

        for(int i = 2; i < num; i++)
        {
            if(num % i == 0)
                return false;

        }

        return true;
    }
    public static void main(String[] args)
    {

        for(int i = 0; i < 100; i++ )
            if(isPrime(i))
                System.out.print(i + " is a prime\n");

    }
}
mrnutty 761 Senior Poster

Well to make a GUI program in opengl, say a basic triangle, all you need
to know about c++ is, functions,libraries,if-else,and switch-statements.

From that you can make your first triangle. Although it might be hard
to understand what which function does from the GUI library.

My suggestion would be to program for a at least a year, before jumping
into GUI.

mrnutty 761 Senior Poster

"\n" and '\n' are completely different. One is a string literal which is
null terminated while other is a newline character.

mrnutty 761 Senior Poster

or you can use pointer member function, and pass the class a function
to call.

#include <iostream>

using namespace std;
 

void callThisFunc() { cout<<"This function was called"; }

class CallFunc
{
	
	typedef void(*pF)();

private :
	int x;
public:
	CallFunc() : x(100){ }
	CallFunc(int xo) : x(xo) { }

	void callSomeFunc(pF yourFunc) { yourFunc();cout<<" and x is : "<<x<<endl; }

};

int main()
{
	CallFunc cF(123);

	cF.callSomeFunc(callThisFunc);
 
    return 0;

}
mrnutty 761 Senior Poster

look at the 4th post on this link.
It shows you one way to sort a struct.