mrnutty 761 Senior Poster

This

printf("no. rows: ");
int row=GetInteger();
printf("\nno. columns: ");
int column=GetInteger();

Is not going to work. Have Row and Col be a big number.
Then ask the user to input row and col and use that.
For example :

int main()
{
 const int MAX_ROW = 200;
 const int MAX_COL = 200;
  char Array[MAX_ROW][MAX_COL] = {0};
  int ROW = 0;
  int COL = 0;
  cout << "Enter row and column :  ";
  cin >> ROW >> COL;

  //now use Array, thinking that ROW and COL are its limit.
}
mrnutty 761 Senior Poster

Well you can use 1d array to represent 2d array. Or you can create a
2d array at runtime, or you can use 2d array of vectors. Show your code as
of now and let see.

mrnutty 761 Senior Poster

This :

class Test{
int i;
public : 
 Test() : i(0){}
};

is very similar to this :

class Test{
int i;
public:
Test(){ i = 0; }
};

The only difference is that the first one is more efficient, and as pointed
out, its called an initializer list.

mrnutty 761 Senior Poster

Ok thanks for helping me now I just have to fix the errors.

The errors are from ROW and COL, you have to define them.

mrnutty 761 Senior Poster

Good. Now combine everything together to get this :

void Fill(char Array[ROW][COL], int row, int col )
{
	if(row < 0 || col < 0 || row > ROW || col > COL) 
		return;
	else if(Array[row][col] == '#' || Array[row][col] == '*') 
		return;
	
	Array[row][col] = '*';
	
	Fill(Array,row+1,col);//down
	Fill(Array,row-1,col);//up
	Fill(Array,row,col-1);//left
	Fill(Array,row,col+1);//right
}
mrnutty 761 Senior Poster

Ok so now we know that , Fill(Array,i+1,j); is down. So whats up? Hint the opposite.

mrnutty 761 Senior Poster

No realize that (i+1,j) , (i+2,j) ... was showing you a sequence.
In code the sequence is generated by the code.

Remember that in array, moving down amounts to increasing the y,
while moving up amounts to decreasing the y. Its not like the
Cartesian coordinate system.

In array its like so :

//column
   0 1 2 
{ a b c } 0 //row
{ d e f } 1 //row
{ h i  j } 2 //row

See that row 2 is lower than row 1, thus as row increases, we are
going down the array.

mrnutty 761 Senior Poster

You know we have to now move around the array and fill it.
We can do something like this :

void Fill(char Array[R][C], int i, int j )
{
	if(i < 0 || j < 0 || i > R || j > C) 
		return;
	else if(Array[i][j] == '#' || Array[i][j] == '*') 
		return;
	
	Array[i][j] = '*';
	
	Fill(Array,i+1,j);
        //more Fill(...)
}

The code Fill(Array,i+1,j) fills the array down from its starting position.
Now we need to also fill it left, right, and up. What do you think
the definition for LEFT, or RIGHT, or UP should look like.

mrnutty 761 Senior Poster

I'm not sure because the normal r+1, j+1, r-1, j-1, etc wouldn't work since the length and width can change depending on the user.

Well we know that we have to start within the the walls. It would
not make sense that we start at the position of the wall. So for now
say we started at the middle of the hollow array. How would you
make it so that we transverse in all direction, left,right,up and down?

mrnutty 761 Senior Poster

Yes that part of it. You have the part that does the actual filling.

So you have added this to the function.

void Fill(char Array[R][C], int i, int j )
{
	if(i < 0 || j < 0 || i > R || j > C) 
		return;
	if(Array[i][j] == '#' || Array[i][j] == '*') 
		return;
	
	Array[i][j] = '*';

  //move position
}

Now as you can see, we need to move the position. Since this is an
array we can only move up , down , left, or right. How would
you move the array while making sure that it will be filled? (Hint : recursion )

>> And I wouldn't use an else?
It does not matter.

mrnutty 761 Senior Poster

So our base case checks if the index is valid, i.e if its positive and within the bounds of the array. Another base case we have is to check
if the value at Array[j] hits the wall or if its already occupied.
In real code This would be our code so far :

void Fill(char Array[R][C], int i, int j )
{
	if(i < 0 || j < 0 || i > R || j > C)  //if !(positive and within bounds)
		return;
       //if we hit a wall or if its already filled 
	if(Array[i][j] == '#' || Array[i][j] == '*') 
		return;

  //logic goes here

In the logic goes here what do you think we need to do? Also for your char shape[][], the column needs to be specified, so you need to do something like this , char shape[][COL], where COL is a const variable declared somewhere in global or something.

mrnutty 761 Senior Poster

Well the base case should be something like this :

if coordinate is invalid return;
else if value at index (i,j) == Wall, return;
else ...
mrnutty 761 Senior Poster

Ok think about it.

1) We have a wall, '#', where if we reach that wall we need not to draw
2) We have a (row,col) inside the rectangle, which will be our starting point
3) What we need to do is fill the whole rectangle.

