2,712 Posted Topics
Re: As to the original question [quote]Is it a good programming practice to not use getters and setters in trivial parts of code?[/quote] If you can you should avoid the getters and setters and create a function that already does what the user would do by using the getters and setters. … | |
Re: Why would it be [I]arrayEnd + 1[/I]? From tradition, [I]arrayEnd[/I] should already be 1-pass the end of the array. So using your function this call would be a bug : [code] const int S = 5; int array[S] = {0}; display(array, array + S); [/code] because you will be looping … | |
Re: If you can, eliminate all the pointers for const-reference. | |
Re: For the first one, the person a_i is in the subgroup iff there are 5 pairs such that an element from the pair is a_i. So you can use that as a clue. | |
Re: Once you do a build from visual studio, the .exe should be in the project's directory. You can just run that. | |
Re: Yea most tutorial you will find are depreciated. check out [url]www.gamedev.net[/url]. That is a very well know game development environment. They have many resources and tutorials you can learn from. Plus they have wicked smart and experience people there. | |
Re: Do yo know how to generate the random numbers? take a look [URL="http://www.cplusplus.com/reference/clibrary/cstdlib/rand/"]here[/URL] for some reference. | |
Re: Google Arrays.sort. Just get the user input into an array, and use Arrays.sort( anArray), then the anArray is sorted. | |
Re: [CODE]for(int i=1; i<N; i++) for(int j=1; j<N; j++) for(int k=1; k <= i*j*log(j); k*=2) x=i+j+k; [/CODE] Your first for-loop runs at most N times. And for each i, it runs at most N times, and for each j, it runs at most i*j*log(j) times Notice i and j is always … | |
If I use ProcessBuilder or Runtime.exec function, in a JApplet, does that applet needs to be signed or is there a way to get around this? I need to communicate with a C++ executable using java JApplet. | |
Re: You should either convert the [i]a[/i] into a string or adjust your parameters. For example : [code] template<typename ReturnType, typename InputType> ReturnType convertTo(const InputType& input){ stringstream stream; stream << input; ReturnType val = ReturnType(); stream >> val; return val; } //...your LOGMSG function int main(){ int a = 100; string … | |
Re: [QUOTE=caut_baia;1446466]Not quite but in this case you're perfectly right.I know it works that way though i was curious if i cand do it this way around.Thank you.[/QUOTE] yes you can use inline files | |
Re: [QUOTE=pseudorandom21;1446319]Yes, you can get your input into a string and parse it. [code] #include <string> #include <sstream> #include <iostream> using namespace std; int main() { <snip> stringstream(input) >> value; <snip> } [/code][/QUOTE] if that fails, stringstream throws and error so testing for 0 value is not a good option. And … | |
Re: @Op: I'm guessing you want something like so : [code] double randomReal(){ return double(rand()) / double(RAND_MAX); } [/code] | |
Re: check the [URL="http://www.cplusplus.com/reference/clibrary/cmath/modf/"]documentation[/URL] | |
Re: You only need to seed it once. So at the beginning of main, put the srand stuff. and take that out of your random function. | |
Re: You need to also make sure its on fixed format. Here is an example : [code] void printDollars(const float amount){ //save old states std::ios_base::fmtflags oldFlg = cout.setf(std::ios::fixed, std::ios::floatfield); int oldPrecision = cout.precision(2); cout << "$ " << amount << endl; //reset old states cout.setf(oldFlg); cout.precision(oldPrecision); } [/code] | |
Re: Try something like this. [code] string praseLine(const std::string& line){ /* prase the line and return the prased line */ } int main(){ string prasedContent; string fileName("test.txt"); ifstream fileIn(fileName.c_str()); string line; while( getline(fileIn,line) ){ string prasedLine = praseLine(line); prasedContent += prasedLine; } doStuff(prasedContent); } [/code] | |
Re: Your almost there. All you have to do is set the parameter to the function, for example you can do this : [code] void sort_sale(double sale[], int n); int main(){ const int n = 7; //... double sale [ n ] = {0, 0, 0, 0, 0, 0, 0}; sort_sale(sale,n); … | |
Re: You can use [icode]cin.get()[/icode] to read each individual characters from the stream. | |
Re: Just to point out, that you shouldn't really throw an exception unless its absolutely necessary. Like the name suggest, an exception should be thrown in exceptional cases. If you can handle the exception then do it, else you have no choice but to propagate it. | |
Re: Forget about Singleton, its an antipattern. For you case, go with a more object oriented approach and define the variables in a class or namespace with appropriate context. For example : [code] class Window{ public: static const int SCREEN_WIDTH = 100; //... }; [/code] or maybe : [code] namespace Environment{ … | |
Re: I'm still not exactly sure what you are trying to do. Can you give me a full example and then we can possible show you a non temporary solution. | |
Re: >>[B]Can someone explain to me what I am doing wrong[/B] EVERYTHING This is what you want : [code] #include <string> #include <iostream> using namespace std; int main(){ string line; getline(cin,line); //read a line /* do stuff with the line */ } [/code] | |
Re: Can you settle for something like this : [code] #include <iostream> #include <string> #include <sstream> #include <vector> #include <iterator> using namespace std; template<typename T> class Table{ private: class TWrapper{ private: T value_; bool isNull_; public: TWrapper(const T& val = T(), bool isnull = true) : value_(val), isNull_(isnull){} bool isNull(){ return … | |
Re: Your getting 64 because thats the size, you have a couple of options : 1) Use string 2) Use std::vector<char> 3) Append a null character at the end 4) Create a length variable to keep tract for example : [code] char msg = "12345"; //null character appended automatically int length … | |
| |
Re: [i]Comments[/i] is of type [i]string[/i] and std::remove returns a ForwardIterator, so your logic is incorrect. I think you want something like so : [code] string::iterator newEnd= std::remove(splitComment.at(1).begin(), splitComment.at(1).end(), ' ' ); item->Comments = string(splitComment(1).begin(),newEnd); [/code] I can't be certain without seeing more code. | |
Re: append an [i]else [/i] before the second and third ifs. | |
Re: Try this one: [code] #include <iostream> #include <string> #include <sstream> #include <vector> #include <iterator> using namespace std; vector<string> split(const string& src, const string& delim){ vector<string> result; string::size_type startPos = 0, endPos = 0; do{ endPos = src.find_first_of(delim,startPos); string::size_type length = endPos - startPos; if(length != 0) result.push_back( src.substr(startPos,length) ); startPos … | |
Re: First you need to play music, check [URL="http://download.oracle.com/javase/1.4.2/docs/api/java/applet/AudioClip.html"]this[/URL] out. Google and see what you get. | |
Re: A guess at what you want : [code] int n1 = 10; int n2 = 5; int n3 = 12; int min1 = std::min(n1,n2); int max1 = std::max(n1,n2); for(int i = min1; i < max1; ++i) cout << i << " "; int max2 = std::max(n2,n3); int min2 = std::min(n2,n3); … | |
Re: [URL="http://www.cs.colorado.edu/~main/bgi/doc/initgraph.html"]Here[/URL] is its documentation. | |
Re: I think he means to [i]delete tail[/i]. @OP: during a list implementation you will have a lot of transversal and deletion code, for that you might want to make a helper function to make your functions clearer. Also your code doesn't work if there is only 1 element, where the … | |
Re: For the first one, here are some hints : 1) Compute the distance from the first square(north-west) to the last square (south-east) and note that for each square there are upto 8 position on can move. | |
Re: Using boost would make it easier for you, for example : [code] #include <iostream> #include <string> #include <map> #include "boost/shared_array.hpp" using namespace std; typedef boost::shared_array<float> Array; typedef std::pair<string,Array> MapElement; typedef std::map<string,Array> Map; MapElement makeElement(const string& str,float* data){ return MapElement(str, Array(data)); } int main(){ Map m = Map(); float data1[] = … | |
Re: You need to seed : [code] #include <iostream> #include <ctime> char getRandomLowerCasedLetter(){ return 'a' + (rand() % ('z'-'a')); } int main(){ //seed the random number generator srand( time(0) ); bool keepPlaying = true; char winningLetter= getRandomLowerCasedLetter(); while(keepPlaying){ cout << "\nGuess a letter : "; char guessLetter = 0; cin >> … | |
Re: Your not going to be able to do this precisely with C++. You need to use graphics API like openGL. But here is some psuedo-code: [code] void showCoordinate(int x, int y){ string coord = "(" + toString(x) + "," + toString(y) + ")"; printOnScreen(coord); } template<typename T> string toString(const T& … | |
Re: Maybe some psuedo-code will start you up : [code] //assuming array column size is 3 function mySwap(Array2D array){ for row := 0 to array.length DO swap(array[0],array[2]) } [/code] And if you want it more general then you can do something like so : [code] function mySwap(Array2D array){ for row := … | |
Re: The best way is to get the original coder to explain it to you. If thats not possible, use the code( if you need to ) for your needs as long as you know what its supposed to do and not necessarily how it does it. If all fails then … | |
Re: Can you have [icode]void doSomething(BaseClass& b){...}[/icode] in your toplayer? Maybe you should show some code of exactly what you are trying to do. | |
Re: I will tell you int's will be faster than floats/doubles. And doubles will be faster than floats. But to answer your question yes, you can use [i]ctime[/i] header. Here is an example: [code] #include <iostream> #include <ctime> int main(){ time_t startTime = clock(); /* code to test goes here */ … | |
Anyone here have an facebook? I'm ready to reveal myself. Be aware, I'm kinda young, and I have a baby face, as I've been told. Anyways, here is firstPerson's true identity. I know i'm not very important, but you guys are like my online buddies. I feel at home here. … | |
Re: Make sure your 1st derived print is virtual, if your second derived is derived from your first derived. | |
Re: The 2D array does not really need a null character. Its the information contained inside that [I]might[/I] need it. | |
Re: check out [URL="http://www.cplusplus.com/reference/clibrary/cmath/fmod/"]fmod[/URL] | |
Re: Maybe this will help. [CODE]#include <iostream> using namespace std; int main(){ char sample[] = "3E"; int result[1] = {}; cout << "Encoding : " << sample << endl; result[0] = (sample[0] << 8) | (sample[1]) ; //encode cout << "Encoded value : " << hex << result[0] << endl; cout … | |
Re: Depends on what you know. But how about some simulation on pathfinding? | |
Re: What you need is [URL="http://download.oracle.com/javase/6/docs/api/java/awt/geom/GeneralPath.html"]General Path[/URL] to plot. | |
Re: For the second one. Remember, [i]toipArray[/i] can have its own address. What it points to is key. And in your case it points to an array of ints. If that didn't answer your question, then please re-phrase it. I wasn't able to read it clearly. |
The End.