mrnutty 761 Senior Poster

also in c++ its ctime and not time.h, for the header.

mrnutty 761 Senior Poster

Have you though about not starting with c++, as I hear it can
be intimidating to beginners.

Also "I'm new and already need help", generally, when one is a
beginner, thats when help is needed.

mrnutty 761 Senior Poster

Here is the definition :

template<typename Type>
class vec2D
{
	typedef bool (Tetris::*MFPtr)(unsigned int ID);
	MFPtr mydrawFuncPtr;

private:
	unsigned int Col_id;
public:
	Type x;
	Type y;	

	vec2D(Type x0,Type y0) : x(x0), y(y0) { }
	vec2D() : x(0),y(0){ mydrawFuncPtr = 0; }

	void reset() { x  = 0; y = 0; }

	//Enables each object member to have its own unique draw func. 
	void setDrawFunc(MFPtr drawFunc  ) {  mydrawFuncPtr = drawFunc;}
	//get-set methods
	unsigned int Color() { return Col_id;}
	void Color(int i) { if(i < 0) Col_id = 0; else Col_id = i; }

	void drawShape(vec2D<Type>& obj,unsigned int colID) 
	{		
		(obj.*mydrawFuncPtr)(colID);
	}
};

And this is where its called

Tetris::Tetris()
{
	
	//For refrence
	//enum BlockType { LINE,SQUARE, ZSHAPE, LSHAPE, TSHAPE, CSHAPE, MAX_SHAPE };
	
	ShapePos[LINE].setDrawFunc(&Tetris::drawLine);
       ShapePos[0].drawShape(*ShapePos,2);
	
}
mrnutty 761 Senior Poster

hey Laiq, I tried your implementation but this gives me an error:

void drawShape(vec2D<Type>& obj,const unsigned int Col_ID) 
 {		
 	(obj.*mydrawFuncPtr)(Col_ID);
}

its just a variation of your code :

void Draw(T obj, const int Id) {
		return (obj.*funcPtr)(Id);
	}

and why is your code returning when its of type void.

The error :

error C2440: 'newline' : cannot convert from 'vec2D<Type> *' to 'Tetris *'
mrnutty 761 Senior Poster

Just by looking at your errors :

You forgot to include proper library. Fastest way is to
#include<iostream> using namespace std; Although its not good
practice.

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

which line does it point to?

mrnutty 761 Senior Poster

Is there any other problem?

mrnutty 761 Senior Poster

Can someone help me out. I haven't dealt with pointer function
much. Here is the class definition for which it resides, although its
only part of it.

template<typename Type>
class vec2D
{
private:
	bool (*drawFunc)(unsigned int ID);
	unsigned int Col_id;
  
   public:
	//Enables each object member to have its own unique draw func. 
	void setDrawFunc( bool(*Pf)(unsigned int) ) { drawFunc = &Pf;  }

   ///some more stuff
}
   
};

Inside another class I have this

class AnotherClass { 
	enum BlockType { LINE,SQUARE, ZSHAPE, LSHAPE, TSHAPE, CSHAPE, MAX_SHAPE };

 	vec2D<float> ShapePos[MAX_SHAPE];

	bool myCheckValidID(unsigned int Col_Id);
	bool drawLine(unsigned int Color_ID);
	bool drawSquare(unsigned int Color_ID);
	bool drawZShape(unsigned int Color_ID);
	bool drawLShape(unsigned int Color_ID);
	bool drawTShape(unsigned int Color_ID);
public : AnotherClass();
};

In the constructor I tried to assign the function to its function
pointer like so :

AnotherClass::AnotherClass(){
//For refrence
//	enum BlockType { LINE,SQUARE, ZSHAPE, LSHAPE, TSHAPE, CSHAPE, MAX_SHAPE };
	
	ShapePos[LINE].setDrawFunc(&Tetris::drawLine);
}

But this gives me a conversion error. How could I pass the function
correctly to setDrawFunc

mrnutty 761 Senior Poster

Before I help can you explain what your trying to achieve here:

for (j = 0; AlphaSeats [j] <= 59; j++)
         AlphaSeats[j] = 0;
            
   for (j = 0; BravoSeats [j <= 59]; j++)
      BravoSeats[j] = 0;
mrnutty 761 Senior Poster

Have a timer class so that 'R' moves every second to a new position,
instead of moving all at once. It will look and feel more natural

To have the 'R' move to position where the user specifies, you can
do this :

