2,712 Posted Topics
Re: Given we are at position (x,y) in a 2d Cell environment, its neighbors are [code] N[x][y+1] N{x+1][y+1] N[x+1][y] N[x+1][y-1] N[x][y-1] N[x-1][y-1] N[x-1][y] N[x-1][y+1] [/code] that assumes that the position (x,y) are not in the edge of the Array | |
Re: Having a scoring function on words, means having heuristic. Need to know what the problem is? Do you want more occurring words to having higher weight? Do you want longer length words to have higher weights? Do you want words that have vowels to have higher weights? You see you … | |
Re: when your dead you'll know. tell us about it | |
Re: once you do it manually, you'll learn to use the standard algorithm for this [icode] std::count(test.begin(),test.end(),'t')[/icode] | |
Re: If you have something like a factory pattern then you can enforce it, for example: [code] class CandyFactory{ private: struct ChoclateBar(){ int calories; ChoclateBar(): calories(){} }; public: shared_ptr<ChoclateBar> makeChoclateBar(){ return shared_ptr( new ChoclateBar() ) } }; [/code] I don't know if thats what you were asking? | |
Re: >>[B]getline(cin, first_sphere[3]);[/B] You want: [icode] cin >> first_sphere[0] >> first_sphere[1] >> first_sphere[2] [/icode] Also as suggested, move this code [code] float RadiusofTwoSpheres(float *sphere1, float *sphere2); { cout << "The Radius for Sphere's 1 and 2 is... " << endl; cout << endl; cout << "R = " << (float)sqrt(pow(sphere2[0] - … | |
Re: @op you are just having syntax issues. For your case to make a proper switch statement, you need to add the braces. Here is an example: [code] #include <iostream> using namespace std; int main() { int test = 1; switch(test) { case 0 : cout << "Option 0\n"; break; case … | |
Re: Well just giving it a [URL="http://codepad.org/0LRlMHY0"]try[/URL] shows that it becomes "X", with quotes. When you write ""string"", it doesn't make sense syntax wise because the first double-quote gets matched with the next double quote, and so on. Hence ""string"", gets interpreted as a empty string, followed by the identifier with … | |
Re: No you can't compare imaginary and real numbers like that. #2 and #3 are both false. And #1 and #4 are true. @OP, can you first show that 1 and 4 are true? Then show that 2 and 3 are false. | |
Re: A converse of a statement P->Q is Q->P, although it does not necessarily make it true. So all you have to do is change the P and Q position. Your answer looks correct | |
Re: [QUOTE=Narue;1653730]If you can suffer the extra storage cost while building the tree, place all of the pointers into an array initially, shuffle the array randomly, [i]then[/i] do the insertion: [code] { std::vector<mesh_t> v(62500); std::fill_n(v.begin(), v.size(), next_mesh()); std::random_shuffle(v.begin(), v.end()); for (auto mesh : v) tree.add(mesh); } [/code] Given a basic binary … | |
Re: [QUOTE=Narue;1654779]If he's lucky. More likely is that his instructor will go through the gamut of lower level and error prone C-style solutions, and only mention the "STL" in passing.[/QUOTE] Haha. When I took my first C++ class, we dealt with arrays extensively, 2-3 weeks. And towards, the end he introduces … | |
Re: [QUOTE=NathanOliver;1653323]A bool can be thought of as an int with a range 0f 0 to 255. As such a 0 means false and anything else is true.[/QUOTE] This is wrong. You shouldn't think of boolean data types as a integer with a range of 0-255. A boolean datatype usually consist … | |
Re: Consider using enums or contants for direction. For example: [code] #include <iostream> enum Direction{WEST,NORTH,EAST,SOUTH}; //assumes proper ordering, WEST = 0, NORTH = 1, EAST = 2, SOUTH = 3 string showDirection(const Direction& d){ const string encoding[] = {"WEST","NORTH","EAST","SOUTH"}; return encoding[d]; } int main(){ Direction currentDirection = WEST; cout << showDirection(currentDirection); … | |
Re: I never heard of 'inverted premutation' but it looks like your reversing the key to value mapping into value to key mapping. The fastest way you can do this is in linear time, since you have to go through the whole array, which your function does. But there are some … | |
Re: Idk if this works but maybe try out using this algebra: [code] 1/9 = 0.1111.... 9 * 1/9 = 9 * 0.1111 1 = 0.999.... [/code] See if you get similar result on a computer. | |
Re: Initially, I'd go with the C language. Because of its lacking of type-safety, there are many ways to hack a C program, or shall I say more opportunities. Also note that, C is meant to be a subset of C++, so you do you Security Analysis using C++ as well. ![]() | |
Start thinking about the things you use to do before you ever knew about programming and now think about how you changed that as a result of programming? What was it? As an example, I always use to start numbering from 1, but after taking my first programming course and … | |
Re: Easy way is to use std::string [code] #include <iostream> #include <string> #include <algorithm> using namespace std; int main(){ std::string input; cin >> input; for(int i = 0; i < input.size(); ++i) { cout << input[i] << endl; } //sort it std::sort( input.begin(), input.end()); cout << input << endl; } [/code] | |
Re: Its up to you, you can scan through a instance of '+' and assert that there are numbers in the left and right of it, and the same for '*'. Try looking into 'postfix' as well. | |
Re: If you are using std::stack, then there isn't any concept of iterators for std::stack, which makes sense. As for your question, you can copy the stack content if needed. But it looks like you shouldn't be using stack in the first place? | |
Re: Something you can try, 1) Create tokens from data, are garu suggested. 2) Insert those tokens into a vector 3) Call std::partition on the vector giving it your own comparison 3.a) You own comparison, could return true if the token is digit, thus separating digits from strings 4) From there … | |
Re: >>[B] cin >> a >> b >> read_hw(cin, homework);[/B] that essentially turns into [icode] cin >> cin [/icode] which doesn't make sense. I agree, for your function, read_hw you should make it void. Enabling syntax such as [icode]read_hw(cin,homework) >> a >> b [/icode] is obfuscated. Just think read_hw as a … | |
Re: If its to learn C++, then I suggest you to do this. 1) In a file list all of the participants name 2) From your program, read/store the participants name 3) Pick a random name and output It will be easier if your program just shows the random person's name … | |
Re: Yes If you are allowed to use STL's list, then [icode] list<account> listOfAccounts[/icode] will do | |
| |
Re: This right here [CODE]friend ostream& operator<< <T>(ostream& os, const List<T>& s); [/CODE] is invalid syntax. It should be [CODE]friend ostream& operator<< (ostream& os, const List<T>& s); [/CODE] Also make sure your implementation of the List is in the same file as the definition, since its templatized. | |
Re: use the inline keyword. Note that the compiler can choose not to respect your request. | |
Re: Check [URL="http://www.tizag.com/javascriptT/javascriptprompt.php"]this[/URL] out | |
Re: I don't know what you are asking for but you need to [i] cin >> v.a >> v.b [\i]. Make sure you define [i] var v [/i] before using it in cin | |
Re: If your trying to implement copying files then you can do something like this. [code] int main(){ ifstream inputFIle('input.txt'); ofstream outputFile('out.txt'); char ch; while( inputFile.get(ch)) outputFile.put(ch) } [/code] | |
Re: Do you know how to create a pascal triangle without recursive? If so then doing it recursive won't be that far off. Give it a go and see what happens. | |
Re: Thats called [URL="http://www.cprogramming.com/tutorial/initialization-lists-c++.html"]Initializer list[/URL] | |
Re: Another option is to create a hash given the class information. [code] #include <iostream> #include <typeinfo> #include <string> using namespace std; size_t hash(const std::string &data) { size_t h = 0; for (unsigned i=0; i < data.size(); i++){ h = (h << 6) ^ (h >> 26) ^ data[i]; } return … | |
Re: First you loop solution is very inefficient, with regards to opening and closing files. Just open it once and close it once. Next a solution to your problem is to have the classes have its own extraction operator. Check [URL="http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/"]this[/URL] link for more details. | |
Re: umm something like so: [code] struct ConstantRandom{ int randNum; bool isFirstTime; ConstantRandom(): isFirstTime(true), randNum(0){}; int operator()(){ if(isFirstTime){ randNum = rand(); isFirstTime = false;} return randNum; }; int main(){ srand( time(0) ); ConstantRandom cr; int i = cr(); //i equals some random number int j = cr(); // j should equal … | |
Re: Let me spell it out to you : [B]main.cpp: In function ‘int main(int, char**)’: [/B] Inside your main function [B]main.cpp:15: error: no match for ‘operator*’ in ‘d * 1.0e+0’[/B] There is no matching function function in the call :"e = d * 1.0;" [B]derived.h:15: note: candidates are: double Derived::operator*(const Derived&) … | |
Re: [QUOTE=WaltP;1613130]Not a clue. Can't read the error message, you don't tell us what line it's on, and your indenting is baaaad.[/QUOTE] Give people some break would you. Not all are fluent in english or do they have enough skills to communicate in english. And since he is a beginner, one … | |
Re: Why don't you move away from console application, and move into more graphics? Use libraries like SDL to make a simple 2D game. That way you will enjoy what your doing and you will be learning. | |
Re: One has the value zero and the other one has the value one. That's the only difference. Its how you interpret the values that matters. For example you interpret the return value of zero as failure, or something else like true. Its all up to the programmer. | |
Re: [QUOTE=jonnyboy12;1627682]Hello, i have been coding for quite a while now. Up until now i have not figured out weather or not to do this. [CODE] somthing * newsomthing; newsomthing->funtion(); [/CODE] or this [CODE] somthing newsomthing; newsomthing.function(); [/CODE] I know what a pointer is , but often i dont know weather … | |
Re: Blood, sweat and tears is my choice of drink and a true mans choice as well | |
Re: The first one is 'using' the second one is 'creating'. | |
Re: I'm quitting-ish it as well. I disabled viewing my profile by everyone except me. THe only reason I use FB is to see how my friends are doing, and occasionally talk to few of them. | |
Re: >>[B]This is static polymorphism in C++:[/B] I don't get why that's called static polymorphism? All that's doing is generating multiple function for each type. There is nothing polymorphic about it. Polymorpic is more like a 1->many relationships, while that's like 1->1 relationship, that is each type has its own function. … | |
Re: You are trying to fit 6 bytes into 2, in general it's not possible, unless the data in bcd are very trivial or you can compress it. What kind of data does bcd hold? It might be possible if the data in bcd are small enough that you can use … | |
Re: [QUOTE=Shy01;1620828]hello am new here.. can somebody tell me if there's a restriction for a decimal numbers entered? for instance, cout<<"Enter number: " cin>>num; --- if the user put a decimal number on the variable num.. i want this to be INVALID INPUT in the terminal screen as a result. any … |
The End.