I am writing a program for a class. Basically it has to do with mathematical sets. My professor gave us the following useSets.cpp and we were to write the MySets.cpp and MySets.h files. The only error I get now when I compile MySets.cpp is " [Linker error] undefined reference to `WinMain@16' ". When I compile useSets.cpp I get a crap load of errors and have no idea how to go about fixing them. If anyone can take a look at this, it would be greatly appreciated.
// FILE: useSets.cpp
#include "MySet.H"
#include <iostream> // used for cin, cout, etc
#include <cstdlib> // used for EXIT_SUCCESS
#include <ctime> // used to seed the random number generator
using namespace std;
int main() {
srand((unsigned)time(0)); // Seed the random number generator
MySet PossibleNumbers("Possible");
for(int i = 1; i <= 60; i++)
PossibleNumbers += i;
MySet Winners("WIN");
// RANDOMLY PICK 6 WINNING NUMBERS
while(Winners.cardinality() < 6) {
int randNum = 1 + (int)(60.0 * (rand()/(RAND_MAX + 1.0)));
if(!Winners.inSet(randNum))
Winners += randNum;
}
// TOM BUYS 10 LOTTERY TICKETS USING QUICK PICK
MySet *Tom;
Tom = new MySet[10];
for(int i = 0; i < 10; i++) {
Tom.setLabel("TOM");
while(Tom.cardinality() < 6) {
int randNum = 1 + (int)(60.0 * (rand()/(RAND_MAX + 1.0)));
if(!Tom.inSet(randNum))
Tom += randNum;
}
}
// JIM BUYS 1 LOTTERY TICKET USING HIS FAVORITE NUMBERS
MySet Jim("JIM");
Jim += 2;
Jim += 3;
Jim += 15;
Jim += 19;
Jim += 29;
Jim += 35;
cout << PossibleNumbers << endl;
// PRINT OUT THE WINNING NUMBERS
cout << Winners << endl;
for(int i = 0; i < 10; i++) {
cout << Tom << endl;
// PRINT NUMBERS TOM GOT RIGHT -- INTERSECTION WITH WINNERS
cout << " " << Tom * Winners << endl;
}
cout << Jim << endl;
// PRINT NUMBERS JIM GOT RIGHT
cout << " " << Jim * Winners << endl;
MySet A("TomsTotals");
for(int i = 0; i < 10; i++)
A += Tom;
cout << "Here are all the numbers Tom picked: " << endl;
cout << A << endl;
cout << "Here are the numbers Jim and Tom had in common " << endl;
cout << (A * Jim) << endl;
cout << "Here are the numbers Tom had that Jim did not " << endl;
cout << (A - Jim) << endl;
cout << "Here are the numbers Jim had that Tom did not " << endl;
cout << (Jim - A) << endl;
MySet Picked("PICKED"); // All of the numbers that were picked
Picked += Jim;
Picked += A;
MySet NotPicked("NOTPICKED"); // possible numbers not picked
NotPicked += PossibleNumbers - Picked;
cout << Picked << endl;
cout << NotPicked << endl;
return EXIT_SUCCESS;
}
If anyone wants the .cpp and .h files hosted somewhere, I can find a place to do that.
// FILE: useSets.cpp
#include "MySet.H"
#include <iostream> // used for cin, cout, etc
#include <cstdlib> // used for EXIT_SUCCESS
#include <ctime> // used to seed the random number generator
using namespace std;
int main() {
srand((unsigned)time(0)); // Seed the random number generator
MySet PossibleNumbers("Possible");
for(int i = 1; i <= 60; i++)
PossibleNumbers += i;
MySet Winners("WIN");
// RANDOMLY PICK 6 WINNING NUMBERS
while(Winners.cardinality() < 6) {
int randNum = 1 + (int)(60.0 * (rand()/(RAND_MAX + 1.0)));
if(!Winners.inSet(randNum))
Winners += randNum;
}
// TOM BUYS 10 LOTTERY TICKETS USING QUICK PICK
MySet *Tom;
Tom = new MySet[10];
for(int i = 0; i < 10; i++) {
Tom.setLabel("TOM");
while(Tom.cardinality() < 6) {
int randNum = 1 + (int)(60.0 * (rand()/(RAND_MAX + 1.0)));
if(!Tom.inSet(randNum))
Tom += randNum;
}
}
// JIM BUYS 1 LOTTERY TICKET USING HIS FAVORITE NUMBERS
MySet Jim("JIM");
Jim += 2;
Jim += 3;
Jim += 15;
Jim += 19;
Jim += 29;
Jim += 35;
cout << PossibleNumbers << endl;
// PRINT OUT THE WINNING NUMBERS
cout << Winners << endl;
for(int i = 0; i < 10; i++) {
cout << Tom << endl;
// PRINT NUMBERS TOM GOT RIGHT -- INTERSECTION WITH WINNERS
cout << " " << Tom * Winners << endl;
}
cout << Jim << endl;
// PRINT NUMBERS JIM GOT RIGHT
cout << " " << Jim * Winners << endl;
MySet A("TomsTotals");
for(int i = 0; i < 10; i++)
A += Tom;
cout << "Here are all the numbers Tom picked: " << endl;
cout << A << endl;
cout << "Here are the numbers Jim and Tom had in common " << endl;
cout << (A * Jim) << endl;
cout << "Here are the numbers Tom had that Jim did not " << endl;
cout << (A - Jim) << endl;
cout << "Here are the numbers Jim had that Tom did not " << endl;
cout << (Jim - A) << endl;
MySet Picked("PICKED"); // All of the numbers that were picked
Picked += Jim;
Picked += A;
MySet NotPicked("NOTPICKED"); // possible numbers not picked
NotPicked += PossibleNumbers - Picked;
cout << Picked << endl;
cout << NotPicked << endl;
return EXIT_SUCCESS;
}
If anyone wants the .cpp and .h files hosted somewhere, I can find a place to do that.
Last edited: