2,712 Posted Topics

Member Avatar for l0v3csci

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

Member Avatar for Fbody
0
8K
Member Avatar for Joe Shmoe

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 …

Member Avatar for Taywin
0
220
Member Avatar for cwarn23
Member Avatar for Tom_Weston

once you do it manually, you'll learn to use the standard algorithm for this [icode] std::count(test.begin(),test.end(),'t')[/icode]

Member Avatar for mrnutty
0
104
Member Avatar for trantran

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?

Member Avatar for mike_2000_17
0
166
Member Avatar for Zvjezdan23

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

Member Avatar for mrnutty
0
329
Member Avatar for Student no.1

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

Member Avatar for Student no.1
0
278
Member Avatar for b3hr0uz
Member Avatar for Labdabeta

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 …

Member Avatar for Labdabeta
0
113
Member Avatar for lynn21

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.

Member Avatar for TrustyTony
0
240
Member Avatar for caut_baia
Member Avatar for lynn21

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

Member Avatar for lynn21
0
90
Member Avatar for falconmick

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

Member Avatar for mike_2000_17
0
439
Member Avatar for Xide

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

Member Avatar for mrnutty
0
167
Member Avatar for meli123

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

Member Avatar for mrnutty
0
96
Member Avatar for crownedzero

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

Member Avatar for mrnutty
0
111
Member Avatar for garu525

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 …

Member Avatar for mbundgaard
0
943
Member Avatar for meli123

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.

Member Avatar for doug65536
-1
273
Member Avatar for Majestics

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.

Member Avatar for diafol
0
199
Member Avatar for mrnutty

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 …

Member Avatar for chiiqui
0
449
Member Avatar for meli123

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]

Member Avatar for TrustyTony
0
297
Member Avatar for XodoX

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.

Member Avatar for XodoX
0
116
Member Avatar for coolbeanbob

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?

Member Avatar for mrnutty
0
215
Member Avatar for garu525

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 …

Member Avatar for Duoas
0
183
Member Avatar for oscargrower11

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

Member Avatar for oscargrower11
0
210
Member Avatar for NetJunkie

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 …

Member Avatar for mrnutty
0
200
Member Avatar for HelpStudents

Yes If you are allowed to use STL's list, then [icode] list<account> listOfAccounts[/icode] will do

Member Avatar for tajendra
0
387
Member Avatar for crapgarden
Member Avatar for ashishseo
0
209
Member Avatar for coolbeanbob

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.

Member Avatar for raptr_dflo
0
175
Member Avatar for ravanan
Member Avatar for tajendra
0
382
Member Avatar for siina

Check [URL="http://www.tizag.com/javascriptT/javascriptprompt.php"]this[/URL] out

Member Avatar for mrnutty
0
77
Member Avatar for narendra_kuma

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

Member Avatar for tajendra
0
104
Member Avatar for Soulreaverx7

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]

Member Avatar for mrnutty
0
138
Member Avatar for beau_nerdathen

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.

Member Avatar for mike_2000_17
0
5K
Member Avatar for Bench

Thats called [URL="http://www.cprogramming.com/tutorial/initialization-lists-c++.html"]Initializer list[/URL]

Member Avatar for Narue
0
3K
Member Avatar for ChaseRLewis

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 …

Member Avatar for ChaseRLewis
0
257
Member Avatar for termin8tor

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.

Member Avatar for termin8tor
0
275
Member Avatar for Oinkertop

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 …

Member Avatar for Oinkertop
0
148
Member Avatar for dusktreader

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

Member Avatar for GreenRiver
0
3K
Member Avatar for Bobbysmile

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

Member Avatar for Bobbysmile
-1
501
Member Avatar for nuclear

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.

Member Avatar for nuclear
0
119
Member Avatar for rina khatkar

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.

Member Avatar for mrnutty
0
160
Member Avatar for jonnyboy12

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

Member Avatar for mrnutty
0
112
Member Avatar for pseudorandom21

Blood, sweat and tears is my choice of drink and a true mans choice as well

Member Avatar for Niles64
0
331
Member Avatar for sergent
Member Avatar for MooGeek

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.

Member Avatar for Netcode
4
502
Member Avatar for Muralidharan.E

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

Member Avatar for Fbody
0
596
Member Avatar for dyingatmidnight

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 …

Member Avatar for ChaseRLewis
0
105
Member Avatar for bigdan182
Member Avatar for Shy01

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

Member Avatar for mrnutty
0
140

The End.