mrnutty 761 Senior Poster

Once you create a facebook, there is no reason to delete it completely. You can use it to your advantage,just filter out the bad and leave only the good for future employers to see.

mrnutty 761 Senior Poster

^^ does the same thing apply to orkut, because i deleted my account few days back

sorry, idk about orkut, didn't even know it existed.

mrnutty 761 Senior Poster

>>aren't portable for various reasons such as being overloaded

what are the other reasons?

mrnutty 761 Senior Poster

Should u not decrement objectCount in Destroy function?

mrnutty 761 Senior Poster

From the presented solution, IMO OP solution is better. Reasons being( in no order ),

1) Less to Type
2) Less chance to get wrong
3) Follows Idiom better( reuse )
4) Possibly faster
5) Cleaner
6) Safer
7) Is more C++ than C

mrnutty 761 Senior Poster

Can this not be done without a constructor?
Because we haven't learnt that yet... it's our next chapter, though.

Yes, it can. A viable solution to this problem is to create a base counter class that is templatized. But I assume you haven't learn that before. So for now you can just create a counter variable and increment it in the proper place and decrement it in proper place. As suggested, use a static count variable, ex.

class People{
private:
 static unsigned PEOPLE_COUNT; //this creates one people_count variable for all class People class object
public:
 People(); //increment it here
 ~People(); //decrement here
 People(const People& p); //what is this, what should u do here?
 People& operator=(const People& p) ; //what should u do here?
 //...are there any other place you should worry about?
};
mrnutty 761 Senior Poster

threse is just 'theres' scrambled up.

This is part of the criteria for the game he is writing. So the human guessing not only has to guess subwords but the entire word as well, that's why the original is scrambled up.

Oh I get it. Computer picks a work, scrambles it up. The client tries to guess the maximum possible word from the given jumbled word. But I still don't see where he needs to generate any permutation.

mrnutty 761 Senior Poster

But from your given example, the subsetOf(theres) == subSet(threse).

I figured that was a miscommunication from the OP originally.

mrnutty 761 Senior Poster

For 1, you choose A, which is correct.

For 2, your almost there but its not correct, because there are 2 nested loop you have to take into account both of them.

For 3, redo 2 then see what you get. But your almost there.

mrnutty 761 Senior Poster

Actually, picking a correct data structure for THIS problem is largely a red herring.

In fact, reading in the entire dictionary file for each go and using a letter frequency algo is sufficient and should cause no significant time lag - unless you're using a computer from the dark ages.

Typically, the student when faced with the age old problem, 'Given a set of scrambled letters, find all sub-words and exact words' tend to go down the permutation route.

This is most probably what the OP means by optimization. Anyone who has written a permute algo knows how expensive it is.

This is where the letter frequency algo wins on all counts. Of course, you can implement a std::set WITH the letter frequency algo which would make it all the faster. But in terms of optimization it is hardly noticeable.

I don't get why he would even want to consider permutation/combinations? The users, i.e the client provides the computer with the subword to check, all his program has to do is, check if that subword is part of the dictionary. The only optimization OP has to do is to pick the right data structure, and be at least decent with the coding.

mrnutty 761 Senior Poster

Man, I start my internship tomorrow, so idk, how much time leisure time I'll have to program. Hopefully, I won't be too busy.

mrnutty 761 Senior Poster

No it deactivates it, but if you sign in within 2 weeks it reactivates it for you. If you pass the 2week period then they 'delete' it, but they might have you still on their database who knows. If you want to stop using it for a bit, then tell your friend to change your password and not give it to you until a week or so.

mrnutty 761 Senior Poster

How to round a number like 1678.5445 to 1678.6?.

Do you really need to round it like that? What benefit would that give you? Its questionable if it should even be rounded that way.

mrnutty 761 Senior Poster

Forget about reading it in an array. Use the correct data structure. Lookup hashtable, which is just created for situation like these, lookup. Using hashTable, you can lookup in the dictionary on average on constant time, as well as insert in constant time.

Basically, thats all the optimization you need. Rest is just implementation.

mrnutty 761 Senior Poster

@firstPerson


Statements like this bother me because areas in which something like this might be practical are so well funded and probably top-secret there is no way in hell that you know that. You might be surprised.

Your right. I'm in on position to claim such a thing, because I do not work with the leading speech recognition company, however just doing some research for example this, states that with just a vocabulary of 1000 words, the state of the art speech recognition is about 97% accurate. Now you might its pretty good, but thats under controlled condition, hence not in general, and also realize that on average humans have a range of vocabs from 10k to 150k, thus the error rates naturally increases as observed experimentally*. The military probably have some of the smartest people in the world working on such things, but at least to the general public, there is no perfect speech recognition software, for the general case. Although there are probably some that are very good.

mrnutty 761 Senior Poster

Whats the problem with loading the bitmap from a file in the same directory?

mrnutty 761 Senior Poster

Your question is kind of vague, but possible any one of these :

string->size(); //if you are using std::string *
strlen(string); //if you are using c-style string
mrnutty 761 Senior Poster

Also note, you might think about using std::stack because of its stack property, when you insert data in it, you will effectively have it in 'reverse'. Example :

#include <iostream>
#include <stack>

template<typename T>
class Reverser{
private:
 typedef std::stack<T> Container;
private:
  Container _cont;
public:
 template<typename Iterator>
 Reverser(Iterator begin, Iterator end){
    while(begin != end){ _cont.push(*begin++); }
 }
 void displayReverse(){
   Container c = _cont;
   while(!c.empty()){ cout << c.top() << " ";  c.pop(); }
 }
};

int main(){
 int A[5] = {1,2,3,4,5};
 Reverser<int> rev(A,A+5);
 rev.displayReverse();
}

its not the proper way of doing a reversal, especially when your only printing them, but its a different way about thinking it. You should examine all ways and pick the best one for your situation.

mrnutty 761 Senior Poster

:) I like that idea. I would rather work on voice sampling software, the kind that takes a sample, analyzes it, and simulates speech.

I'm using C# to make a game plan creator for my Americas Army 2 gaming buddies. It's almost done, just a minor bug left--and it should be pretty useful when we want/need to use it.

Also working on some input mapping software for the xbox 360 controller, and keeping my mind open to new ideas.

You have no idea how hard voice sampling is. There is no software out there that has perfect speech analyzer, because of how much speech can vary, and just a little variation can cause a lot of trouble. Right now I don't have enough math skills to tackle such software, but I gotta start somewhere.

mrnutty 761 Senior Poster

Anyone here working on some project? I'm just curious on what people here work on? Maybe its a job or maybe a virus to steal bank accounts, either way, don't hesitate not to say and announce it here. This could potentially give others ideas on what their next project should be. As for me, right now, I'm working on music visualization software.

mrnutty 761 Senior Poster

Every update cycle you move the guard to the left, if it hits the wall, move it to the right, and repeat.
Thats all you need to do. Here is an example :

#include <iostream>
#include <ctime>
#include <string>
#include <vector>
using namespace std;


using namespace std;

void updateMap(std::vector<string>& map);
void displayMap(const std::vector<string>& map){
	for(int i = 0; i < map.size(); ++i) cout << map[i] << endl;
}
void clearScreen(const int N = 10){
	//crude way
	for(int i = 0; i < N; ++i) cout << "\n";
}
int main() {

	srand( time(0) );
	std::vector<string> maze;
	const char GUARD = '#';
	//update every x millisecond
	const int UPDATE_TIME_IN_MILLISECONDS = 1000;
	maze.push_back("XXXXXXXXXXXXXXXXXXXXXXXXX");
	maze.push_back("X                      XX");
	maze.push_back("X     XXXXXXXXXXXXXXXXXXX");
	maze.push_back("X                      XX");
	maze.push_back("X           #          XX");
	maze.push_back("X                      XX");
	maze.push_back("X                      XX");
	maze.push_back("X XXXXXXXXXXXXXXXXXXXXXXX");
	maze.push_back("X                      XX");
	maze.push_back("XXXXXXXXXXXXXXXXXXXXXX XX");
	maze.push_back("X                      XX");
	maze.push_back("XXXXXXXXXXXXXXXXXXXXXXXXX");

	long startTime = clock(); //start time in millisecond
	//game loop
	while(true){
		//check if we should update now
		if(clock() - startTime > UPDATE_TIME_IN_MILLISECONDS){
			updateMap(maze); //update guard position
			displayMap(maze);
			//clearScreen();  //use API method if you have it
			cin.get(); //inserted this so its easier for you to see and debug
			startTime = clock();
		}
		else{
			//wait it its time to update
		}
	}
	return 0;
}

void updateMap(std::vector<string>& map){
	static bool shouldGuardMoveLeft = true; //start out by moving left initially
	//just looking at the map, you would probably want ot calculate it in a class
	const int GUARD_POS_Y = 4;
	const char WALL = 'X';
	if(shouldGuardMoveLeft){
		string& str = map[GUARD_POS_Y]; //find the string that contains '#'
		string::size_type pos …
mrnutty 761 Senior Poster

You can add '#' character as a guard or some other character, and have it move for example from a left wall to right wall

mrnutty 761 Senior Poster

Chocking a chicken that's the best anyone could think of?

Have a big pot of some black coffee, break out the full flavored smokes and lean back to scan the room, letting it all settle in, you ponder why you've confined yourself in a room to stare at the glowing box with its radiant warmth. How long till your eyes ache, and you're regretting your missing time?
You've got beat this addiction, before it has you injecting pure internet forums intravenously, in the back of a hotel alleyway.

Sounds like a good time. I'm sure OP is just going through a phase. I was addicted to internet forum at one point ( lol ).

@OP, gather some friends, and go to movies, go clubbing, go out! Get away from the house. Go workout. Learn something new, how old are you?

iamthwee commented: Sounds like you got the overall balance just about right. +0
mrnutty 761 Senior Poster

>>Can We find any Number through binary search in 33 size array?

As long as the number is in the array and the array is sorted.

mrnutty 761 Senior Poster

>>but also need to render the material as the image indicate.
Explain to me what that means. I can speculate but don't know for sure.

>>Why is my thought invalid though?
Initially, you said 2d space which means that a 3D object can be modeled in 2D space.

Now that I know you need to model 2D shape, you can go with your idea. What graphics library are you using to render the image?

mrnutty 761 Senior Poster

Check out blender, others are 3DS Max and Maya, here is a list, http://en.wikipedia.org/wiki/3D_computer_graphics_software

mrnutty 761 Senior Poster

It might be possible but it would be a lot of work, and might not be worth it. Is this just for curiosity or a project or something else?

mrnutty 761 Senior Poster

Google cctype library. Here is an example :

string n = "1232"
bool isNumber = std::count_if( n.begin() , n.end() , isdigit) == n.size(); // check if all element isDigit

The few function you would want to take a look at are isdigit() and isalpha() .

mrnutty 761 Senior Poster

As suggested the easiest way to achieve it is using std::string as follows:

std::string getClampedInput(const int maxSize){
 string str;
 getline(cin,str);
 int clampedSize = maxSize > str.size() ? str.size() : maxSize; //make sure maxSize is not greater than input size
 return str.substr(0,maxSize);
}

another way is to do it is using cin.get, but the above method is the easiest.

mrnutty 761 Senior Poster

First you have to think if your idea is valid? Even though you are modeling the shape in 2D space, the object to be modeled could still be 3D( is it? ). If it is, then you might be better off trying to model it mathematically, rather than importing it as a picture then applying clever transformation on the image.
What exactly does the shape look like? And as for you initial question, use a external library to import the picture. Then you can use your graphics library or some library to put the image to the screen.

mrnutty 761 Senior Poster

you can use std::sort. Here is an example :

struct DaniwebMember{
  int ranking;
  int age;
  DaniwebMember() : ranking() , age() {}
  DaniwebMember( int r , int a ) : ranking(r) , age(a){}
};
bool compareByRanking(const DaniwebMember& m1, const DaniwebMember& m2){ return m1.ranking < m2.ranking; }
bool compareByAge(const DaniwebMember& m1, const DaniwebMember& m2){ return m1.age < m2.age; }

int main(){
 DaniwebMember members[100]; 
 //populate members ...
 std::sort( members , members + 100 , compareByAge ) ;//sort by age
 std::sort( members, members + 100, compareByRanking ); //sort by ranking
}

so you see, all you have to do is create a compare function and pass it onto std::sort

mrnutty 761 Senior Poster

I think the simple approach would produce good results, that is defining some DistanceSplit value. For example, consider the data below.

[ 4 12 13 21 30 38 39 45 60 84 90 91 95 96 97 109 113 114 128 148 149 163 175 180 182 184 192 ]

say the distance split is 10, then we would have the following subset
[ [4,12,13,21,30,38,39,45] , [60] , [84,90,91,95,96,97] , [109,113,114] , [128,148,149,163] [175,180,182,184,192] ]

Obviously the lower the distanceToSplit value the more subsets you will have. You can calculate the distanceToSplit by using factors such as the mean,variance and standard deviation.

Does the given data follow some type of patterns?
What does the data represent?
Given the above sample data, what would be the 'correct' subset to you? Can you give us more information on the problem this is going to solve?

mrnutty 761 Senior Poster

Your terms are way to vague. Judging from your example, you can do something like this :

1) Sort the set
2) Define a MIN_DISTANCE_TO_SPLIT
3) Keep a beging / end pointer, both pointing to the start of the sorted list
4) Move the end pointer until a difference of MIN_DISTANCE_TO_SPLIT is observed from element i to i+1 or until you get to the end of the list
5) Now create a subset from [beginPointer,EndPointer]
6) Set begin pointer to endPointer + 1
7) Increment endPointer
8) Repeat from step 4, until an invalid endPointer


What are you trying to solve with this anyways?

mrnutty 761 Senior Poster

You need to understand .bmp format first. As always Wiki has a great article on its format. You need to read in specific things before you read the actual pixel first. If you really just want to learn then you can go read the article and work from there, if you just want to get a picture in the screen first, then learn later, then go use a external library that does the work for you already.

mrnutty 761 Senior Poster

