
-----------------------------------
tinhnho
Mon Mar 22, 2004 1:01 pm

Cycle() and print() function
-----------------------------------
Hi everyone
please help me this proplem,i'm really appreciate.
Question:
Write a cycle, and print function follow difination

template
void cycle(TYPE& a,TYPE& b, TYPE& c)
{
    //replace a's value by b's value and b's by c's and c's by a's

}

note: i sitll working on it,sorry if my code look messed up.Should i use this ?:
[code]
template 
class triple
{
public:
    ...........

private:
   TYPE a,b,c;
}[/code]

-----------------------------------
xtxnx
Mon Mar 22, 2004 4:34 pm


-----------------------------------
i think you should do :
template
class triple
{



}

int main()
{

 .....
 return 0.
}

void cycle(Type& a, Type& b, Type& c)
{
 .....
}


void print(Type& a, Type& b, Type& c)
{
............
}

good luck

-----------------------------------
Tony
Mon Mar 22, 2004 5:29 pm


-----------------------------------
it looks like your code is wrong. You're replacing one variable with another, not switching them around. So when A becomes B, B does not become A (it  becomes C)

so


temp = a;
a = b;
b = c;
c = temp;

 :wink:

-----------------------------------
wtd
Mon Mar 22, 2004 7:05 pm


-----------------------------------
You could certainly wrap it up in a class.  This has one small error, but shift_right works.

#include 

template 
class bundle
{
   private:
      _t storage[_length];
      unsigned int number_stored;
   public:
      bundle();
      void add(_t);
      _t at(unsigned int) const;
      bool full();

      template 
      void shift_right();

      template 
      friend std::ostream& operator