mrnutty 761 Senior Poster

I have finals this week and next, so I can't do anything now, but in a week and a half, I can make problems, or help. Do you guys think we should make a list of problems here and go from that?

mrnutty 761 Senior Poster

I think using glScale would work.

mrnutty 761 Senior Poster

Don't use define.
Use this :

const unsigned int MAX_SIZE = 6;
int main(){ ... }

For sorting and searching use the stl sort and find method.

So to start have this :

#include<iostream>
#include<algorithm> //for search and sort methods

using namespace std;

int menu(); //returns a choice from sorting and/or searching

int main(){
  const unsigned int MAX_SIZE = 10;
  int Array[MAX_SIZE] = {0}; //set all elements to 0
 
   int choice = menu();
  if(choice == 1) { std::sort(Array, Array + MAX_SIZE ); }   //then display it
else if(choice == 2) { std::find(...) ; }
else;// print errror

return 0;
}
mrnutty 761 Senior Poster

Try degubbing it. Print out everything in the map before and after you
make that search call.

mrnutty 761 Senior Poster

Is it in the same directory? Show some code?

mrnutty 761 Senior Poster

In C++ term of reference or in general ?

You can do this :

Complex& Complex::getClass() { return *this; }

That way, you get the Complex class as a reference in terms of the reference operator.

mrnutty 761 Senior Poster

try something like this :

char *Index[2] = { "Index of first(", "Index of second(" }; //and so on

int cntr = 0;
while(start != end) //start and end are the beginning and the end iterator of a container
{
    cout << Index[cntr] << *start <<")"<<endl;
    start++;
}
mrnutty 761 Senior Poster

Can you use remove_if ?

mrnutty 761 Senior Poster

Go to youtube and learn about functions from professors. Youtube has many good programming videos. try it out.

mrnutty 761 Senior Poster

In your load function, you want to load in the data the exact way you
saved it right? Can you take it from there?

mrnutty 761 Senior Poster

Wow, people clearly didn't like my simple most obvious answer :P

They didn't like that one either.

mrnutty 761 Senior Poster

plzzzzzzzzz tel me basics thing of programing

yaaa gotta make variables, then use ifs and loops is ther anythn else ya gotta know?

Ya gotta learn english 1st.

zobadof commented: This is very funny!! :) +1
mrnutty 761 Senior Poster

>>. I also have to get these 2 classes to communicate somehow so it can use the hours from array2 and the pay from array1 to come up with a total pay amount.
>>I just don't know how to make the 2 classes communicate.

There are couple of ways.

But I suggest you make a function, that calculates the total pay amount.

float calculateTotalPay(const ClassOne& pay, const ClassTwo& rate){...}
mrnutty 761 Senior Poster

This part is wrong :

inF >> id;
while (!inF.eof())
	{
		cnt++;
		myStuds[cnt].id = id;
		myStuds[cnt].fname = fname;
		myStuds[cnt].lname = lname;
		for (int i = 1; i < 5; i++)
			inF >> myStuds[cnt].gr[i];
		myStuds[cnt].avg = 0.0;
		myStuds[cnt].letGr = 'Y';
		inF >> id;
	}

I assume you wan't something like this :

while(!inF.eof()){
	inF >> myStuds[cnt].id;
	inF >> myStuds[cnt].fname;
	inF >> myStuds[cnt].lname;
	for (int i = 0; i < 6; i++)
		inF >> myStuds[cnt].gr[i];
	inF >> myStuds[cnt].avg;
        int grade = 0;
	inF >> grade;
       myStuds[cnt].letGr =  convertNumberToLetterGrade(grade);

    ++cntr;
}
mrnutty 761 Senior Poster

>>I think do you have the idea and please help me sir with my project...

Not really, care to explain a bit more?

mrnutty 761 Senior Poster

>>I m having a lot of errors please help

Can you post the errors, and what line it points to?

mrnutty 761 Senior Poster

That sounds really boring to me :icon_neutral:
I thought the problem would be a slightly less specific, such as to create a game of snake or tetris or make a program to achieve something within certain restrictions, where you can apply lots of creativity (obviously that would be Intermediate / Advanced), but that sounds more appealing to me.

Thats sounds good but the problem with that is the time it would
take to asses every program. Making a game would not be a bad idea
but it would be hard to evaluate it. Anyways, my suggestion was just
a suggestion, as is yours. So I don't really know. Anyone else have more ideas?

mrnutty 761 Senior Poster

Well. . even among the dedicated members, there is a lot of variation in skill here. Wouldn't it be better to have 3 different levels, similar to Sane's challenge at Daniweb's sister site, PFO?

I was thinking something like :

abstract Problem : general ( what we are trying to solve ).