U+0020 is the code for whitespace. So you have a whitespace at the end of your sentences in your file.
Run through the file and remove any whitespace at the end of the sentence. Alternatively, you can create a trim function that removes whites spaces from the front/end.

mrnutty 761 Senior Poster

Find a hobbie.

- Workout
- Sports
- Poker?
- Get a new look
- Go hang with friends
- masturB**e

mrnutty 761 Senior Poster

You can do it through a conversion operator :

class PositiveInteger{
  int i;
public:
  PositiveInteger(int i1 = 0 ) 
   { i = i1 <  0 ? 0 : i1; }
  operator int(){ return i; }
};
int main(){
 PositiveInteger i(23);
 int j = i; //convert to int
}
pseudorandom21 commented: I learned something. +6
mrnutty 761 Senior Poster

1) Replace all instance of 'char' with std::string in your program
2) Don't use 'goto', use conditional loops instead. Imagine there were no 'goto' command, how would you restructure your program accordingly?

mrnutty 761 Senior Poster

To expand on what has been said you can use break to break out of the loop and continue to skip the current execution for example :

for(int i = 0; i < 5; ++i){
  if(i == 3) break;
}

will break out of the loop that is exit out of the loop when i == 3 is true.

Similarly, the code:

for(int i = 0; i < 10;++i){
  if( i % 2 == 0 continue; //if i is even then skip to next iteration but does not exit out of the for loop
}
mrnutty 761 Senior Poster

Seems pretty easy, all you have to do is use the points to calculate the 6 lines. So you can calculate a line from (1,1) to (1,3) then from (1,1) to (3,1) then (1,1) to (3,3) and so on. So to start

1) Create a function that calculates the slope given two coordinates
2) Create a function that takes a slope and two coordinates and prints all values between the two coordinates
3) Apply the above procedure for the six lines you need.

mrnutty 761 Senior Poster

Casting in that example if fine. But looking at your code, you are probably going to want to encapsulate the member variables, that way operator< does not have to be a friend function.

#include <string>
#include <iostream>
using namespace std;

class StrategyKey
{
public:
	StrategyKey(){}
	~StrategyKey(){}

	StrategyKey(const char* strA):
		str_strategy(strA)
	{}
       virtual const std::string& getStrategyValue()const{ return str_strategy; }
private:	
	std::string str_strategy;
};

class TechniqueKey : public StrategyKey
{
public:
	TechniqueKey(){}
	~TechniqueKey(){}

	TechniqueKey(const char* strA, const char* strB): StrategyKey(strB),
		str_technique(strA)
	{}
        const std::string& getStrategyValue()const{ return str_strategy; }
private:
	string str_technique;
};

bool operator< (const StrategyKey& stratKeyA, const StrategyKey& stratKeyB){
 return stratKeyA.getStrategyValue() < stratKeyB.getStrategyValue();
}

bool operator< (const TechniqueKey& stratKeyA, const TechniqueKey& stratKeyB){
 const int cmp = stratKeyA.getStrategyValue().compare( stratKeyB.getStrategyValue() );
 if( cmp != 0 ) return cmp < 0;
 else{ //same so compare base values
   return dynamic_cast<const StrategyKey&>(stratKeyA) < stratKeyB; 
 }
}
Jsplinter commented: Thanks! I need to read up on friend functions. +2
mrnutty 761 Senior Poster

>>Is there a way I can find the list of sets of Coordinates on it's parameter?
>>The expected out put should be:

I still don't know what exactly you mean by that. Can you explain a bit more.

mrnutty 761 Senior Poster

>> while((e!=0) || (i<5));

I think you want to change that to while((e!=0) && (i<5)); I would suggest restructuring your program using functions and std::vector

mrnutty 761 Senior Poster

Also check out HMM

mrnutty 761 Senior Poster

Why cant you just center it at position 0?

mrnutty 761 Senior Poster

First how are you storing the data types?

mrnutty 761 Senior Poster

Maybe your thinking this is java or something. In C++ this is how you would sort any data type:

#include <vector>
#include <algorithm>
using namespace std;

int main(){
 std::vector<int> integerArray;
 integerArray.push_back(1);  
 integerArray.push_back(102);
 integerArray.push_back(-23);
 integerArray.push_back(1);

 std::sort( integerArray.begin(), integerArray.end() ); //sort the integer array 
}

you would do similar for any data type, although you might have to specify an explicit comparator

mrnutty 761 Senior Poster

1) Make sure you spelled it correctly
2) If its on another file, make sure you import it using #include "insertHeaderNameHere.h"
3) Else post your code

mrnutty 761 Senior Poster

>>the program should check if all even integers from low to high can be written as the sum of two prime numbers

So if one test fails in that range then the whole test fails? I'm sure I can prove that given a range of x to y
that there has to be at least one number that doesn't sum from 2 prime

mrnutty 761 Senior Poster

Can you modify the function so that it needs ints or make it template?