home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume36
/
formes
/
part01
/
quizset.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-01
|
2KB
|
104 lines
/*
* Copyright (C) 1992-1993 Jeffrey Chilton
*
* Permission is granted to anyone to make or distribute copies of
* this program, in any medium, provided that the copyright notice
* and permission notice are preserved, and that the distributor
* grants the recipient permission for further redistribution as
* permitted by this notice.
*
* Author's E-mail address: 172-9221@mcimail.com
*
*/
static char *whatstring = "@(#)quizset.c 2.2 JWC";
#include <stdio.h>
#include <time.h>
#include "class.h"
#include "quizset.h"
#include "random.h"
extern Random *Squizzer;
QuizSet *
QuizSet_new()
{
QuizSet *self;
self = (QuizSet *)malloc(sizeof (QuizSet));
if (!self)
{
fprintf(stderr, "QuizSet_new: malloc fails\n");
goto out;
}
self->allQuizs = Collection_new(NULLMATCH, Quiz_destroy);
if (!self->allQuizs)
{
free(self);
self = (QuizSet *)0;
fprintf(stderr, "QuizSet_new: Collection new fails\n");
goto out;
}
out:
return self;
}
void
QuizSet_addOne(self, quiz)
QuizSet *self;
Quiz *quiz;
{
Collection_add(self->allQuizs, (char *)quiz);
}
Quiz *
QuizSet_getOneAtRandom(self)
QuizSet *self;
{
unsigned long n;
Quiz *quiz;
n = Random_long(Squizzer) % Collection_size(self->allQuizs);
quiz = (Quiz *)Collection_atGet(self->allQuizs, (int )n);
return quiz;
}
Quiz *
QuizSet_getOneFromClass(self, class)
QuizSet *self;
int class;
{
Quiz *quiz;
/* TEMPORARY [crude beyond words] */
quiz = QuizSet_getOneAtRandom(self);
while (Quiz_getClass(quiz) != class)
{
quiz = QuizSet_getOneAtRandom(self);
}
return quiz;
}
void
QuizSet_destroy(self)
QuizSet *self;
{
Collection_destroy(self->allQuizs);
free(self);
}