2,712 Posted Topics

Member Avatar for artur7

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. …

Member Avatar for mrnutty
0
132
Member Avatar for SacredFootball

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 …

Member Avatar for Moschops
0
195
Member Avatar for exca
Member Avatar for prosperr

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.

Member Avatar for mrnutty
0
124
Member Avatar for skorm909

Once you do a build from visual studio, the .exe should be in the project's directory. You can just run that.

Member Avatar for mrnutty
0
150
Member Avatar for moreautemps

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.

Member Avatar for mrnutty
0
91
Member Avatar for BowMadness

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.

Member Avatar for mrnutty
0
26
Member Avatar for o0sample0o

Google Arrays.sort. Just get the user input into an array, and use Arrays.sort( anArray), then the anArray is sorted.

Member Avatar for Eric Cute
0
1K
Member Avatar for eline83

[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 …

Member Avatar for eline83
0
120
Member Avatar for mrnutty

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.

Member Avatar for mrnutty
0
92
Member Avatar for Mr_PoP

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 …

Member Avatar for Mr_PoP
0
111
Member Avatar for caut_baia

[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

Member Avatar for mike_2000_17
0
109
Member Avatar for thekitoper

[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 …

Member Avatar for pseudorandom21
0
341
Member Avatar for XerX

@Op: I'm guessing you want something like so : [code] double randomReal(){ return double(rand()) / double(RAND_MAX); } [/code]

Member Avatar for MosaicFuneral
0
3K
Member Avatar for XerX
Member Avatar for mrnutty
0
4K
Member Avatar for bbman

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.

Member Avatar for Narue
0
167
Member Avatar for alonewolf23

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]

Member Avatar for mrnutty
0
135
Member Avatar for iamthesgt

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]

Member Avatar for mrnutty
0
218
Member Avatar for saleh-elyani

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); …

Member Avatar for saleh-elyani
0
160
Member Avatar for MrJNV

You can use [icode]cin.get()[/icode] to read each individual characters from the stream.

Member Avatar for mrnutty
0
167
Member Avatar for Hand

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.

Member Avatar for mike_2000_17
0
133
Member Avatar for Wej00

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{ …

Member Avatar for Banfa
0
1K
Member Avatar for MasterGberry

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.

Member Avatar for MasterGberry
0
156
Member Avatar for tchild

>>[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]

Member Avatar for ravenous
0
137
Member Avatar for imolorhe

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 …

Member Avatar for mrnutty
0
532
Member Avatar for simply_viks

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 …

Member Avatar for hillstone_softw
0
188
Member Avatar for stevanity
Member Avatar for MasterGberry

[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.

Member Avatar for MasterGberry
0
221
Member Avatar for Skyline8k
Member Avatar for Skyline8k
0
348
Member Avatar for MasterGberry

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 …

Member Avatar for MasterGberry
0
2K
Member Avatar for java1

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.

Member Avatar for mrnutty
0
125
Member Avatar for folwea

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); …

Member Avatar for mrnutty
0
130
Member Avatar for Arbus

[URL="http://www.cs.colorado.edu/~main/bgi/doc/initgraph.html"]Here[/URL] is its documentation.

Member Avatar for mrnutty
0
64
Member Avatar for LevyDee

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 …

Member Avatar for LevyDee
0
110
Member Avatar for stevanity

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.

Member Avatar for mrnutty
0
101
Member Avatar for Dorson8009

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[] = …

Member Avatar for Dorson8009
0
168
Member Avatar for alonewolf23

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 >> …

Member Avatar for alonewolf23
0
152
Member Avatar for prgmwitch

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& …

Member Avatar for mrnutty
0
241
Member Avatar for jitender939

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 := …

Member Avatar for Red Goose
0
122
Member Avatar for sahil1991

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 …

Member Avatar for sahil1991
0
216
Member Avatar for LevyDee

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.

Member Avatar for LevyDee
0
95
Member Avatar for matthewkeating

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 */ …

Member Avatar for mrnutty
0
128
Member Avatar for mrnutty

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. …

Member Avatar for Borzoi
0
171
Member Avatar for gilly231

Make sure your 1st derived print is virtual, if your second derived is derived from your first derived.

Member Avatar for gilly231
0
151
Member Avatar for AmerJamil

The 2D array does not really need a null character. Its the information contained inside that [I]might[/I] need it.

Member Avatar for mrnutty
0
55
Member Avatar for knotholaze

check out [URL="http://www.cplusplus.com/reference/clibrary/cmath/fmod/"]fmod[/URL]

Member Avatar for vijayan121
0
124
Member Avatar for jeffpro

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 …

Member Avatar for gerard4143
0
97
Member Avatar for techalerts
Member Avatar for JKP()
0
67
Member Avatar for Janes

What you need is [URL="http://download.oracle.com/javase/6/docs/api/java/awt/geom/GeneralPath.html"]General Path[/URL] to plot.

Member Avatar for mrnutty
0
133
Member Avatar for Akill10

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.

Member Avatar for Akill10
0
128

The End.