mrnutty 761 Senior Poster

That doesn't make sense. Why do you derive parent from a GrandParents.
Its like saying a parent "is a" GrandParents. Where we know thats not true. A GrandParents, has a child. A parent has a child. That suggests composition, not inheritance. And why do you create a Abstract parent class and a non-abstract parent class. The name,
GrandParent and Parent, is centered around the child. You need to rethink the design and the name. What are you trying to accomplish exactly?

Carrots commented: appreciated +1
mrnutty 761 Senior Poster

>> But when I run that, the code works other than the fact that it exits out after pause. How do I have it go back to the main "cin"

int cmd = 0;
while( cin >> cmd) {
  if(cmdIsBad()) break; //out of the loop
  /* else logic goes here */
}
mrnutty 761 Senior Poster

The usual rule around here is that you pay us 100 dollars per an hour.
It usually takes us 1-2 hour per homework. So what do you think?

jonsca commented: That's too conservative of an estimate. First we've got to find yet another forum to repost his question on, wait for that answer, come back, answer the OP's question. That could take a day or two... :) +2
mrnutty 761 Senior Poster

Try something like this :

#include <vector>
#include <particle.h>

using std::vector;

int main() {
vector <particle*> vec;
vec.push_back(new particle());
vec.front()->move(); //option 1
vec[0]->move(); //option 2
}
mrnutty 761 Senior Poster

help i need to search and delete a node from a link list
but i am not sure of the algorithm
can someone please help me with the algorithm and concept
need example thanks..

Draw a picture of a linked list on paper. Then write down the steps
you feel is needed to find an element. The same for deleting an element.

Salem commented: Nice +19
mrnutty 761 Senior Poster

>>No matter what I do, I always get the numeric value from the ASCII chart. In this case I get 104, even though I denote Name[2] as a character

Thats because tolower() prototype is declared as, int tolower(int c).
So it takes a int and returns a int.

mrnutty 761 Senior Poster

double linked list is slower for insert and delete and uses more memory.
It's only really preferable over a single linked list if you desire iteration in both directions.

Double Linked list has O(1) insertion and deletion, while
a single linked list, has O(n) insertions and deletions.
A double linked list does not use that much more memory than a single linked list, in a small scale size list. If the memory used by a double linked list is a problem, then you shouldn't be even using a list.

A double list is usually more preferable over single linked list, but there are special cases as always.

mrnutty 761 Senior Poster

>>static bool not_isOdd(const int &i)

A better name would be , isEven(...);

Work with 2 copies, of the vector and transform then into even and odd
vectors like so :

int A[9] = {1,2,3,4,5,6,7,8,9};
	std::vector<int> numbers = std::vector<int>(A,A+9);
	std::vector<int> evenNumbers = numbers;
	std::vector<int> oddNumbers = numbers;
	std::vector<int>::iterator vecItr;

	
	vecItr = std::remove_if(evenNumbers.begin(),evenNumbers.end(),isOdd);
	evenNumbers.resize(vecItr - evenNumbers.begin());

	vecItr = std::remove_if(oddNumbers.begin(),oddNumbers.end(),isEven);
	oddNumbers.resize(vecItr - oddNumbers.begin());
mrnutty 761 Senior Poster

Why would they ever ban this sport. Its so easy to play.
You can play with your families. You can play with friends. Hell,
you can even play with a random stranger walking down the street.

mrnutty 761 Senior Poster

But won't a friend give more versatility?

Obviously you did not get my post. In your case friend does not
do anything different to offer than the same function without it being friend.
So don't use friends for that. There is no need. Just implement
a class member function of type :

