Okay, so I've gotten my second project in C++ and this seems pretty extream for a second project to me, but I'm determined to get this working. so my teacher suplied two header files (set.h and bingoball.h) our job is to take those files and program a bingoball.cpp and a set.cpp, he will than make a generic main.cpp to test our codes. I'm having a lot of trouble with calling functions from other files, I've just started writing the first function of creating a new random bingo ball from 1-75 that than adds the appropriate number. and I just wanted to test that it was working before moving on to more functions, but my lack of knowledge on the syntex of multiple files is holding me back. if someone could help me figure out how to call functions to an object I created and clairify what I'm doing horibly horibly wrong that would be awesome. Currently I get a LNK2019 error when I try to compile for "unresolved external symbol".....

I'm sorry, but this is just gonna be bad.

set.h provided by teacher that is not allowed to be changed:

#ifndef SET_H
#define SET_H
#include <string>

using namespace std;

template <class type>

class set 
{
public:
    explicit set();
    //constructs an empty set of objects

    type remove();
    //removes a random element of the set and returns it
    //else returns null

    type remove(type t);
    //removes a specific element of the set and returns it if it exists
    //returns null if it doesn't

    bool add(type t);
    //adds a specific element to the set if not already there
    //returns true if it is successful and false if not

    string toString();
    //prints out the entirety of the set
};

#endif  /* SET_H */

bingoball.h file provided by the teacher and not allowed to be changed:

#ifndef BINGOBALL_H
#define BINGOBALL_H
#include <string>
#include <stdexcept>

using namespace std;

class bingoBall 
{
private:
    int num;
    char letter;
public:
    explicit bingoBall();
    //constructs a random bingoBall which a member of the universe of bingoBalls

    explicit bingoBall(int) throw(invalid_argument); 
    //constructs a bingoBall of number int (1-75) if outside of range, throw()
    //assigns char as follows
    //int =  1-15 = B 
    //int = 16-30 = I
    //int = 31-45 = N
    //int = 46-60 = G
    //int = 61-75 = O

    explicit bingoBall(int, char) throw(invalid_argument); 
    //constructs a bingoBall of number int and letter char 
    //must be validated if char or int is outside of range, throw()

    bool isEqual(bingoBall b);
    //compares self to b, return true if equal, otherwise return false

    string toString();
    //returns a string of the balls value e.g.: "B7"

};

#endif  /* BINGOBALL_H */

The hell that is what I've tried to code for BingoBall.cpp:

#include "BingoBall.h"
#include "Set.h"
#include <string>
#include <ctime>
#include <cstdlib>
#include <iostream>

using namespace std;
void BingoBall();
void isEqual();
string toString();
int ballValue = 0;
string ballName = "";
string tempChar = "";
int tempValue = 0;
string tempBallName = "";

bingoBall::bingoBall()
{

}

static void bingoBall()
{
    ballValue = rand() % 75 + 1;
    if (ballValue < 16)
    {
        ballName = "B" +ballValue;
    }
    else if (ballValue < 31)
    {
        ballName = "I" +ballValue;
    }
    else if (ballValue < 46)
    {
        ballName = "N" +ballValue;
    }
    else if (ballValue < 61)
    {
        ballName = "G" +ballValue;
    }
    else if (ballValue < 76)
    {
        ballName = "O" +ballValue;
    }


}



void isEqual()
{

}

static string toString()
{
    return ballName;
}

I don't see any reason this should not work so I can only assume I am encountering more than one syntex problem...
my set.cpp is nothing but defined functions with nothing in them so far.

and these are the two diffrent methods that I've tried to put in a main file to call on bingoBall();

    bingoBall bingoBall_obj;
    bingoBall bingoBall();
    cout << bingoBall_obj.bingoBall();

    bingoBall* bingoBall_obj = new bingoBall();
    bingoBall_obj -> bingoBall();
    cout << bingoBall_obj -> toString();

any help at all would be great, I've only been in this class for 4 weeks, and this is only our second project...this class does not teach us c++, but it requires us to know it, so I'm sucking I know, but at least I'm trying.