First get RowNum, ColNum. Then determine the difference between
the 'R' position and the specified position. To do this say
'R' is at position 0,0. Where the first number is the row and the
second it the column number. Then say the user specifies the
coordinate 5,5. Where again, the first number is row and second is
col.
The difference between the final position and initial position
is (5-0),(5-0). Where is first set of number is the row coordinate and
the other is the col. So you can now increment the initial row
coordinate of 'R' by 1 say every one seconds. And when it reached
the difference (5-0) = 5 row number, stop the 'R'. And then go onto
the column coordinate. And find the difference, in the final and the
initial column coordinate. And update it every second until the
difference is met.

mrnutty 761 Senior Poster

1) Implement the person definition. Make sure You have all needed
constructor, for it will be used in the derived class.

2) Implement student class but in the constructor you need to pass
it the information needed to person class.

class person
{
   private : string name;
   public : person(string str) : name(str) { }
};
class Programmer : public person
{
   private :  string Language;
   public : Programmer(string name, string language ) : person(name), Language(language) { }
};

If you do not explicitly provide the programmer class with a person
constructor, the compiler will use the default constructor. If there
is no matching constructor, it will throw an error.

mrnutty 761 Senior Poster

I am not good at taking people's word. ;) Why does (float)rand()/RAND_MAX have low odds of generating 1 and how does it justify adding .1 in all cases?

It has low odds of generating 1 because for rand()/RAND_MAX to be
1, rand() HAS to generate RAND_MAX in which the odds are
1 out of 32767(RAND_MAX). Percentage wise its 0.000031.

In using 0.1f, it shifts the chances by a little bit more.

When (float)rand()/RAND_MAX generates 0.9 through 1.0, adding
0.1 would make it range from 1.0 to 1.1. This result gets multiplied to max-min, and since its an int it would not cause this function to
generate a higher number than max, unless the offset if set to
0.5 instead of 0.1, then it has a chance.

So the chances increases because now rand has to only generate
a number greater than 0.9 * RAND_MAX to get a 1. And that chance
from my calculation leads to 0.10 percent of generating maxNum.

mrnutty 761 Senior Poster

So the user enters say row 0 and col 0 for the starting position
for R and the ending position say row 5 and col 5. And you want
help to calculate the movement for the robot. Is this correct?

mrnutty 761 Senior Poster

That's because you're an idiot. You use one or the other. NOT both.

Hahahahahahahahha.哈哈哈哈哈哈哈哈哈哈哈哈哈哈. 母母母母母母母母母母母.

mrnutty 761 Senior Poster

Here is another random generator :

int  randI( int min , int max)
{ 
    return    (float)rand()/RAND_MAX * (max-min) + min;
}

since generating 1 from (float)rand()/RAND_MAX has low odds, thus returning max would be low, so to fix it
you can shift the odds by adding 0.1f;

so the function would look like this :

int  randI( int min , int max)
{ 
    return    ( 0.1f + (float)rand()/RAND_MAX  ) * (max-min) + min;
}
mrnutty 761 Senior Poster

Forget tutorials. Get a book written by usually a professor who
is very educated in his subject, no offense to anyone.

I would suggest C++ Primer Plus. Its an extensive C++ book.
Its designed for beginners in mind. Its about 1k pages.
It teaches you from beginning till the end(whatever that is).

mrnutty 761 Senior Poster

First you need to read in the data. Have some flags ready.

Then you have a string array with data. Now you need to sort it.

There are a couple of ways to sort it now. You can google "sorting
c++" and you will find ways to sort data.

mrnutty 761 Senior Poster

1st - your program should throw an error if both the w and r starts
at the same position.

I am not understanding your question well, is that you have a problem
distinguishing the position of the R?

Whats your program trying to simulate?

mrnutty 761 Senior Poster

"4) add 2 nodes sale file and sale item"

First I do not know what a sale file is nor a sale item. I do not
bother to download your code to see because most here are too
lazy to do that, including me.

So if you post and show what they are then we could help you.

mrnutty 761 Senior Poster

Try creating your own

Salem commented: Such an elegant and obvious answer :) +36
mrnutty 761 Senior Poster

.

mrnutty 761 Senior Poster

Not exactly sure what you need help with.

mrnutty 761 Senior Poster

"First Person: I was just trying to keep it simple because 'Dr.Stupid' (I feel like I am insulting him but I am not...) is a beginer. So yeah, if I had to do something like this, I would have probabaly thought of something different like first converting everything into lower or uppercase and then do some random thing with it...
"