Fraction operator*(const Fraction& rational){  
  /* logic goes here * /
}
Dave Sinkula commented: I don't look at these things closely enough sometimes. I'm glad other do. +13
mrnutty 761 Senior Poster

I want them to have access to the private section of the class.

The reason you might want friends is so you can do something like this:

Fraction frac(2,3);
Fraction f = 1/2.0 * frac;

But in your friend function is doing this :

Fraction f(3,4);
Fraction g(4,5);
Fraction r = f * g; //or g * f;

Since you only provide fraction as an argument to the friend function.
For your function a friend is not needed because implementing a simple Fraction operator*(double); will do the job.

Now if you prototype were this :

Fraction operator*(const double frac)const;

Then you should also provide a friend function with this prototype:

friend Fraction operator*(const double frac1, const Fraction& frac2);

That way you can do this :

Fraction f = 1/2 * aFractionObject; //uses the friend function
Fraction g = aFractionObject * 1/2; //uses aFractionObject.operator*(double);
mrnutty 761 Senior Poster

Is there any way to reduce the number of times you have to write:

template<typename T>

for a bunch of functions all using the same template parameters?

i.e., something like this:

template<typename T>
namespace my_functions_using_T {

T function_do_something(const T & t);

void function_do_something_else(T & t);
}


(besides making them all methods of a class... which seems heavy handed...?)

Nope. Don't be that lazy.

mrnutty 761 Senior Poster

Why don't you use arrays ? For example his code :

ImageIcon c1icon = new ImageIcon ("clubs-2-75.jpg");
	ImageIcon c2icon = new ImageIcon ("clubs-3-75.jpg");
	ImageIcon c3icon = new ImageIcon ("clubs-4-75.jpg");
	ImageIcon c4icon = new ImageIcon ("clubs-5-75.jpg");
	ImageIcon c5icon = new ImageIcon ("clubs-6-75.jpg");
	ImageIcon c6icon = new ImageIcon ("clubs-7-75.jpg");
	ImageIcon c7icon = new ImageIcon ("clubs-8-75.jpg");
	ImageIcon c8icon = new ImageIcon ("clubs-9-75.jpg");
	ImageIcon c9icon = new ImageIcon ("clubs-10-75.jpg");

Can be substituted with this :

ImageIcon[]  clubSuitIcon = new ImageIcon[10-2]
for(int i  = 0; i < clubSuitIcon.length; ++i){
  String card= "clubs-" + String.valueOf(i + 2) + "-75.jpg";
  clubSuitIcon[i] = new ImageIcon(card);
}

Making similar changes can make your code much better.

BestJewSinceJC commented: Good suggestion, I was thinking the same. +4
mrnutty 761 Senior Poster

Who the h--l taught you that? He should be shot.

Please don't help anyone else. You are teaching very bad habits -- even worse than instructors teaching Turbo-C and conio.h

I am not sure behind your rational. Why do something twice, when one
is enough ? Maybe if you give a good example and reasoning then
I might see your point. Until then just saying that its a bad habit
doesn't cut it. Curious on what other people think about this.


P.S :
Just curious, because you disagreed with one of my rational, why do you say not to help anyone else?
Did you witness me "preaching" this to anyone else? Did you find any other advice that I gave bad advice?

mrnutty 761 Senior Poster

What does it supposed to do, make the user specify the shape of the
function? For example, is the input supposed to be something like this :

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

Should the user input a hallow box?

jonsca commented: Rep for this monster thread +2
mrnutty 761 Senior Poster

I will suggest the following :

1) Create a vector
2) Fill the vector with numbers 0 through MAX
3) Find one fib number from the vector and delete it.
4) Find the next fib number and delete it.
5) Repeat 3-4 until MAX is reached
6) Print the vector

mrnutty 761 Senior Poster

We're not physics. Post your code!

Its probably something wrong with your program. Maybe the "1" in "104"
is your boolean variable and the 04 is something else.

WaltP commented: It's not "physics", it's "psychics" :o) +9
mrnutty 761 Senior Poster

We are all tired of from our daily lives. So I suggest to sit back and
play this game. I present here a hangman game( text version ) for
your enjoyment. There might be some bugs as I haven't throughly
tested it, so sorry if you find it( I'm sure you can fix it ). Happy late
Chinese new year! P.S no cheating, and get your vocabs up...

mrnutty 761 Senior Poster

You need to realize the conversion between 2d array and 1d array.
Namely, that 1D_Row = 2dRow * MAX_ROW + 2D_Column;
In code it would look like this :

for(int row = 0; row < MAX_ROW; ++row){
  for(int col = 0; col < MAX_COL; ++col){
     Array1D[col + row*MAX_ROW] = Array2d[row][col]
  }
}
mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

The warnings tells a thousand words :

30 [Warning] ` class Kontrolka' only defines private constructors and has no friends 
33 [Warning] ` class KontrolkaAtomowa' only defines private constructors and has no friends 
36 `Kontrolka' with only non-default constructor in class without a constructor

Realize that in a class, if you don't specify a modifier, the function inside
of a class, the constructors, the destructures, and the member variables
are all private.

For example this class :

class Kontrolka : public NieDesktop{                      //abstract
    Kontrolka(const Kontrolka&);                 
};

The constructure you provided is private, because its that way by default. To solve your problem make the constructure pubilc, for this
one and you other ones.

mrnutty 761 Senior Poster

The problem is that D3DXVECTOR3 is not being found for whatever
reason. Have you linked ALL of the lib and headers? Maybe something
got corrupted.

>>I've actually been building this from a tutorial (its beginners DirectX for C++ Veterans) where the source code compiles and runs perfectly, yet, even pasting the source into my project (or even only pasting SMALL parts of it) yields the Unresolved external errors.

This tells me that you are not linking your lib and headers properly.
Why, because when you unzip their project, included are the dlls
for directX and thus the .exe works because it finds them in the same
directory. But you say that you pasted the code and it gives you
a linking error, which definitely means that you did not link the files
correctly.

mrnutty 761 Senior Poster

In recursion there are 2 main things :

1) basis :
2) Induction.

In you recursive, you have provided the Induction, namely
f() = f(), but you have not provided a basis case.

Here is an example of a recursion function. Again, a recursion function
has a basis and the Induction.

//example of recursion
void printXTimes(int printWhat, int howMany){
    if( howMany == 0) return; //our basis...

    cout << printWhat; //print whatever is passed in
    printXTimes(printWhat, howMany-1); //our Induction
}

As you can see we reduce howMany by 1 in ever recursive call.

The above function is a recursive function because it has a basis case
and an Induction. It is defined as follows :

Our function is defined as, F : N --> empty , where empty means it
returns nothing. Then our basis and induction are :

Basis : n = 0
Induction : F(x,n) = F(x,n-1)

MrYrm commented: thx for the info +0
mrnutty 761 Senior Poster

Use std::copy. If not then create your own like so.

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

template<typename Container>
void print(const Container c){
	Container::const_iterator itr = c.begin();
	cout << "{ ";
	while(itr != c.end()){
		cout << *itr++ << " ";
	}
	cout << "}"<<endl;
}
template<typename SrcIterator,typename DestIterator>
void myCopy(SrcIterator srcBegin, SrcIterator srcEnd, DestIterator dest){
	while(srcBegin != srcEnd){
		*dest++ = *srcBegin++;
	}
}
int main()
{	
	string src = "1234567890";
	std::vector<char> dest;
	
	//using std::copy method
	//copies src into dest, while expanding dest as needed
	copy(src.begin(),src.end(),std::back_insert_iterator<std::vector<char>>(dest));
	cout << "Vector now contains : ";
	print(dest);
	cout << endl;

	
	string src2 = "abcdefghijklmnopqrctuvwxyz";
	std::vector<char> dest2;

	//using myCopy function
	//copying src2 into dest2 while expanding size of dest2 if necessary
	myCopy(src2.begin(),src2.end(),std::back_insert_iterator<std::vector<char>>(dest2));
	cout << "Vector2 now contains : " ;
	print(dest2);
	return 0;
}

I recommend using std::copy so there is no chance for mistake.

mikabark commented: Thanks you so much. +1
mrnutty 761 Senior Poster

>>But, I've been told that srand() will produce a better random number

Whomever told that to you should not talk about programming anymore.
All srand does is seed the random number generator.

>>a good one is the mesner twister
>>It's called the Mersenne Twister.

Yes that is better than rand, however usually, rand should suffice for
newbies.

mrnutty 761 Senior Poster

>>[edit]wow...i'm slow....[/edit]

Yep. We are super ninjas.

Nick Evan commented: We are indeed :) +12
mrnutty 761 Senior Poster

>> the flamethrower works differently then the gun

Does it?

The flamethrower shoots and so does the gun.
The flamethrower has some mass and so does the gun
The flamethrower can run empty and so does the gun.

The point here is that, they do differ internally, but not so much
externally. Thus a solution to your problem is to create a hierarchy
with virtual and pure virtual functions, as pointed out already, while
making the have the same functions like shoot() or destroy(), or whatever.

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

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

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

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

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

A class :

class Test{};

A pointer :

int *p = 0;

Combine them and you get a "class pointer" :

class Test{};  Test *p = 0;
mrnutty 761 Senior Poster

You need to make it a reference.
In fact do something like this :

void write(const string& str, std::ostream& out = cout){
 out << str << endl;
}

Now you can call the code like this :

write("Hello"); // and prints to screen
write("Hello",myout); //and write to file
mrnutty 761 Senior Poster

Your code is really hard to look at. But from your question : "cant
determine the winner" I figure that the winner checker is not working.
There are 2 things you can do.

Option1 : Make a hard-coded function that checks for winner
Option2 : create a for loop to that checks the winner.

I would say Option1 is easier. So For now, you should get that working.

To check for winner you need to first create a function like so :

bool checkForWinner(const char *Board[3], const char key){
 if( Board[0][0] == key && Board[0][1] == key && Board[0][2] == key)
    return true;
 //and so one
}

Thats the hard-coded way. Try and see if you can get that working.
Also try to make your code neater and easier to read.

Salem commented: Yes, that code desperately needs functions. +19
mrnutty 761 Senior Poster

combine your even and odd in one loop :

for(int num = start; num != end; ++num){
  if(num % 2 == 0) cout << num << " is even\n";
  else cout << num << "is odd\n";
}
mrnutty 761 Senior Poster

>>1. You emphasized on using const wherever I can, I'll but may I know why it is good?

Because making things const not only enables the compiler
to maybe optimize things, it also promises that the variable
wont be altered, and in general, if its not needed to be altered, then make it const.

>>2. If I use parameterless constructor like as u said Matrix(), how'll I initialize dimensions? I am not saying only have Matrix() constructor, have multiple overloaded constructor.

Matrix a ; //default constructor Matrix()
Matrix b = Matrix(3,3); // Matrix(const int& Row, const int& Col);
Matrix c = Matrix(3,3 0 ); //Matrix(const int& Row, const int& Col, const int& initValue);
a = Matrix(2,4); // init Matrix a.

>>3. Can you give me a little more hint on that private function, to be used in constructor?
Make a private function like the following pseudo function:

void _arithmeticHelper(const Matrix& other, const int& Operator){
 for i = 0 to Row
   for j = 0 to Col
    switch( Operator){
     case ADD : _myMatrix[i][j] + other._myMatrix[i][j]; break;
     case SUBTRACT : ... break;
     case MULTIPLY : ... break;
    }
}

Where ADD, SUBTRACT, and MULTIPLY is some private static const,
maybe declared like so :

class Matrix{
//private helpers
private: 
  static const int ADD = '+';
  static const int SUBTRACT = '-';
  static const int MULTIPLY = '*';
}

>>4. const-corrected means using const parameteres in functions?
There is more to it, look …

Nick Evan commented: Good suggestions +12
mrnutty 761 Senior Poster

I have commented on your code with code comments , see below :

#include<iostream>
using namespace std;
// A TEMPLATE CLASS WILL BE BETTER
class matrix //USUALLY A CLASS NAME SHOULD START WITH A CAPITAL LETTER( from convention)
{
 //is the user able to change these ? if not then make it constant
 int dim1,dim2; // a better name would be Row and Column
 int **mat;
 public:
 matrix(int x=2,int y=2) //No need for default ctor of that form. Either Matrix() or Matrix(const int  
                                     //MaxRow, const int MAXCOL)
 {
  dim1=x;
  dim2=y;
 //make a private function that does this, which will make you code neater
  mat=new int*[dim1];
  for(int i=0;i<dim1;i++)
	  mat[i]=new int[dim2];
  for(int i=0;i<dim1;i++)
   for(int j=0;j<dim2;j++)
    mat[i][j]=0;
 }
 int returndim1() //whats dim1 the Row or the column ?
 {
  return dim1;
 }
 int returndim2() //goto : returndim1 comment
 { 
  return dim2;
 }
 //why ?Just let the user handle this
 void input()
 {
  cout<<"Enter the elements of matrix - ";
  for(int i=0;i<dim1;i++)
   for(int j=0;j<dim2;j++)
    cin>>mat[i][j];
 }
 //out is a bad name, and what if user wan't a specific format ?
 void out()
 {
  for(int i=0;i<dim1;i++)
   {
    cout<<"\n";
    for(int j=0;j<dim2;j++)
	cout<<mat[i][j]<<" ";
   }
 } 
 //use const matrix x, also make this function const-corrected( look it up)
 matrix operator+(matrix x)
 {
  matrix c(dim1,dim2);
  if(dim1==x.returndim1() && dim2==x.returndim2())
   {    
    for(int i=0;i<dim1;i++)
      for(int j=0;j<dim2;j++)
	   c.mat[i][j]=this->mat[i][j]+x.mat[i][j];
	return c;
   }
  else
  {
   cout<<"Matrix cant be added";  
   return c;  
  }
 }
//goto comment on operator+
 matrix operator-(matrix x)
 {
  matrix c(dim1,dim2);
  if(dim1==x.returndim1() && dim2==x.returndim2())
   { 
    for(int i=0;i<dim1;i++)
      for(int j=0;j<dim2;j++)
	   c.mat[i][j]=this->mat[i][j]-x.mat[i][j];
	return …
vidit_X commented: Very informative. +2
mrnutty 761 Senior Poster

i want diz for my final project...tq

Really? I mean really ? I am utterly speechless. Really, you have got to be kidding?

mrnutty 761 Senior Poster

hello???
can you give me a complete program about a fraction calculator???

I'll give it to you for 1 zillion gazillion quintillion dollars?

mrnutty 761 Senior Poster

>> i am not dating but once you are into something real, you dont feel like you need females any more..

Sounds more If a hot girl hit on me, then I would be dating, but since I
do not have the courage to hit on hot girls, I found a hobby to keep me
occupied. :)

mrnutty 761 Senior Poster

They are the member variables. For example :

class Person{
private:
 //attributes
 int health;
 int power;
public:
 Person(){ ... };
}

So a health and strength is an attribute of a person.

mrnutty 761 Senior Poster

Is this not giving you an error :
"stream << hex << number;" ?

Make it stream <<std::hex << number; "

>> outputs a bunch of numbers
What what do you mean? In hex, just numbers could represent
some decimal numbers as well.

cwarn23 commented: Great info with quick replies +4
mrnutty 761 Senior Poster

Is this what you need :

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

using namespace std;

typedef size_t Type;

string toHex(const Type& number){
	stringstream stream;
	stream << hex << number;
	return stream.str();
}
int main(int argc, char *argv[])
{
	string num  = toHex(15);
	cout << num << endl;
 
    return 0;
}
kvprajapati commented: Solved! +6
mrnutty 761 Senior Poster

Usually C++ test are useless. A test just shows that you know definition( in a sense). It does not really show how well you program. Instead of looking for a test, how about you program a big project, with big being
subjective. Learn a new skill. Do you know anything about AI? Do you
know anything of templates and the crazy techniques one can do?
Bottom line, forget about a C++ test and go program some new things
to develop your understanding in a subject that is new to you, or enhance by creating better code on a subject you already know.

mrnutty 761 Senior Poster

>>u = new double[I*sizeof(double)];

No! This is not C. In C++ its used like this :
u = new double[ I ];

The value inside [ ], is the number of elements. No need for the sizeof.

Put your printing loop out side separately. Like this :

void Foo(const int Size, const double value = 0 )
{
   double *Array = new double[ Size];
  //initialize it
   for( int i = 0; i != Size; ++i){
     Array[i] = value;
   }

   //print it
   for(int i = 0; i != Size; ++i){  
     cout << Array[i] << " ";
  }
}
mrnutty 761 Senior Poster

Sin(x) = x - x^3/3! + x^5/5! + x^7/7! ...
Cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! ...
Cos(x) = Sin( x - 90 ) ; //assuming x is in degrees
Tan(x) = Sin(X)/cos(X)
"!" means factorial.

for example to calculate Sinus you can do this :

//Sin(x) = x - x^3/3! + x^5/5! + x^7/7! ...
float Sinus( float val ){
  float result = val - std::pow(val, 3.0) / factorial(3);
  result  += std::pow(val,5.0) / factorial(5);
  result  += std::pow(val,7.0) / factorial(7);
  result += std::pow(val,9.0) / factorial(7);
 return result;
}
mrnutty 761 Senior Poster

Some background.

We all used the string class, but some of you might not know that
string is just a typedef of basic_string.
In fact here is the typedef you might find when looking in the XString library.

typedef basic_string<char, char_traits<char>, allocator<char> >   string;

This code snippet shows you how to use basic_string to your
advantage. It has almost the same functionality as the string library
but it adds some functionality. It has little error checking. Again this
is shown as an example to learn from. Here is a list of things to
keep in mind :

- template class
- inheritance
- pointer function
- const correctness
- template functions
- scoped namespace
- assert function
- use of typedef

mrnutty 761 Senior Poster

Giggidy Giggidy Giggidy
- Family Guy, Quagmire.