well, as testing the program would be nice, but not really required I guess I can just finish the files and hope they work when my teacher writes the main.cpp... not really sure if my problem lies in how I'm calling them or in how they are written...

First of all in your Bingoball.cpp the if else statements are not proper.
Your teacher wrote in the bingoball.h file:

 //assigns char as follows
    //int =  1-15 = B 
    //int = 16-30 = I
    //int = 31-45 = N
    //int = 46-60 = G
    //int = 61-75 = O

So your first if statement should be:

  if (ballValue >= 1 && ballValue <= 15)//Between and including 1 and 15 
    {
        ballName = "B" +ballValue;
    }

Now you can continue with the other else if statements according to the assigning chars as written by your teacher.

the reason I did not account for less than 1 for that function is it creates a random bingo ball between 1-75 so I know the number range is right, no human error need be accounted for, I just need a main.cpp to be able to call it. just not sure how it all works.

how my bingoBall.cpp looks now

#include "BingoBall.h"
#include "Set.h"
#include <string>
#include <ctime>
#include <cstdlib>
#include <iostream>

using namespace std;
void BingoBall();
bool isEqual();
string toString();
int ballValue = 0;
string ballName = "";
char tempChar;
int tempValue = 0;
string tempBallName = "";
int b = 0;
char B = B;
char I = I;
char N = N;
char G = G;
char O = O;

bingoBall::bingoBall()
{

}

static void bingoBall()
{
    ballValue = rand() % 75 + 1;
    if (ballValue < 16)
    {
        ballName = "B" +ballValue;
    }
    else if (ballValue < 31)
    {
        ballName = "I" +ballValue;
    }
    else if (ballValue < 46)
    {
        ballName = "N" +ballValue;
    }
    else if (ballValue < 61)
    {
        ballName = "G" +ballValue;
    }
    else if (ballValue < 76)
    {
        ballName = "O" +ballValue;
    }


}

static void bingoBall(int ballValue) throw(invalid_argument)
{
    if (ballValue < 0)
    {
        try
        {
            throw 76;
        }
        catch (int e)
        {
            cout<< "An error occurred. did you enter a number between 1-75?" << endl;
        }
    }
    if (ballValue < 16)
    {
        ballName = "B" +ballValue;
    }
    else if (ballValue < 31)
    {
        ballName = "I" +ballValue;
    }
    else if (ballValue < 46)
    {
        ballName = "N" +ballValue;
    }
    else if (ballValue < 61)
    {
        ballName = "G" +ballValue;
    }
    else if (ballValue < 76)
    {
        ballName = "O" +ballValue;
    }
    else
        try
    {
        throw 76;
    }
    catch (int e)
    {
        cout<< "An error occurred. did you enter a number between 1-75?" << endl;
    }
}

static void bingoBall(int num, char letter) throw(invalid_argument)
{
    num = ballValue;
    letter = tempChar;
    if (ballValue >= 1 && ballValue <= 15 && tempChar ==B)
    {
        ballName = tempChar +ballValue;
    }
    else if (ballValue >= 16 && ballValue <= 30 && tempChar == I)
    {
        ballName = tempChar +ballValue;
    }
    else if (ballValue >= 31 && ballValue <= 45 && tempChar == N)
    {
        ballName = tempChar +ballValue;
    }
    else if (ballValue >= 46 && ballValue <= 60 && tempChar == G)
    {
        ballName = tempChar +ballValue;
    }
    else if (ballValue >= 61 && ballValue <= 75 && tempChar == O)
    {
        ballName = tempChar +ballValue;
    }
    else 
        try
    {
        throw 76;
    }
        catch (int e)
    {
        cout<< "An error occurred. did you enter a number between 1-75?" << endl;
    }
}

static bool isEqual()
{
    if (ballValue == b)
    {
        return true;
    }
    else return false;
}

static string toString()
{
    return ballName;
}

so apparently that is as wrong as wrong can be, and I have no idea why. JOY!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.