It's nice to start thinking of different ways to solve a problem
especially when you first start.

mrnutty 761 Senior Poster

This is a bug : " ii <= userword.length() ".

mrnutty 761 Senior Poster

You know creating a terrain from heightmap is not hard. Its
actually easy once you understand the concept.

mrnutty 761 Senior Poster

(assuming visual studio) right click on the header and click "open document" and see if it
exist.

mrnutty 761 Senior Poster

use cin.get(). It reads chars including spaces.

Try something like this

ifstream iFile("sample.txt");
char c;
while( iFile.get(c) ) 
{ 
    if(c == ' ') //add to new string
    else addToTheLastString .
}
mrnutty 761 Senior Poster

帮你顶下!
哈哈!

" Helps you to go against! Ha! Ha! " ?

mrnutty 761 Senior Poster

You need to create your own semi-string class, that has
the operators above overloaded.

mrnutty 761 Senior Poster

.

mrnutty 761 Senior Poster

dj, thats one semi-correct way of doing it, another approach is do
something of the following :

std::string lowStr = "abcdefghijklmnopqrstuvwxyz";
int lowCnt[26] = {0};
std::input;
cin >> input;

for(int i = 0; i < input.length(); i++)
{
   //something similar to this
   if(input[i] == lower[ int ( (input[i]) - 'a' ) ] //this is not even needed. Just a visual reminder
     lowCnt[i] +=1;

  //Alternative to above you can do just this, realizing that elem 0 is 'a' elem1 is 'b' and so on
    lowCnt[ int( input[i] - 'a') ] +=1
}

//Display result...

mrnutty 761 Senior Poster

what does the code return?

mrnutty 761 Senior Poster

I can revive it once a while.

Tom Gunn commented: Will you revive it until you are banned for intentionally breaking the rules? -1
mrnutty 761 Senior Poster

"counting occurrences of each letter." Does that mean you count
all letters from a to z? In a sentence and display all letters and the
number of occurrence?

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

.

mrnutty 761 Senior Poster

This has already been said in the sticky thread posted by Narue, what makes you think anybody will read this?

Because a title named Cool New Game must See!! is more
catching than Thread Rules or something similar.

tux4life commented: You're exactly doing the same as all others by opening this thread and giving it a not-meaningful title, so I wouldn't complain to much about it. -4
mrnutty 761 Senior Poster

#include "Employee Class.cpp"

There should be no space between the name , it should be

#include "EmployeeClass.cpp"

mandofl commented: Gives good advice +1
mrnutty 761 Senior Poster

Is that the correct function name ? What is KillALData and where
is it declared?

mrnutty 761 Senior Poster

rand() % 15; // ranges from 0 -> 14
wildgoose, would you mind explaining you snippet a little "bit" more?

mrnutty 761 Senior Poster

Forgive me Admin. Now that I got your attention. I just wanted to say
one thing. PLEASE put meaningful titles on your thread. No, Help,
Urgent!!, I HATE C++, or even worse "UNTITLED". Instead, put titles,
like help creating a recursive add function, or help I don't understand
this homework problem, or even something more descriptive. Note that
this is in the forum rules, but I guess not many bother to read them.

Thank you,

FirstPerson.

mrnutty 761 Senior Poster

Is that your class haven't learned arrays, or that the teacher
said you can't use arrays. How about emailing your teacher.

Btw, you need to seed your random number generator like so : srand(time(0));

mrnutty 761 Senior Poster

Can you use pointers and dynamic memory?

mrnutty 761 Senior Poster

what error do you receive?

mrnutty 761 Senior Poster

validTime(hoursIn,minsIn,hoursOut,minsOut);// check the time.

should this be : float hoursIn, float minsIn, float hoursout, float minsOut) ?

mrnutty 761 Senior Poster

"int maint() {...}"

should be int main(){...}

mrnutty 761 Senior Poster

You can use the indexes, but you can also use flags.

First try to read in a file. Then check for the first quote ( " ) and
if found read in the data until another quote ( " ) is found.

mrnutty 761 Senior Poster

I'm sorry I am still not getting your problem

mrnutty 761 Senior Poster

Make an Id grid like so :

_______________________________
|  a    |   b     |    c   |    d      |
--------------------------------
|   e   |     f   |     g  |     h     |
--------------------------------
|   i   |     j   |   k    |    L    |
--------------------------------
|    m  |       n |    o   |    p      |
--------------------------------