Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
| Search | Today's Posts | Mark Forums Read
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2004, 02:40 AM
Registered User
 
Join Date: Jul 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Porting simple code from Borland to VC++

Hi,

I get:
error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup

when there is a main() function. It works fine in Borland 5.5

Any ideas?

Thanks

/************************************************** ********************
Filename: poker.cpp
Chapter: 4 Classes
Compiler: Borland C++ Version 5.01 Summer 1998
C++ for C Programmers, Edition 3 By Ira Pohl
************************************************** ******************/
#include <iostream>
#include <stdlib>
using namespace std;

enum suit { clubs, diamonds, hearts, spades };

class pips {

public:
    void assign(int n) { p = n % 13 + 1; }
    int getpip() { return p; }
    void print() { cout << p; }

private:
    int p;
};

class card {

public:
    suit s;
    pips p;
    void assign(int n)
    { cd = n; s = static_cast<suit>(n/13); p.assign(n); }
    void pr_card();

private:
    int cd; //a cd is from 0 to 51
};


class deck {

public:
    void init_deck();
    void shuffle();
    void deal(int, int, card*);
    void pr_deck();

private:
    card d[52];
};

void deck::init_deck()
{
    for (int i = 0; i < 52; ++i)
        d[i].assign(i);
}

void deck::shuffle()
{
    for (int i = 0; i < 52; ++i) {
        int k = i + (rand() % (52 - i));
        card t = d[i]; //swap cards
        d[i] = d[k];
        d[k] = t;
    }
}

void deck::deal(int n, int pos, card* hand)
{
    for (int i = pos; i < pos + n; ++i)
        hand[i - pos] = d[i];
}

int main()
{
    card one_hand[9]; //max hand is 9 cards
    deck dk;

    int i, j, k, fcnt = 0, sval[4];
    int ndeal, nc, nhand;

    do {
        cout << "\nEnter no. cards in a hand (5-9):";
        cin >> nc;
    } while (nc < 5 || nc > 9);

    nhand = 52 / nc;
    cout << "\nEnter no. of hands to deal: ";
    cin >> ndeal;

    srand(time(NULL)); //seed rand() from time()

    dk.init_deck();

    for (k = 0; k < ndeal; k += nhand) {

        if ((nhand + k) > ndeal)
            nhand = ndeal - k;

        dk.shuffle();

        for (i = 0; i < nc * nhand; i += nc) {
            for (j = 0; j < 4; ++j) //zero suit counts
                sval[j] = 0;

            dk.deal(nc, i, one_hand); //deal next hand

            for (j = 0; j < nc; ++j)
                sval[one_hand[j].s]++; //increment suit count

            for (j = 0; j < 4; ++j)
                if (sval[j] >= 5) //5 or more is flush
                    fcnt++;
        }
    }

    cout << "\n\nIn " << ndeal << " ";
    cout << nc << "-card hands there were ";
    cout << fcnt << " flushes\n ";

    int look; cin >> look;
}
 
Old December 18th, 2004, 08:43 PM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First, you need to create a Windows Console Application. Under File->New, select Win32 Console Application. Give it a name over on the right and click OK. In the next window, select "An empty project", click "Finish" then "OK" in next window. Then go to File->New again, and under Files tab, select C++ Source File. Copy and paste the following revised code into the .cpp file and run.

/************************************************** ********************
Filename: poker.cpp
Chapter: 4 Classes
Compiler: Borland C++ Version 5.01 Summer 1998
C++ for C Programmers, Edition 3 By Ira Pohl
************************************************** ******************/
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

enum suit { clubs, diamonds, hearts, spades };

class pips {

public:
    void assign(int n) { p = n % 13 + 1; }
    int getpip() { return p; }
    void print() { cout << p; }

private:
    int p;
};

class card {

public:
    suit s;
    pips p;
    void assign(int n)
    { cd = n; s = static_cast<suit>(n/13); p.assign(n); }
    void pr_card();

private:
    int cd; //a cd is from 0 to 51
};


class deck {

public:
    void init_deck();
    void shuffle();
    void deal(int, int, card*);
    void pr_deck();

private:
    card d[52];
};

void deck::init_deck()
{
    for (int i = 0; i < 52; ++i)
        d[i].assign(i);
}

void deck::shuffle()
{
    for (int i = 0; i < 52; ++i) {
        int k = i + (rand() % (52 - i));
        card t = d[i]; //swap cards
        d[i] = d[k];
        d[k] = t;
    }
}

void deck::deal(int n, int pos, card* hand)
{
    for (int i = pos; i < pos + n; ++i)
        hand[i - pos] = d[i];
}

int main()
{
    card one_hand[9]; //max hand is 9 cards
    deck dk;

    int i, j, k, fcnt = 0, sval[4];
    int ndeal, nc, nhand;

    do {
        cout << "\nEnter no. cards in a hand (5-9):";
        cin >> nc;
    } while (nc < 5 || nc > 9);

    nhand = 52 / nc;
    cout << "\nEnter no. of hands to deal: ";
    cin >> ndeal;

    srand(time(NULL)); //seed rand() from time()

    dk.init_deck();

    for (k = 0; k < ndeal; k += nhand) {

        if ((nhand + k) > ndeal)
            nhand = ndeal - k;

        dk.shuffle();

        for (i = 0; i < nc * nhand; i += nc) {
            for (j = 0; j < 4; ++j) //zero suit counts
                sval[j] = 0;

            dk.deal(nc, i, one_hand); //deal next hand

            for (j = 0; j < nc; ++j)
                sval[one_hand[j].s]++; //increment suit count

            for (j = 0; j < 4; ++j)
                if (sval[j] >= 5) //5 or more is flush
                    fcnt++;
        }
    }

    cout << "\n\nIn " << ndeal << " ";
    cout << nc << "-card hands there were ";
    cout << fcnt << " flushes\n ";

    int look; cin >> look;
    return 0;
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
porting ch18 sample code to new kernels ninuzzo BOOK Beginning Linux Programming, 3rd Edition 1 February 12th, 2007 12:50 PM
Very Simple code Tal1481 Beginning VB 6 9 January 29th, 2007 11:12 AM
Very Simple code Tal1481 Visual Basic 2005 Basics 1 January 25th, 2007 07:15 AM
Regions in the VC . NET code iceonfire VS.NET 2002/2003 2 September 12th, 2006 06:45 PM
Internet Explorer from VC#.NET code sachin-csharp C# 2005 1 September 18th, 2004 01:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.