One way to do this is use a recursive function.
From our starting point, we should move left , right, up, and down,
while filling the array as we move. And if we hit a wall, '#', then we
should return. From this statement can you deduce what the base
case should be?

mrnutty 761 Senior Poster

Ok you know that for every recursive function we need a base case, right?
Otherwise the stack will overflow, memory overloaded?

So before we get to the base case. Do you have any idea on how
the fill function might work. For example we could linearly go through the
whole array and look for a space and replace it with asterisk, but thats
not allowed.

mrnutty 761 Senior Poster

Ok, give me 1 quick example of recursion. And FYI, I am going somewhere with this.

mrnutty 761 Senior Poster

Ok. Did you know learn about recursion?

mrnutty 761 Senior Poster

If I am reading this correctly, then what you have is a blank square
like so :

#####
#   #
#   #
#####

or something similar. To that. Then the uses specifies the row and the
column or the (x,y) coordinate, per say, that is within the space of
the square. For example it could be this :

#####
#   #
# s #
#   #
#####

the "s" represents the start coordinate. Now you need to fill the
rectangle with some characters? Before I say something, Are these
assumptions correct?

mrnutty 761 Senior Poster

What you should do is create a 2D array class. Then use a vector to hold it. Here is what I mean :

std::vector< Array2D > vecOfArray2D;
 int size = 0;
 cin >> size;
 vecOfArray2D.resize(size);

The Array2D is a class that you should implement.

mrnutty 761 Senior Poster

I would like to go for 7 :) though i think its gonna be harder than learning Java...
Any comments(or help or recommendations will be highly appreciated ;P)?

Seriously, instead of wasting your time asking people for what you
should learn, you could have picked a subject and started learning already.
Just Pick One and go. Run and don't look back, unless you see that hot girl.

mrnutty 761 Senior Poster

Looks like your vertices are not correct. Have you tried to load
a simple mesh first?

mrnutty 761 Senior Poster

Make use of the string functions like find_first_of and so one.
For example you can do something like this :

string vowels = "aeiou";
string sentence = "hello baby!";
if(sentence.find_first_of(vowels) != string::npos){
 cout << "There is a vowel in " << sentence << endl;
}
mrnutty 761 Senior Poster

Next step ? Pick one ;

1) Learn more about C++, for there is practically no limit.
2) Learn more about algorithms and data structures
3) Learn about design patterns
4) Pick a similar language, java , C# ?
5) Pick different language like haskel, php?
6) Go buy stocks?
7) Find a hot girl?

mrnutty 761 Senior Poster

Come to think of it. Make a function for everything.

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

//supports hex, dec and octal
//base can only equal decimal(10),octal(8),or hex(16)
template<typename ReturnType, typename InputType>
void convertBases(const InputType& src, ReturnType& dest,const int base,bool showBase = true)
{
	stringstream stream;
	
	if(showBase) 
		stream << showbase;	

	switch(base)
	{
	case 10: stream << dec;  break; /* dec by default but...*/ 
	case 16: stream << hex;  break;
	case 8:  stream << oct; break;
	default: throw std::exception("Base not supported"); break;
	}
	
	stream << src;

	if(!(stream >> dest) ){
		string errMsg = "Conversion failed\n";
		errMsg +=  "Tried to convert \"" + string(typeid(src).name());
		errMsg +=  "\" into \"" + string(typeid(dest).name()) + "\"";
		throw std::exception(errMsg.c_str());
	}	
}
int main(){
	const int decValue = 15;

	enum{ HEX = 16, DEC = 10, OCT = 8 };

	string hexValue;
	string octalValue;
	string deciValue;

	try{
		convertBases(decValue,hexValue,HEX);
		convertBases<string>(decValue,octalValue,OCT);
		convertBases<string>(decValue,deciValue,DEC);
	}catch(std::exception& e) { 
		cout << e.what() << endl;
		return -1; 
	}

	cout <<"For " << decValue << " : \n";
	cout << "hexValue = " << hexValue << endl;
	cout << "octalValue = " << octalValue << endl;
	cout << "decValue = " << deciValue << endl;
	cout << endl;

	return 0;
}
mrnutty 761 Senior Poster

sigh. Its practically the same concept as before, when I gave you
toHex() function. This time try to learn whats going on, please.

#include <iostream>
#include <sstream>
#include <string>

using namespace std;
template<typename Type>
string toHex(const Type& value, bool showBase = true){
	stringstream strm;
	if(showBase)
		strm << showbase;
	strm  <<  hex << value;
	string to_hex;
	if(!(strm >>  to_hex)) throw std::exception("Conversion to hex failed!\n");
	return to_hex;
}
typedef __int64 int64;

