2,712 Posted Topics
Re: You can use sdl's timer or clock, or if your on windows, Queryperformance counter. For example, here is one that uses clock(). [code] #include <iostream> #include <ctime> using namespace std; class Timer{ public: typedef clock_t TimeType; private: TimeType _clockStart; //holds the time of reference public: Timer(): _clockStart(clock()){ } TimeType getTicks()const{ … | |
Re: Whe you create [I]BinaryTree<EmployeeInfo> tree;[/I], you can only insert EmployeeInfo into it. If you want to insert TreeNode into it, then create a [I] BinaryTree<BinaryTree::TreeNode> tree[/I]. I don't know why TreeNode is public. The user should not get a hold of it, since they can mess the tree up! So … | |
Re: Thats because uint3_t can only hold numbers. What you want is strings. [code] #include <iostream> #include <string> using namespace std; int main(){ string input; cout << "Enter something : "; cin >> input; cout << "You entered : " << input << endl; return 0; } [/code] | |
Re: >>I want to calculate sqrt(2) to the maximum level of digits possible... You can't. Its a [URL="http://en.wikipedia.org/wiki/Square_root_of_2"]irrational number[/URL]. | |
Re: I need to see the definition of elem and sentinel before we jump to conclusion. | |
Re: my guess is that you are going out of the array bounds. Whats the size of the array? | |
| |
Re: In C++ you cannot seperate the template header from its definition. So You can't have LinkedList.cpp. You need to put the definition in the same file as the header file. | |
Re: You don't necessarily need a matrix class. All you need is arrays. Better yet, you should use std::vector < std::vector<float> >, as a 2d array. Adjacency matrix are fairly easy to implement with the cost of O(row^2) of space. What exactly are you having trouble with, in respect to Adjacency … | |
Re: Change your template to this : [code] template <class T, class T2> T searchArray(T index, T2 answer, int numOfParts){ [/code] | |
What do you guys think of this new daniweb design? Personally, I'm not very fond of it. The simpler the better. I just don't like the design. It needs more "flavor" or something. Idk, what do you guys think? | |
Re: >> Hello FirstPerson Good morning to you to,em-kay. Now just a few points. 1) Don't use global variables like that. 2) If you don't have a choice then at least, name your variables something meaningful,so I can understand what they are. 3) To move your circle you can do 2 … | |
Re: Here is an example : [code] //Sqrt.h class Sqrt{ private: const float originalValue; const float sqrtValue; public: Sqrt(); Sqrt(float initValue); float sqrtValue(); float originalValue(); } [/code] [code] //Sqrt.cpp Sqrt::Sqrt() : originalValue(0.0f), sqrtValue(0.0f) //initializer list { } Sqrt::Sqrt(float value) : originalValue(value), sqrtValue( std::sqrt(value) ) //initializer list { /* empty */ } … | |
Re: 1) Create a member variable. To hold the weapon. [code] class CPlayer{ private: Sprite weapon; //... } [/code] Now create a get and set function for the weapon : [code] void setWeapon(const Sprite& aWeapon){ weapon = aWeapon; } Weapon getWeapon()const{ return weapon; } [/code] Now you need position the weapon … | |
Re: First, I'm not sure about this : [code] /string string message = () ; [/code] Do this instead: [code] string message; //will hold the encoded message [/code] Now your main problem is decryptLetter. This function is fairly simple. What problem are you having with this exactly? | |
Re: [code] string fileName = "File"; string extension = ".txt"; for(char fileNum = '0'; fileNum <= '9'; ++fileNum){ string currentFile = fileName + string(1,fileNum) + extension; cout << currentFile << endl; } [/code] | |
Re: Try implementing [URL="http://en.wikipedia.org/wiki/Dijkstra's_algorithm"] this [/URL]. | |
Re: Do something like this : [code] class Polynomial{ private: std::vector<int> coeff; //the coefficiants public: void getInput(); void printPolynomial(); } [/code] its pretty much similar to yours except I use a vector instead of raw arrays. Now just implement the input and output functions. ![]() | |
Re: Maybe this will help you get started : [code] #include <stdio.h> int power(int base, int exp){ //logic goes here } int main(){ int res = power(2,10); //res = 1024 printf("%i",res); return 0; } [/code] | |
Re: [QUOTE=Ancient Dragon;1221642]Have you not heard of type casts? [icode]foo((char*)client_message[i].c_str());[/icode] or [icode]foo( const_cast<char*>(client_message[i].c_str()));[/icode] But you have to be careful about casting away the const, especially if function foo() wants to modify the contents of the string.[/QUOTE] I strongly advise against doing that. If you need to cast away a const, then … | |
Re: why do you have Sleep(...) ? and normally "if(Dict.is_open()) " is used as a error checker. There is a lot of problems with you code. Instead of listing them all, I will show you a sample program and you should contrast. [code] #include <iostream> #include <fstream> #include <string> #include <windows.h> … | |
Re: If you can return an iterator, but I think that would be out of your scope. So instead return a index counter, although I am not sure how good thats gonna do you. Try something like this : [code] int floatlist::search(double x) { int index = -1; listnode *p = … | |
Re: What its asking you is to make a walk through table -- a step by step table where each row corresponds to each iteration of the loop. Here, I'll get you started Given this code : [code] int c = 0, sum = 0; while (sum < 8) { c++; … | |
Re: You are looking for std::vectors. Here is an example : [code] std::vector<int> aList(2,0); // 0 0 [size = 2] aList[1] = 1; // 0 1 [size = 2 ] aList.push_back(2); // 0 1 2 [size = 3] aList.pop_back(); // 0 1 [size = 2] [/code] You can also simulate what … | |
Re: [URL="http://lmgtfy.com/?q=C%2B%2B+Pointers+tutorial"]hmmm[/URL] | |
Re: [QUOTE=muralikalpana;1219712]if condition and else condition is there....i want to display hello world. [ICODE] <? if(Condition) { echo "hello"; } else { echo "world"; } ?> [/ICODE] then my frnd asked to me what the condition should write in if condition to display "hello world".[/QUOTE] With that code its not possible. … | |
Re: There are many ways you can approach this problem. I would just notepad to first sort the file and then read it in and do whatever I need to do with it. But I assume this is for learning purposes. So here is some things you can do : 1) … | |
![]() | Re: Here is a site to practice on, [URL="http://www.projecteuler.com"]http://www.projecteuler.com[/URL] |
Re: I am not sure what you are asking exactly, but I'll take a stab at it, say you want to measure the time it takes for a specific part of your program to execute. To get better results, you might want to use QueryPerformanceCounter, rather than clock. But I'll show … | |
![]() | Re: Here is a way to do it using metaprograming. That way you get the result before you even start the program. [code] #include <iostream> template<int binarySequence> struct Binary{ enum{ result = Binary<binarySequence/10>::result << 1 | binarySequence % 10 }; }; template<> struct Binary<0>{ enum{ result = 0 }; }; int … |
Re: Actually, I never seen that before. Usually I just call the function w/o the return statement. I think you should omit the "return" statement on line 8 and 17, because that might confuse a reader thinking that it actually returns something. | |
Re: I don't know if its right. But I would suggest to apply the euler method, or better yet, the RK4 method. Google it. | |
Re: Here are some although googling would help you get more problems : 1) Create a program that checks if the input is odd or eve 2) Create a program that checks is a power of 2 3) Create a program that asks the user for a positive even number, if … | |
Re: >>[B] But before adding the two matrices: m1 and m2 , their destructors gets called[/B] why do you think so ? | |
Why would they ever [URL="http://www.youtube.com/watch?v=o_psomRhMOQ"] ban this sport[/URL]. Its so easy to play. You can play with your families. You can play with friends. Hell, you can even play with a random stranger walking down the street. | |
Re: Have a device where men can see what women are thinking, so they wont be so complicated. | |
Re: Ok, here is the deal. Do you know how to do this with 1 file ? For example in 1 file, you would do this : [code] //main.cpp #include <iostream> using namespace std; float calcAverage(int inputs[], const int size); // [1] function prototype int main(){ const int NUM_OF_INPUTS = 5; … | |
Re: >>**This is my first post as I JUST joined daniweb ^^ << Welcome :) We're glad to have you apart of us. why isn't this defined ? [code]Bible::Bible(string nam, int chapt, int vers, string testa, string txt) //Initialize to any size[/code] | |
Re: First create a skeleton, maybe something like this : [code] // include needed libraries //... int toDifferentBase(int number, int originalBase, int newBase){ //code here } int main(){ //test here } [/code] Now your problem now is to implement toDifferentBase. The easiest way is to convert the input into base 10. … | |
Re: In java you do not need put a semicolon after the class deceleration. In C++ you need it. So this part : [code] #define FERMATH #ifndef FERMATH #include <iostream> #include <cmath> using namespace std; class Fermat { private: long prime p; public: Fermat(); Fermat(long num); long getNum(); bool isPrime(); }[COLOR="Red"];[/COLOR] … | |
Re: Yea, if this is what you mean : [code] #include <iostream> #include <vector> #include <string> using namespace std; typedef string Type; int main(){ std::vector<Type> msg(2,"a"); std::vector<Type>::iterator itr = msg.begin(); while(itr != msg.end()){ cout << itr->data() << endl; ++itr; } } [/code] | |
Re: What you do is use strings : [code] string data; cout << "Enter the date in MMDDYYYY format: "; cin >> date; asserCorrectFormat(data); //make sure valid format doStuff(data); [/code] ![]() | |
Re: [QUOTE=Salem;1214741]I wonder if you anticipated this kind of response? [url]http://clusty.com/search?query=virtual+function&sourceid=Mozilla-search[/url][/QUOTE] I wonder if he anticipated [URL="http://lmgtfy.com/?q=what+are+virtual+functions+in+C%2B%2B"]this[/URL] kind of response too? | |
Re: No it dosen't matter. You are a computer scientist. But for your own good I would advice you to take trig based physics. In computer graphics programmer, you will use more trig and vectors than calculus. Its good if you know calculus with addition. Anyways, its your choice, why not … | |
Re: And lets be honest, there are people that just fall under the bell curve. Sometimes, they just either 1) Don't put in the time to learn 2) Give up after getting confused 3) Or just try to pass the class, w/o a care in the world of the subject. | |
Re: For this one : [code] If c >= 17 Then PictureBox17.Location = PictureBox16.Location End If If c >= 16 Then PictureBox16.Location = PictureBox15.Location End If If c >= 15 Then PictureBox15.Location = PictureBox14.Location End If If c >= 14 Then PictureBox14.Location = PictureBox13.Location End If If c >= 13 Then … | |
Re: Whats confusing about it? Maybe some pics will help : [code] //initial list 1->2->3->4->5->6 [/code] If I put [] around a number then thats the current pointer pointing to. So the pointer starts pointing to 1 so : [code] [1]->2->3->4->5->6 [/code] Let P1 be the current pointer, then from your … | |
Re: You know, this is just a suggestion so you don't have to listen. These methods : [code] double dist( Point ); void move( double, double, double ); [/code] I wouldn't make put them into the Point interface. Because I feel that they would be better of decoupled from the interface. |
The End.