Inherit from abstract :Beginner version : Easy implementation, just get it to work

Inherit from abstract : Intermediate version : A slight variation
of the problem, to make it harder. Have it neat, clean, error
checking, no fails. And works for all cases

Inherit from abstract : Others : A harder variation,
works flawlessly, and is very fast, with good coding style.

Maybe the first few should be reasonable so people could join and
get the hang of it?

mrnutty 761 Senior Poster

If I want to define what is a double -> double function pointer I use:

typedef double (*double_fp1)(double);

But what if I would like to distinguish
const double -> double
it is possible?
And the above definition consists the const double -> duble function?

you mean :

const double_fp1  =  &myDoubleFunction;
mrnutty 761 Senior Poster

The cmath library already has the power function so you don't have to
create a function. Plus your syntax is horrible.

You got the idea correct but not the logic and the syntax.

This is what you should be doing

#include<iostream>
#include<cmath>

using namespace std;

int main()
{
 float input = 0.0f;
 bool goAgain = true;

 while(goAgain){  
 //ask user for which function to use
  cout <<"1) Power function\n";
  cout <<"2 Sqrt function\n";  
  int choice = 0;
  cin >> choice;

  //ask user to enter a number to either use pow or sqrt
  cout<<"Enter a number : ";
  cin >> input;

  if(choice == 1){
   //print the power of input
  }
  else if(choice == 2){  
   //print the sqrt root of input
  }
 
  cout<<"Try again (0 = no), (1 = yes ) : ";
  cin >> goAgain;  

  }

}
mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

Posted in the correct thread this time. This is also another way, and still
naive. It shows both static_assertion and exceptions.

#include<iostream>

using namespace std;
 
template<typename Type>
struct assert_numeric{ const static int i = 0; };

template<> struct assert_numeric<short>					{ const static int i = 1;	};
template<> struct assert_numeric<unsigned short>		{ const static int i = 1;	};
template<> struct assert_numeric<int>					{ const static int i = 1;	};
template<> struct assert_numeric<unsigned int>			{const static int i = 1;	};
template<> struct assert_numeric<float>					{ const static int i = 1;	};
template<> struct assert_numeric<double>				{ const static int i = 1;	};

template<typename Type>
class Numeric{

public:		
	 struct BadType : std::exception{
		BadType(const char *msg) : exception(msg){}
	};
public:
	Numeric()
	{ 
		//int asserter[assert_numeric<Type>::i];// Way# 1 cannot have an array of size 0
		
		if(assert_numeric<Type>::i == 0) //Way number 2 : throw custom exception
			throw BadType("Type is not numerical!");
	}
	~Numeric(){ }
};

int main()
{

	try{
		Numeric<char> j;
	}
	catch(Numeric<char>::BadType& e){ cout << e.what() <<endl; }
	

 
  return 0;
}
mrnutty 761 Senior Poster

Boy that went on the wrong thread. Thats it. I need some sleep. And the static assert is also shown in the example.

I think in the other post of Narue, it talks static_assert.

mrnutty 761 Senior Poster

Thread split from ancient thread, moved and given an appropriate title :)

@OP: You need to read this

aww man. I though some n00b came up with this title. I should have
known. This is funny though.

mrnutty 761 Senior Poster

Don't make it too simple, because it's only fun if we need to bend our brains a bit.
I don't really feel like making the n-gazillion'st palindrome-finder for example.

Oh, you guys were expecting me to do it? But I want to participate
too...lol.

I guess I could make a thread or two. But eventually we need some
rotation going around. I though maybe some mods, could make
a special thread or something?

mrnutty 761 Senior Poster

Well there are also other ways.

Here is a another way :

#include<iostream>

using namespace std;
 
template<typename Type>
struct assert_numeric{ const static int i = 0; };

template<> struct assert_numeric<short>					{ const static int i = 1;	};
template<> struct assert_numeric<unsigned short>		{ const static int i = 1;	};
template<> struct assert_numeric<int>					{ const static int i = 1;	};
template<> struct assert_numeric<unsigned int>			{const static int i = 1;	};
template<> struct assert_numeric<float>					{ const static int i = 1;	};
template<> struct assert_numeric<double>				{ const static int i = 1;	};

template<typename Type>
class Numeric{

public:		
	 struct BadType : std::exception{
		BadType(const char *msg) : exception(msg){}
	};
public:
	Numeric()
	{ 
		//int asserter[assert_numeric<Type>::i];// Way# 1 cannot have an array of size 0
		
		if(assert_numeric<Type>::i == 0) //Way number 2 : throw custom exception
			throw BadType("Type is not numerical!");
	}
	~Numeric(){ }
};

