473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

About C/C++ Program Question....

2
I download IBM Synthetic Datat for Association rules(from http://www.almaden.ibm.com/cs/projects/iis/hdb/Projects/data_mining/datasets/syndata.html ),
After I compiler it, it found a lot of bug... Plese help me. Thank you for
your time.

Above is my operation environment:

Microsoft Visual C++ 6.0
MS Windows XP SP2

Above is dist.h
================================================== =====

#include "glob.h"

#define INIT_SEED -1

float ran0(long &idum);

//============================= Distributions =============================

class UniformDist;

class RandSeed
{
private:
static UniformDist *ran1;
public:
static void set_seed(long new_seed);
static long new_seed(void);
// Returns a random seed between 0 and MAXLONG, using
// INIT_SEED to initialize the random sequence.
};


// Returns a random deviate between 0.0 and 1.0 (exclusive of
// the endpoint values). Call with a negative integer to
// initialize.
//
#define NTAB 32
class UniformDist
{
private:
long idum;
long iy;
long iv[NTAB];

float ran1(void);
public:
UniformDist(void)
: iy(0) { idum = RandSeed::new_seed(); };
UniformDist(long seed)
: iy(0), idum(seed) {};
FLOAT operator()(void) // returns a random number between 0 and 1
{ return ran1(); };
};


class PoissonDist
{
private:
FLOAT lambda;
float sq,alxm,g,oldm;
UniformDist *ran1;

float poidev(float xm);
// Returns as a floating-point number an integer value that is
// a random deviate drawn from a Poisson distribution of mean xm.
public:
PoissonDist(FLOAT mean) //
: lambda(mean), oldm(-1.0) { ran1 = new UniformDist(); };
LINT operator()() // returns a random variable with Poisson dist.
{ return LINT( poidev(lambda) ); };
};


class NormalDist
{
private:
FLOAT mu; // mean
FLOAT sigma; // (std. deviation)^2
int iset;
float gset;
UniformDist *ran1;

float gasdev(void);
// Returns a normally distributed deviate with zero mean and
// unit variance.
public:
NormalDist(FLOAT m, FLOAT s) // mu, sigma
: mu(m), sigma(s), iset(0) { ran1 = new UniformDist(); };
FLOAT operator()() // returns a random variable with Normal dist.
{ return gasdev() * sigma + mu; };
};


class ExpDist
{
private:
float lambda;
UniformDist *ran1;

float expdev(void);
// Returns an exponentially distributed, positive, random
// deviate of unit mean.
public:
ExpDist(FLOAT mean = 1.0)
: lambda(mean) { ran1 = new UniformDist(); };
FLOAT operator()() // returns a random variable with an exp. distribution
{ return lambda * expdev(); };
};


// Used to choose k random numbers in the range [1..n]
//
class Choose
{
private:
LINT *num; // list of the positions
FLOAT *rval; // random value (used to get random ordering of the items)
public:
Choose(LINT n, LINT k);
~Choose(void);
LINT pos(LINT i) { return num[i]; }; // returns the i-th position
};


================================================== =====

Above is THE ERROR MESSAGE:
--------------------Configuration: IBMSynData - Win32 Debug------------------
--
Compiling...
main.c
d:\ibmsyndata\dist.h(5) : error C2143: syntax error : missing ')' before '&'
d:\ibmsyndata\dist.h(5) : error C2143: syntax error : missing '{' before '&'
d:\ibmsyndata\dist.h(5) : error C2059: syntax error : '&'
d:\ibmsyndata\dist.h(5) : error C2059: syntax error : ')'
d:\ibmsyndata\dist.h(9) : error C2061: syntax error :
identifier 'UniformDist'
d:\ibmsyndata\dist.h(9) : error C2059: syntax error : ';'
d:\ibmsyndata\dist.h(11) : error C2061: syntax error : identifier 'RandSeed'
d:\ibmsyndata\dist.h(11) : error C2059: syntax error : ';'
d:\ibmsyndata\dist.h(12) : error C2449: found '{' at file scope (missing
function header?)
d:\ibmsyndata\dist.h(20) : error C2059: syntax error : '}'
d:\ibmsyndata\dist.h(46) : error C2061: syntax error :
identifier 'PoissonDist'
d:\ibmsyndata\dist.h(46) : error C2059: syntax error : ';'
d:\ibmsyndata\dist.h(47) : error C2449: found '{' at file scope (missing
function header?)
d:\ibmsyndata\dist.h(61) : error C2059: syntax error : '}'
d:\ibmsyndata\dist.h(84) : error C2061: syntax error : identifier 'ExpDist'
d:\ibmsyndata\dist.h(84) : error C2059: syntax error : ';'
d:\ibmsyndata\dist.h(85) : error C2449: found '{' at file scope (missing
function header?)
d:\ibmsyndata\dist.h(98) : error C2059: syntax error : '}'
d:\ibmsyndata\gen.h(3) : fatal error C1083: Cannot open include
file: 'stream.h': No such file or directory
Error executing cl.exe.

main.obj - 19 error(s), 0 warning(s)

yours Sinerely,
Jun 27 '07 #1
2 2890
Likely the problem is the package is developed to work within C not C++. Many modern headers include some extra code in the headers to fix errors like this, but you may have to manually add it yourself. Try the following:

Expand|Select|Wrap|Line Numbers
  1. extern "C" {
  2. #include "glob.h"
  3. }
This tells the compiler that everything in between the {} is C code and should be compiled as such. Ideally this type of code would be in the header, but it doesn't hurt to add it here.

Unfortunately there are times where C packages cannot be used within C++, due to things like reserved words being used as variables names. So you may strike out on the above.
Jun 28 '07 #2
piuck
2
Likely the problem is the package is developed to work within C not C++. Many modern headers include some extra code in the headers to fix errors like this, but you may have to manually add it yourself. Try the following:

Expand|Select|Wrap|Line Numbers
  1. extern "C" {
  2. #include "glob.h"
  3. }
This tells the compiler that everything in between the {} is C code and should be compiled as such. Ideally this type of code would be in the header, but it doesn't hurt to add it here.

Unfortunately there are times where C packages cannot be used within C++, due to things like reserved words being used as variables names. So you may strike out on the above.

When I add

extern "C" {
#include "glob.h"
}

it found 2 errors:
--------------------Configuration: IBMSynData - Win32 Debug--------------------
Compiling...
main.c
d:\ibmsyndata\dist.h(2) : error C2059: syntax error : 'string'
d:\ibmsyndata\gen.h(3) : fatal error C1083: Cannot open include file: 'stream.h': No such file or directory
Error executing cl.exe.

main.obj - 2 error(s), 0 warning(s)

Another file gen.h is below:
//========the star of this file
#include "glob.h"
#include "dist.h"
#include <stream.h>
#include "fstream.h"


//============================= Parameters =============================


// Parameters used for StringSet
// StringSet can be either large itemsets, or sequences
//
//class StringSet;

class PatternPar {
public:
LINT npats; // number of patterns
FLOAT patlen; // average length of pattern
FLOAT corr; // correlation between consecutive patterns
FLOAT conf; // average confidence in a rule
FLOAT conf_var; // variation in the confidence
LINT seed;

PatternPar(void)
: npats(10000), patlen(4.0), corr(0.25), conf(0.75), conf_var(0.1), seed(0)
{}

void write(ostream &fp);
};


// Parameters used to generate transactions
//
class TransPar {
public:
LINT ntrans; // number of transactions in database
FLOAT tlen; // average transaction length
LINT nitems; // number of items
PatternPar lits; // parameters for potentially large itemsets
BOOLEAN ascii; // Generate in ASCII format
LINT seed; // Seed to initialize RandSeed with before x-act generation

TransPar(void)
: ntrans(1000000), tlen(10), nitems(100000), ascii(FALSE), seed(INIT_SEED)
{}

void write(ostream &fp);
};


// Parameters used to generate transactions
//
class TaxPar:public TransPar {
public:
LINT nroots; // number of roots
FLOAT fanout; // average fanout at each interiori node
FLOAT nlevels; // average number of levels
FLOAT depth_ratio; // affects ratio of itemsets chosen from higher levels

TaxPar(void)
: nroots(0), fanout(0), nlevels(0), depth_ratio(1)
{}

void calc_values(void); // calculates nroots, given nlevels
// default values: nroots = 250, fanout = 5
void write(ostream &fp);
};


// Parameters used to generate sequences
//
class SeqPar {
public:
LINT ncust; // number of customers in database
FLOAT slen; // average sequence length
FLOAT tlen; // average transaction length
LINT nitems; // number of items

FLOAT rept; // repetition-level (between 0 and 1)
FLOAT rept_var; // variation in repetition-level

BOOLEAN ascii; // Generate in ASCII format

PatternPar lits; // parameters for potentially large itemsets
PatternPar lseq; // parameters for potentially large sequences

SeqPar(void)
: ncust(100000), slen(10), tlen(2.5), nitems(10000),
rept(0), rept_var(0.1)
{
lits.npats = 25000;
lseq.npats = 5000;
lits.patlen = 1.25;
lseq.patlen = 4.0;
}

void write(ostream &fp);
};


//------------------------------ Taxonomy ------------------------------


//
// models taxonomy over items as a tree
// 0 is a valid item here (get rid of it when actually adding item
//
class Taxonomy
{
friend class TaxStat;
private:
LINT nitems; // number of items
LINT nroots; // number of roots
FLOAT depth; // used when assigning probabilities to items

LINT *par;
LINT *child_start;
LINT *child_end;

static const LINT item_len; // ASCII field-width of item-id
public:
Taxonomy(LINT nitems, LINT nroots, FLOAT fanout, FLOAT depth_ratio);
~Taxonomy(void);

void write(ofstream &fp); // write taxonomy to file
void write_asc(ofstream &fp); // write taxonomy to ASCII file
void display(ofstream &fp); // display taxonomy (for user)

FLOAT depth_ratio(void) { return depth; }
LINT num_roots(void) { return nroots; }
LINT root(Item itm) { return (par[itm] == -1); }

LINT num_children(Item itm) { return child_end[itm] - child_start[itm]; }
LINT child(Item itm, LINT n) { return child_start[itm]+n; }
// returns the n'th child of itm
LINT first_child(Item itm) { return child_start[itm]; }
LINT last_child(Item itm) { return child_end[itm]-1; }

Item parent(Item itm) { return par[itm]; } // -1 => no parent
};


//--------------------------------------------------------------------------


//
// 0 is a valid item here (get rid of it when actually adding item
//
class ItemSet
{
private:
LINT nitems; // number of items
Taxonomy *tax; // taxonomy (optional)
FLOAT *cum_prob; // cumulative probability
FLOAT *tax_prob; // cumulative probability of choosing a child
UniformDist rand;

void normalize(FLOAT prob[], LINT low, LINT high);
public:
ItemSet(LINT nitems, Taxonomy *tax = NULL);
~ItemSet();
void display(ofstream &fp);
Item get_item(void); // returns a random item (weighted)
Item specialize(Item itm); // if no taxonomy, returns itm
FLOAT weight(Item itm); // returns prob. of choosing item
};


class String
{
friend class StringSet;
LINT nitems; // number of items
Item *items; // list of the items
// FLOAT *rval; // random value (used to get random ordering of the items)
// Item *ritems; // randomly chosen items
FLOAT prob; // probability that this string is chosen
FLOAT conf; // probability that this string is corrrupted

// void shuffle(void); // shuffles items in string
public:
String(LINT nitems);
~String(void);

void display(ofstream &fp, LINT prob_comp = 1);
void display(ofstream &fp, StringSet &lits, LINT prob_comp = 1);
// prob is multiplied by prob_comp before being writeed

LINT size(void) { return nitems;}
Item item(LINT n) { return items[n];} // return nth item of the string
FLOAT conf_lvl(void) { return conf; }

void set_size(LINT newsize) { nitems = newsize;}
void set_item(LINT n, Item itm) { items[n] = itm;}
void set_conf_lvl(FLOAT newconf) { conf = newconf; }

// void shuffle(LINT k); // allows selection of k random items from the string
// Item rand_item(LINT n) { return ritems[n];} // works with shuffle
};

typedef String *StringP;


class StringSet
{
friend class StringSetIter;
private:
ItemSet *items;
Taxonomy *tax;
LINT npats; // number of patterns
StringP *pat; // array of patterns
StringP answer;
FLOAT *cum_prob; // cumulative probabilities of patterns

StringP specialize(LINT i); // specializes pattern #i
public:
StringSet(LINT nitems, // number of items
PatternPar par, // npats, patlen, corr, conf & conf_var
Taxonomy *tax = NULL, // taxonomy (optional)
FLOAT rept = 0, // repetition-level
FLOAT rept_lvl = 0.2 // variation in repetition-level
);
~StringSet();
void display(ofstream &fp); // for large itemsets
void display(ofstream &fp, StringSet &lit); // for sequences
StringP get_pat(LINT i); // returns pattern #i
};


class StringSetIter
{
private:
UniformDist rand;
StringSet *strset;
LINT last_pat; // if -ve, unget_pat() was called
public:
StringSetIter(StringSet &str_set) : strset(&str_set), last_pat(0) {};
StringP get_pat(void); // returns a random pattern
void unget_pat(void); // the last pattern is put back in the sequence
};


//--------------------------------------------------------------------------


class Transaction {
private:
LINT tlen; // expected number of items in transaction
LINT nitems; // number of items currently in transaction
LINT maxsize; // size of array items
LINT *items; // items in the transaction

static const LINT cid_len; // ASCII field-width of customer-id
static const LINT tid_len; // ASCII field-width of transaction-id
static const LINT item_len; // ASCII field-width of item-id

static LINT tid; // transaction-id

void sort(void);
BOOLEAN add_item(LINT itm);// returns TRUE if added, FALSE if already present
public:
Transaction(LINT sz);
~Transaction();

BOOLEAN add(String &pat, BOOLEAN corrupt = TRUE);
// adds pattern to transaction
// returns TRUE if added, FALSE if trans. full
void write(ofstream &fp, LINT cid = 0);
void write_asc(ofstream &fp, LINT cid = 0);
LINT size(void) { return nitems; }
};

typedef Transaction *TransactionP;


class CustSeq {
private:
Cid cid; // customer-id
LINT slen; // expected number of transactions in sequence
LINT tlen; // avg. expected number of items in a transaction
LINT ntrans; // number of transactions in sequence
LINT nitems; // number of items in sequence
LINT maxsize; // size of array trans
TransactionP *trans; // transaction in the sequence

public:
CustSeq(Cid cid, LINT seq_len, LINT tot_items);
~CustSeq(void);

BOOLEAN add(String &pat, StringSet &lits); // adds pattern to transaction
void write(ofstream &fp);
void write_asc(ofstream &fp);
LINT size(void) { return nitems; }
};
//=======================the end of this file
Jun 28 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Tony Johansson | last post by:
Hello experts!! I reading in a book about C++ and there is something that I'm not sure about. I don't belive that the book is wrong but I will just ask you out there what you think. The book...
6
by: jalkadir | last post by:
As I wrote the subject of this message, I got a cold feeling about this question, I have realized that this is not only a programmer question, but it is also a question about one the most...
47
by: sunglo | last post by:
Some time a go, in a discussion here in comp.lang.c, I learnt that it's better not to use a (sometype **) where a (void **) is expected (using a cast). Part of the discussion boiled down to the...
28
by: Wonder | last post by:
Hello, I'm confused by the pointer definition such as int *(p); It seems if the parenthesis close p, it defines only 3 integers. The star is just useless. It can be showed by my program: ...
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
4
by: Tony | last post by:
Hello! Below I have a complete working program.with some simple classes one of these is a generic class. The question is about this method GetCows() {...} which is a member in the generic...
13
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.