2,712 Posted Topics
Re: 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 : [code] int alpha[a]; int j; for(j = 0; j< … | |
Re: >>[B]static bool not_isOdd(const int &i)[/B] A better name would be , isEven(...); Work with 2 copies, of the vector and transform then into even and odd vectors like so : [code] 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 … | |
Re: Take a look at [URL="http://www.cplusplus.com/reference/clibrary/cctype/"] cctype [/URL] header. This is very handy. | |
Re: >> However because vector2f is a type I cannot manipulate it so I need to make an instance of it. what do you mean? | |
Re: [QUOTE=MyRedz;1150529]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..[/QUOTE] Draw a picture of a linked list on paper. Then write down the steps you feel … | |
Re: [QUOTE=jwenting;1149831]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.[/QUOTE] Double Linked list has O(1) insertion and deletion, while a single linked list, has O(n) insertions and deletions. A double linked … | |
Re: >>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. | |
Re: put srand(time(0)) at the beginning of your main. Make sure to include "#include<ctime>". | |
Re: >>[B] Given n points, how can I find how many different lines can be drawn through these points[/B] If thats the exact question then the answer is infinitely many solution. | |
Re: >>[B] however I want to print it out at random places and in random numbers. Can anyone suggest how I would go about it? [/B] Depends on what you know. Here is one suggestion : [code] srand(time(0)); //seed random number generator const int MAX_SPRITE = 10; sf::Image sprites[MAX_SPRITE]; const int … | |
Re: Is there a reason on why the overloaded operators are not part of the Rational class? I think the GCD and simplify function need not to be there. Why shouldn't the class automatically simplify the numerator and the denominator? I can't think of any of the top of my head. … | |
Re: I assume the problem you are having is to install the library into your IDE. What compiler are you using ? | |
Re: Can you give a specific example of the equation you have in mind. | |
Re: >>for(int n=0; n<i; n++) should that be n < j ? Also what exactly is the problem? | |
Re: if Array is of type string, then the correct declaration would be : [code] ifstream readFile(Array[5].c_str()]; [/code] | |
Re: >>[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 … | |
Re: This function : [code] 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; } } [/code] should only take O(1) and not O(n), since you are storing a tail pointer. The tail pointer should always point … | |
Re: 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. | |
Re: >>[B]And the best part is, you can call it like this from anywhere, including inside of a class function, because it is global [/B] That's not the best part, in fact, that's the worst part! | |
Re: >>[B] if((number!=3) || (number!=5) || (number!=7) || (number!=9))[/B] 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 … | |
Re: Do something like this : [code] //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, … | |
Re: [QUOTE=clutchkiller;1146225]I was just in class, learning about STL and class templates. My teacher said you cannot split the class declaration and the function definitions into the normal header/cpp file like you can with non template classes. Is this true, and if so why? I assume it would have somthing to … | |
Re: >>[B]I need some help writing code for a stack using link list implementation without using the STL[/B] So your first task is to create a linked list implementation. Do you know how to start ? Try it and come back. | |
Re: >>[code] bool Empty() { if(Head->GetFront()==NULL) return true; else return false; }[/code] condense that down to : [code] bool isEmpty(){ return Head->GetFront == NULL; } [/code] >> code in DigiNode, "DigiNode* Front". That name , Front is misleading. Consider renaming it nextNode or something similar. This part of the code from … | |
Re: >>[B] tamano = length(v);[/B] That line does not do what you think it does. The array passed in as a parameter gets converted to a pointer, essentially. When that happens, the size of the array is lost. You can either pass in the size( as suggested by WaltP) or you … | |
Re: These are wrong : [CODE] 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 … | |
Re: As always, practice makes close to perfect. Type as much as you can and eventually you will get better. | |
Re: Minor fix : [quote] #include<iostream> int* get_address(int&); int main() { int number = 0; std::cout << "Enter a number: "; std::cin >> number; std::cout << "The memory address for the number is: " << get_address(number); return 0; } [COLOR="Red"]int *[/COLOR]get_address(int& num_addr) { return &num_addr; } [/quote] | |
Re: Why don't you use arrays ? For example his code : [code] ImageIcon c1icon = new ImageIcon ("clubs-2-75.jpg"); ImageIcon c2icon = new ImageIcon ("clubs-3-75.jpg"); ImageIcon c3icon = new ImageIcon ("clubs-4-75.jpg"); ImageIcon c4icon = new ImageIcon ("clubs-5-75.jpg"); ImageIcon c5icon = new ImageIcon ("clubs-6-75.jpg"); ImageIcon c6icon = new ImageIcon ("clubs-7-75.jpg"); ImageIcon c7icon … | |
Re: Think of it this way, a = 19; b = 5; result = a < b; // result = 0 So its essentially the same thing. You compare each bits. Check if there is a mis-match, and go from there. For example the equation for A < B, where A … | |
Re: >>[B] friend Fraction& operator +(Fraction& c); friend Fraction& operator -(Fraction& c); friend Fraction& operator *(Fraction& a, Fraction& b);[/B] Why do these need to be friends anyway? | |
Re: [QUOTE=Kikazaru;1144469]Is there any way to reduce the number of times you have to write: template<typename T> for a bunch of functions all using the same template parameters? i.e., something like this: template<typename T> namespace my_functions_using_T { T function_do_something(const T & t); void function_do_something_else(T & t); } (besides making them all … | |
Re: That code is pretty bad. Its congested with unneeded try and catch statement. You naming convention is very bad. You code is not easy on the eyes. You are using a char arrays which is a bug in my book. Why open it in binary? You do not comment on … | |
Re: 1. Use code tags, [code ] /* put code here */ [code] 2. You code is not doing what you think it is doing. 3. To make it do what you think its doing, you need to use loop(s). 4. Create a min and max variable. Whenever the user enters … | |
Re: Generally there are : CE : computer engineering CS : computer science CSE : computer science engineering Each one has its own percentage of software and hardware teaching. For example, in my school CE is about 70% hardware and 30% software. CS is about 10% hardware and 90% software, and … | |
Re: You cannot do that with regular arrays, sorry. But its a simple fix if you use vectors. | |
Re: Try something like this : [code] void doSomething(const int updateValue, const int maxLoop){ if(updateValue < 0 ) return; for(int curr = 0; curr != maxLoop; curr += updateValue){ /* do something */ } } [/code] and call it like so : [code] int main(){ //stuff whileGameIsNotOver(){ doSomething( player.updateSpeed(), Wall.MaxPosition()); doSomething(2,50); … | |
Re: [CODE]int funcReturn() { int a[3] = {33, 44, 55}; for( int i = 0; i < 3; i++) { return a[i]; } }[/CODE] 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 … | |
Re: If I am reading this correctly, then what you have is a blank square like so : [code] ##### # # # # ##### [/code] or something similar. To that. Then the uses specifies the row and the column or the (x,y) coordinate, per say, that is within the space … | |
Re: I'm gonna post your code here : [code] #include <iostream> using namespace std; int ShowMenu(); int main() { int choice = 1; // end if user picks 4 or with invalid entry, continue program otherwise while ( choice != 9 ) { do { if (choice > 9 || choice … | |
Re: Can you compile a simple program with either openGL or direct3D? | |
Re: >>[B] i have forgotten how to do the setw for the output[/B] You also forgot to use Code Tags. Thus I forgot to help, sorry. | |
Re: >>[B]It may sound harsh, but if you can't figure this one out, you might want to consider switching your major. It doesn't get any easier.[/B] Well not everyone can be like us :). | |
Re: 1) Use code tags. 2) #include "blah.h" tells compiler to look into the project directory for the file. Libraries like string and cctype are not in your directory and so use #include<blah> syntax. 3) Whats your problem? [CODE] //adjusted a little #include<stdio.h> #include<conio.h> //non standard #include<process.h> #include<ctype.h> #include<string.h> #include<io.h> #include<fcntl.h> … | |
Re: Very nice. Now if we can only get what the problem is, then it would be nice of you. | |
Re: Do you have to insert after the index, before the index, or at the index. | |
Re: I believe this is useless: [CODE]currNode->next = head; [/CODE] just take it. Also whats up with the index parameter in your addLast(). You are not doing anything useful with it, so just remove it. And finally you are not returning anything with your addLast() function if index >= 0. | |
Re: If you provide a definition for the constructor for that class, you need to define the constructor. That statement is what the error is saying. For example : Correct way [code] class Test{ int i; public: Test(); }; Test::Test(){ i = 10; } [/code] Incorrect or wrong [code] class Test{ … | |
Re: I'm not sure what your answer, but here is what I believe is the answer : [code] 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 … |
The End.