int main()
{

	try{
		Numeric<char> j;
	}
	catch(Numeric<char>::BadType& e){ cout << e.what() <<endl; }
	

 
  return 0;
}
mrnutty 761 Senior Poster

Nothing is wrong with *this, except that it doesn't solve the problem. Calling multiply within the operator* function produces the same incorrect answer in the resulting matrix.

Thats a problem with you multiply function then. Check the formula.

mrnutty 761 Senior Poster

Whats the problem with :

Matrix Matrix::operator* (const Matrix &B){
Matrix temp;
multiply(*this,B,temp);
return temp;
}
mrnutty 761 Senior Poster

Summer. Because there is no school. Just eat, sleep, and poop, among other things.

mrnutty 761 Senior Poster

>>But this looks ugly and I had to use a separate variable.

I think that looks beautiful. In fact you can just make a function that does that, and so it will be in a sense a one liner.

I don't think there is a standard implementation of getch in C

mrnutty 761 Senior Poster

so for instance say i did dataTable->at(key) would i be referring to the list or vector? or both?

dataTable is a vector.

dataTable is a list

dataTable.front() is the int.

And also I don't think mixing up vectors and list would be a good
idea, unless it really really makes sense to do so.

mrnutty 761 Senior Poster

>>"The vector holds a list of data type int? "

the word list has ambiguity.

A better term(IMO) would be : The vector contains a container in which the contained container is of type int and the contained container is a stl's list container.

mrnutty 761 Senior Poster

From :

while ((cin >> ar[i]) && (i < arSize))

To :

while ((i < arSize) && (cin >> ar[i]) )
mrnutty 761 Senior Poster

So I was thinking, we should have a challenge of the day or week,
for a specific language, that poses a unique problem. This way people can practice, and others can learn maybe something new from someone else's idea. What do you guys think ? For example in our
C++ section, we can have a C++ challenge question. And people can participate in it. I know I would like to know other people solutions
to a problem. That way it will help me think in different ways.

mrnutty 761 Senior Poster

Then you can either make multiply a template function. Or make mystruct
a template class with myclass begin a template class that takes 2
typenames argument.

mrnutty 761 Senior Poster

Or Use us as a reference.

mrnutty 761 Senior Poster

inside the operator*, call the multiply function.

mrnutty 761 Senior Poster

Now try to create a soduko solver, if you dare. (NO cheating).

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

>>The you can just concat title with first name.

That was my objection. Those two can not be joined.

Are you talking about conceptually or technically?

mrnutty 761 Senior Poster

So you want the call to myobj1.function() to work?

mrnutty 761 Senior Poster
lastElem =remove_if(v1.begin(), v1.end(), islowerCase);//line1

Line 1 : remove_if(...), if the containers contains a lower case character
the function removes it. It does this, and returns the a pointer that
points to the new end since some elements has been deleted.

ostream_iterator<char> screen(cout, "");//line2

Line 2 : creates an iterator. Just like the vector::iterator, ostream_iterator is an iterator. It can insert elements into the
ostream object, cout. When you do :

cout << 'a';

Its almost the same as if you do :

screen = 'a';

Its just doing it in a different way.

copy(v1.begin(), lastElem, screen);//line3

Remember what I said, if you do screen = 'a'; It will print out a into the
console. So the above code roughly does screen = vec[0] ... vec[lastElement]. That means everything inside the vector is getting
printed to the screen.


Also check this out for some reference : remove_if , istream_iterator using std::copy

mrnutty 761 Senior Poster

did you get the texture to load onto a shape?

mrnutty 761 Senior Poster

Wrong answer. Those strings don't have enough space allocated to concatenate them (see original post). Each of those strings need to be copied into some buffer that is large enough to hold all the strings at one time.

Oh, when I said result, I was implicitly talking about a new result string, as suggested by the function prototype that I gave. I thought it was obvious but I guess not.

mrnutty 761 Senior Poster

I have made my own image load function that reads the file extension and loads the image with the appropriate method. but at the moment it can only load bitmaps. and i know now why the image wasn't loading properly, the image was 8 bit but the function was reading it assuming it was 24 bit. how could i discard the pixels that are a certain colour (the colour around the edge)?

just use a software to convert it into a 24bit bitmap

mrnutty 761 Senior Poster

They have it , in the link I provided you with.

mrnutty 761 Senior Poster

Do you know functions ? loops? classes ? templates ? structs ?
polymorphism ? inheritance ? pointers ? data structures ?

see here

mrnutty 761 Senior Poster

Well what do you know so far?

mrnutty 761 Senior Poster

Since "I started learning C++ November 14th 09!!"

Then I would suggest to keep learning it more a while.

mrnutty 761 Senior Poster

Put the definition in the same file as the templete header, unless your
compiler supports the keyword export.