Category : Files from Magazines
Archive   : CUJ0894.ZIP
Filename : STRTST3C.CPP

 
Output of file : STRTST3C.CPP contained in archive : CUJ0894.ZIP
Listing 6 - A test program for the strq wrapper class with an output
operator

//
// strtst3c.cpp - test genq3 using str elements
//

#include

#include "showheap.h"
#include "strq3.h"

ostream *os_ptr;

void print_str(void *e)
{
*os_ptr << ' ' << *(str *)e;
}

ostream &operator<<(ostream &os, strq &q)
{
os_ptr = &os;
q.apply(print_str);
return os;
}

#define DIM(a) (sizeof(a)/sizeof(a[0]))

void test()
{
char c;
size_t qn;
str qe;
strq q[4];
while (cin >> c)
{
showheap();
if (c == 'q')
break;
if (c == 'a')
{
cin >> qn >> qe;
if (qn >= DIM(q))
cout << "no such queue\n";
else
q[qn].append(qe);
}
else if (c == 'c')
{
cin >> qn;
if (qn >= DIM(q))
cout << "no such queue\n";
else
q[qn].clear();
}
else if (c == 'r')
{
cin >> qn;
if (qn >= DIM(q))
cout << "no such queue\n";
else if (q[qn].remove(qe))
cout << "removed " << qe << '\n';
else
cout << "q[" << qn << "] is empty\n";
}
else
continue;
for (size_t i = 0; i < DIM(q); ++i)
cout << i << ':' << q[i] << '\n';
}
}

int main()
{
showheap();
test();
showheap();
return 0;
}


  3 Responses to “Category : Files from Magazines
Archive   : CUJ0894.ZIP
Filename : STRTST3C.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/