If you don't need to print out the actual permutations, then you can
just calculate the number of different permutation.
Maybe something like this would work :
return pow(2.0 , double( strlen(str) ) ) - 1;
If you don't need to print out the actual permutations, then you can
just calculate the number of different permutation.
Maybe something like this would work :
return pow(2.0 , double( strlen(str) ) ) - 1;
>>'cannot build abstract class' compile errors.
If thats the error, then what its probably trying to tell you is that
the class you tried to instantiate is an abstract class. If it is not mean to
be then check that you override the proper function with the exact signature.
>>aPure virtual function needs to be defined in the derived class
Not true. It does not have to be defined.
That doesn't make sense. Why do you derive parent from a GrandParents.
Its like saying a parent "is a" GrandParents. Where we know thats not true. A GrandParents, has a child. A parent has a child. That suggests composition, not inheritance. And why do you create a Abstract parent class and a non-abstract parent class. The name,
GrandParent and Parent, is centered around the child. You need to rethink the design and the name. What are you trying to accomplish exactly?
>> But when I run that, the code works other than the fact that it exits out after pause. How do I have it go back to the main "cin"
int cmd = 0;
while( cin >> cmd) {
if(cmdIsBad()) break; //out of the loop
/* else logic goes here */
}
>>i need to instantiate one of the objects HELP
come again?
Your in the C++ section, why can't you use string?
Could anyone help me fix the non-recursive post-order traversal? I Don't have a clue on how to get it working how he wants. It's just confusing the hell out of me.
Also, does anyone know how to add helper methods to a class implementation that are not part of a class's declaration? Because he wants us to add helper methods to make recursive functions possible, but he does not want us adding them to the class declaration of the bt/bst. It just seems like a backwards way of trying to do this assignment...
Google it!! Wiki has a good explanation.
>> (L (APR/1200.0) * pow(brac1,N) ) / (pow(brac2,N) - 1.0);
I think you meant, :
(L * (APR/1200.0) * pow(brac1,N) ) / ( pow(brac2,N) - 1.0 );
You know its easier if you do something like this :
// (L * (APR/1200.0) * pow(brac1,N) ) / (pow(brac2,N) - 1.0);
double term1 = L * APR/1200.0;
double term2 = pos(brac1,N);
double term3 = pow(brac2,N) - 1.0;
double payment = term1 * term2 / term3;
Note that term1,2,3 are bad names. Give them something more meaningful. Dividing the equation into pieces and conquering it is a common strategy. That way you will see the error better.
!!!Initialize your variables!!!
Hint : check your set functions, specifically, check the name of the parameter.
>>vector<class Note> Measurenum;
Its vector<Note>. You don't put that class keyword.
There is no best way. Pick a way that fits the context that its used with.
friend stringArray operator+(const stringArray& left, const stringArray& left);
1) Does not need to be a friend.
2) Need to implement the assignment operator.
stringArray::stringArray(const stringArray& source)
{
count = source.count;
for(int i = 0; i < max_size; i++)
{
strcpy(storage[i], source.storage[i]);
}
}
3) Is not implemented correctly.
4) Give more info, where does it crash? Where is your main?
>>but if you're just gonna laugh at me...go ahead(I'm glad somehow I made you laugh)...i guess you don't know how to answer this problem as well
On the contrary, we are not laughing at you. In fact, I wasn't even
laughing. I apologize if my post sounded offensive, it was not meant to be. What we are trying to tell you is that you can add 2 large numbers
just like you would add it in pen and paper.
For example :
123
+456
----
579
what you did there was add the last digit of both numbers. Then since
it was below 10, we did not carry it to the next number so the result, 9
is our last number of our answer. Then we added the middle number 2 and 5. Thus 2 + 5 = 7. Since this is not over 10, we don't carry. So 7
is our middle number in our answer. Finally we add 1 and 4 to get 5.
Since this does not exceed 10. We don't need to carry, thus 5 is our first
digit. And our answer is 579.
The main thing we did there is start at the last digit of each number
and add them and move left until we reach the first position. This
essentially is the idea.
Instead of using int to hold a number, you can use a …
>>i != '\0'
BAD idea!
her professor says i can help her :-P
Is your mom really taking an engineering course and you
are legit trying to help her? Its hard to believe, although its not
unbelievable. The reason I say is that, your mom is mature and
she would probably realize that, if she needed help, she would ask
the professor instead of asking her son/daughter. I could be wrong
but I suspect that this is for your own h.w. Sorry If i am wrong, but
you have to see where I am coming from.
>> I have downloaded a library from this site that deals with Matrix and Complex
You do realize that C++ has its own complex class. Why don't you
use another application online to verify your answer.
I don't trust NEHE code much. Its outdated. If you are going to
use someone else's code, why not use a better code than theirs.
There are many libraries for printing text in opengl. Pick one an use it.
It is much more flexible and you can create better and cooler looking
text. BTW, I suggest your textprinter to be a singleton. And I am
surprised that glaux is supported in your library. But if you insist
on using this code, then step through the debugger and see whats
happening. It will give you practice and you will eventually find the
error.
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.
Ok, get a pencil( or pen) and a paper. Then start adding two numbers.
This time instead of brainlessly adding, realize what you are doing in
each step. For example, when you add two single digit numbers, you
either get 1 single digit number as the answer or you get 2 digit number
as an answer. When would you get 1 digit number as an answer and when would you get 2 digit number as an answer when you add
2 single digit number.
i have abook but i cant solve it if u can help ,it is a home work
help me if u can
thanx
Instead of asking random people in the internet, use that money
you spent on school, and ask the professor, the teaching assistance,
tutors, your friends. Hell you'll have a better chance asking random
kids in your class.
>> secInHour / mph
Its backwards. Its mph/secInHour
First worry about converting hex values into decimal, specifically into
R,G,B values in base 10.
Suppose the colors in hex, is 0xFF00FF.
The first 2 hex values ,FF, is (R)ed.
The second 2 hex values, 00 is (G)reen.
The third 2 hex values, FF, is (B)lue.
Now in general say the colors, are 0xUVWXYZ,
where UV is the red component, WX is the green component, and
YZ is the blue component. U,V,W,X,Y,Z can be any values.
1) Your first mission is to extract each 2 sequential digit after the 0x.
2) Report back after you get that done, or if you have trouble getting it done.
>> Queue<AvlNode> q ; //it would not allow me to do this
You meant Queue<AvlNode<int>> q ; //right?
The usual rule around here is that you pay us 100 dollars per an hour.
It usually takes us 1-2 hour per homework. So what do you think?
Hints :
1) Make use of for loops
2) Make use of the mod, % , operator
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
Sorry if its been said already.
The keyword class and typename when used in a template function has the same meaning, so they are interchangeable.
At first, there was only the keyword class for a template function. The
keyword class was used because people did not wan't to add any more new keyword( since it would be more to remember). But after a while, they decided that the usage of the keyword class when used in template function confused people as you see.
So they added the new keyword typename.It is more clear and I suggest you to use it if you can.
The only time you should use the keyword class in the context of template function is when you care about backward compatibility, since
some compiler does not implement the keyword typename.
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
}
I read your post, but I'm still confused a little. Can you explain a little more?
Can't compile it but I don't think that output you gave is correct for
the snippet.
There are few assumptions that the snippet makes, "a" is a const number and its greater than 5.
Now lets go through this code :
int alpha[a];
int j;
for(j = 0; j< 5; j++)
{
alpha[j] = 2 * j;
if(j % 2 == 1)
alpha[j - 1] + j;
}
when j = 0, the inside body gets executed, and so alpha[0] = 2 *0 = 0. So alpha[0] = 0.
when j = 1, the inside body gets executed and so alpha[1] = 2 * 1 = 2.
Then the statement (j % 2 == 1) evaluates to (1 % 2 == 1) = true,
the inside body of that loop gets executed, but the inside body
of that loop is just alpha[j - 1] + j which equals, alpha[1 - 1] + 1 = alpha[0] + 1. But that is just a statement that has no effect. So alpha[1]
is still 2. Keep doing this and the output, I think will be :
alpha[] = { 0,2,4,6,8}.
I think the statement alpha[j-1]+1 is copied wrong. Should it be
alpha[j-1] += 1 ?
>> However because vector2f is a type I cannot manipulate it so I need to make an instance of it.
what do you mean?
First the constructor. This is the constructor thats giving you problems :
TreeNode (Comparable value, TreeNode *leftTree, TreeNode *rightTree) ;
All you have to do is, set the left equal to leftTree and set the right
equal the rightTree. But you should be cautions of that. What if
the root value of the rightTree is not greater than the current Tree?
Then it should not be a rightTree right? The same goes for leftTree.
As for your second question, take a look at this code thats in java.
Its not a binary tree, but a general tree, where a node can
have more than 2 childs, thus we cannot just use a left and right
pointer, but instead we use a list.
public void printPreOrder(){
if(this == null)
return;
System.out.print(toString() + " ");
ListIterator<GeneralTree<Type>> itr = _children.iterator();
while(itr.hasNext()){
itr.next().printPreOrder();
}
}
These are the general steps :
1) Check if the current class is null. If so then return; //base case
2) print current node
3) for each children, printPreOder().
That function should be implemented in the TreeNode class. Hope that helps somewhat.
Look at it in our eyes. You talk a little and dump a whole *lot of code on
us. Make it simpler for us to help you by shows only the relevant code
and stating the problem correctly.
I have a hunch, that you are not getting the theory behind a binary
search tree. You should re-read your text book more carefully.
TreeNode *left, and TreeNode* right, both are subtrees. Sure
it is a node, but if you draw a picture, you will soon realize and see
that it is also a subtree. That is why trees are recursive in nature.
As for your problem, I am not sure what to do, since your problem
wasn't stated clearly.
-------------------------------------------------------------------------------------------
*lot is subjective of course
help i need to search and delete a node from a link list
but i am not sure of the algorithm
can someone please help me with the algorithm and concept
need example thanks..
Draw a picture of a linked list on paper. Then write down the steps
you feel is needed to find an element. The same for deleting an element.
>>s a final note I'm wondering whether I should let my ParticleEffect class update all the particles by setting their vaules directly (so basically, the Particle class is public and has no functions) or I should have it call each particle's Update member function.
Go with update() function.
And could you use the update function instead of the reset function?
>>No matter what I do, I always get the numeric value from the ASCII chart. In this case I get 104, even though I denote Name[2] as a character
Thats because tolower() prototype is declared as, int tolower(int c).
So it takes a int and returns a int.
>> Given n points, how can I find how many different lines can be drawn through these points
If thats the exact question then the answer is infinitely many solution.
double linked list is slower for insert and delete and uses more memory.
It's only really preferable over a single linked list if you desire iteration in both directions.
Double Linked list has O(1) insertion and deletion, while
a single linked list, has O(n) insertions and deletions.
A double linked list does not use that much more memory than a single linked list, in a small scale size list. If the memory used by a double linked list is a problem, then you shouldn't be even using a list.
A double list is usually more preferable over single linked list, but there are special cases as always.
>> however I want to print it out at random places and in random numbers. Can anyone suggest how I would go about it?
Depends on what you know. Here is one suggestion :
srand(time(0)); //seed random number generator
const int MAX_SPRITE = 10;
sf::Image sprites[MAX_SPRITE];
const int MAX_X = 50;
const int MIN_X = -50;
const int MAX_Y = 50;
const int MIN_Y = -50
for(int indx = 0; indx != MAX_SPRITE; ++indx){
sprites[indx].posX = rand() % (MAX_X - MIN_X) + MIN_X;
sprite[indx].posY = rand() % (MAX_Y - MIN_Y) MIN_Y;
//and more attributes
}
put srand(time(0)) at the beginning of your main. Make sure
to include "#include<ctime>".
>>for(int n=0; n<i; n++)
should that be n < j ?
Also what exactly is the problem?
>>[3, 3, 4, 3, 3, 3, 2, 8, 8]
// becomes...
// [3, 4, 3, 2, 8]
There is a handy function that does this in the stl, but I won't point you
to it. Notice that each adjacent elements are compared to, and if
the same then deleted. Try to emulate that.
This function :
void LinkedList<T>::insertLast(T newobj)//O(n)
{
ListNode<T> *newNode;
newNode=new ListNode<T>;
cout<<newobj;
newNode->obj=newobj;
newNode->next=NULL;
ListNode<T> *current;
if(head==NULL){
head=newNode;
tail=newNode;
}
else{
current=head;
while(current->next)
current=current->next;
current->next=newNode;
tail=newNode;
}
}
should only take O(1) and not O(n), since you are storing a tail pointer.
The tail pointer should always point to the last element, so instead of this part of the code :
else{
current=head;
while(current->next)
current=current->next;
current->next=newNode;
tail=newNode;
}
it should utilize the tail pointer by doing something like this :
else{
tail.next = newNode;
tail = tail.next;
}
see how much simpler that is. The tail pointer should be the last element at all time, so to add one to the end, you just add it to tail.next, so now instead of tail.next being null, it has another node.
Then you move the tail pointer forward, so its still at the end of the list.
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.