int64 hexToInt64(const string hexStr){
	stringstream strm;
	strm << hex << hexStr;
	int64 value = 0;
	if(!(strm >> value)) throw std::exception("Conversion to int64 failed!\n");
	return value;
}
int main(){
	cout << hexToInt64(toHex(3145131833)) << endl;	
	cout << toHex( hexToInt64("bb76e739")) << endl;
}
cwarn23 commented: Best code ever!!! +4
mrnutty 761 Senior Poster

Again use CODE TAGS...arghhh

>>What is the output?

The output is either compile time errors, or a stack overflow in your "recurse" function.

mrnutty 761 Senior Poster

Use CODE TAGS please?

>> What is the output?
The output is a bunch of compiler errors, that says WTF are you doing?

mrnutty 761 Senior Poster

>> in C++ by everyone and his brother

On the contrary, its, "by everyone and his mother" :)

mrnutty 761 Senior Poster

In java all you have to do to create a template class is this :

class List<T>{...}

In C++ its not that simple. The syntax for a template class is this :

template<typename Type>
class List{...}

The above code tells the compiler that the class List is a template
class. It's body will only be instantiated when you create a List object.
The "typename Type" tells the compiler that "Type" can be anything,
int, float, double, or string. Think of it as a generic data type.
For example you know how you declare a int variable like so :

int var ; //declare var as int

Think of Type, as anything. It can be int, float or whatever, depending
on how List is instantiated. So this code :

Type var; //declare var as Type

says that var is a variable
of type Type. Again Type can be int or float or something else.

mrnutty 761 Senior Poster

What you are looking for is template. I think this is what you are trying to
accomplish.

template<typename Type>
class Object{
protected:
  Type var;
public:
 Object(){}
 Object(const Type& initValue) : var(initValue){ }
virtual string toString()const ; //leaves the derived to implement this
}

Then you can do something like this :

class Int : public Object<int>{
public:
 Int() : Object<int>(0) {}
 //convert to string
 string toString()const{
  stringstream strm;
  strm << var;
  return strm.str();
 }
};
class Float: public Object<float>{
public:
 Float() : Object<float>(){}
 string toString()const{
 stringstream strm;
  strm << var;
  return strm.str();
 }
}

Of course I don't see why you would need this for your situation
because I don't know your situation. But I assume this can be
helpful it you put important information for each data-type.

WargRider commented: Very Helpful +1
mrnutty 761 Senior Poster

You know most of the time the error says it all :

::list' : use of class template requires template argument list

You have this

class MergingLists : public list

The error tells you that list uses templates so that means that
your MergingLists has to also be a template class if you want
to inherit from list.

So you can either change your code to this

template<typename Type>
class MergingLists : public list<Type>

Or you can just inherit one type like so :

typedef int Type;
class MergingLists : public list<Type>{}

For the second one you can only have 1 Type, so Type can either be
int,string,float, or double, but not all; Whereas the first one can be
any.

mrnutty 761 Senior Poster

Show us how you are detecting your collision. And a picture of the
situation would be nice as well. Depending on the situation, you might be
able to get away with 1d collision.

mrnutty 761 Senior Poster

First create a function that makes a rectangle like so :

#######
#     #
#     #
#     #
#######

After you get that , then its a simple change.

mrnutty 761 Senior Poster

If you want to see if a/b == c/d , then all you have to check if
a == c && b == d; More specifically, if a == kc && b == kd where k is
an element from the natural numbers.

mrnutty 761 Senior Poster

1) Your insert function is incorrect
2) Your remove function is mis informative, called it removeTop() or pop_front().
3) You concat function shouldn't be very hard(unless I am missing
something). All you have to do is either append the whole list you get
into your list front part or the rear. I will assume its towards the rear, or
the end. All you have to do is get a Node*ptr towards the end of your
list. Then keep adding the list content into the end. In fact, you should
make a function call addToEnd(ElementType val). Then you can just
call it inside your concat function.

4) You know how you are keeping a head Node. Keep a tail node as
well. Then you always have a node pointing to the end. This will make
things easier.

mrnutty 761 Senior Poster

Just to check, what happens when you comment out line 24?

mrnutty 761 Senior Poster

It won't be hard. First if you do the way you suggested to do it, i.e

if(RIGHT_KEY_PRESSED) moveScreen(World.RIGHT);

Then there will be a problem. The problem being that the screen will stutter. In fact try it out and see if its good enough, though.

What I would suggest it to do it one step up, and move the screen
relative to the player. So Find the middle of the screen, then calculate
how far the player is ways from the middle of the screen. Then if
the player passes the bounds you place on it, then move the screen
at the velocity of that of which the player is moving at. That way you
don't get any stutter, because of the different velocity the player and
the screen moves at.

mrnutty 761 Senior Poster

<me> clock() returns the time in mili seconds
<you>This returns the number of clock ticks since the last call to clock().

I take that back, clock returns the number of clock ticks since the
program was launched, not since the last call to clock().

mrnutty 761 Senior Poster

The Art of sorting?
The Art of searching?
The Art of finding shortest path?

mrnutty 761 Senior Poster

For powers of two all you have to do is use the shifter, which is very
fast and is probably almost constants for the usual powers of 2.

For ordinary numbers, its probably the O(exp), where exp is the
exponent. For example, base^exp, to calculate that it would probably take exp times to multiply base to get the answer.

The above is not definite, its just a hunch.

mrnutty 761 Senior Poster

The easy way is to use the setw method or the cout.width method.
Take a look :

void printChars(const char whatToPrint, const size_t howMany){
	for(int i = 0; i < howMany; ++i)
		cout << whatToPrint;
}
void printTri(const size_t height){	
	for(int i = 0; i < height; ++i){
		std::cout.width(height-i);
		printChars('*',(i+1));
		cout << endl;
	}
}

But go ahead and try it without setw. Just make sure that enough
spaces are present at each height. Actually, this code here :

std::cout.width(height-i);

should be a hint on how
to print the spaces.

mrnutty 761 Senior Poster

Do you know what this means :

typedef unsigned int uInt //?

Do you know what a class is?

Then all this

typedef basic_string <char> string

is, is a typedef for a template class called basic_string;

Its the same as this :

typedef int INT

in concept, but instead of int they substitute it for a template class.

kvprajapati commented: Helpful! +7
mrnutty 761 Senior Poster

>> Aside from stuff like rent-a-coder, you're probably not going to find a part-time job doing C++.

Does that apply to full time job as well, in your opinion?

mrnutty 761 Senior Poster

Maybe an easier class will help see below :

class Integer{
private:
  int myInt; //an integer variable
public:
 Integer(){ myInt = 0; } //a constructor
 Integer(const int initValue){ myInt = initValue; } //another constructor
 void setMyInt(int value){ myInt = value; } //set myInt to some value
 int getMyInt(){ return myInt; } //get the current value that myInt has
};

The getMyInt and setMyInt functions are called getters and setters.
What they do is get the current value of myInt, and set the new value
to myInt. The reason why we make get and set function is because
it enables us to control what happens when they use the method
getMyInt and setMyInt. As you gain experience, you will know what that
means.

mrnutty 761 Senior Poster

Which line is the problem pointing to?

mrnutty 761 Senior Poster

>>short shortEgyPop = 80000000

for_each(seconds : 1 minute)
   printBig("OVERFLOW");
//From MSDN
//"Microsoft Visual C++ recognizes the types shown in the table below."

Type Name      Bytes      Other Names                                Range of Values
short            2      short int, signed short int short        -32,768 to 32,767
unsigned short   2       unsigned short int                       0 to 65,535
mrnutty 761 Senior Poster

i want the time complexity for transpose of a matrix

i want the time complexity for heap sort

i want time complexity for merge sort

And I want :

1) 1 million dollars
2) 2 billion dollars
3) 3 trillion dollars


I got an idea, how about you help me out and I will help you.
Here let me start, "Merge sort is an O(n log n) comparison-based sorting algorithm"(Wiki). Now its your turn.

mrnutty 761 Senior Poster

Using only C++ won't do this for you. You will have to use external
libraries and such. For example using win32, you probably can get
control of the mouse, maybe. Using audio libraries, you can play an
manipulate sounds. Using an image library, you can manipulate images.
Using a graphics libraries, you can simulate the earth destruction in
2012. The point is there are different libraries for different stuff.
Google it and see what happens.

mrnutty 761 Senior Poster

Haven't looked at it in details, but I see that your search function is a linear
search. Make it a binary search since the array should be sorted already. You will see that
using the linear search you will have to do about on average N/2, where N is the total names,
while in binary search you do about log2(N). In low numbers for N it does not make big
difference, but if N was say 1 million, by using linear search you will have to make in average
500,000 comparisons, while in binary search you will make log2(1000000) which equals about 19 comparisons.

mrnutty 761 Senior Poster

Also instead of returning the minimum value, consider returning the minimum index, that way the person calling the function also knows where the minimum is as well.

mrnutty 761 Senior Poster

No don't make it that complicated. This is what I was suggesting :

<input> 4 2
<output> 4/2

We see that the numerator is divisible by the denominator right?
That is 4 % 2 == 0. That means we can divide both the numerator
and denominator by 2, so we get (4/2) / (2/2) = 2/1 = 2

See? Now we can repeat this process until necessary. Thats the euler
algorithm for finding GCD, greatest common divisor.

Try to implement that.