SHWOO 25 Junior Poster in Training

This function is supposed to open a file stream and copy the text into an integer array to be used for a map key. Here is the contents of the file. I am getting the decimal value stored in the array and I just cannot figure out how to correct the problem. I tried casting, atoi(), and other stuff, but I am still not figuring it out.

0000000000000000
0111110000000000
0111110222220000
0111111222220000
0111110222220000
0111110222220000
0000010222220000
0000030020000000
0000333330000000
0000333330000050
0000333330444440
0000333333444440
0000333330444440
0000000000444440
0000000000444440
0000000000000000

void map::initMapKey()
{
	j_mapFile.open( jMapName, std::ios_base::in);		// open the file for storing
	j_mapFile.flags( std::ios_base::dec);

	if(!j_mapFile.is_open() )
	{
		cout << "File could not be opened!";
	}
	else{

		for(int i=0;i<jMaxRows;i++)					// loop for each row
		{
			for(int j=0;j<jMaxCols;j++)
			{	
				int myInt = j_mapFile.get();
				j_mapKey[i][j] = myInt;
			}
					
		
		}
	}
	j_mapFile.close();
}
SHWOO 25 Junior Poster in Training

ahnoldschwarz said he wants to be a game designer, not a game programmer. I would start out by learning the basic concepts of programming, i.e. variables, control statements, and other concepts that are apparent in just about any language. I would then go on to learn a scripting language such as Python, Ruby, or Lua.

Game designers generally do not do a whole lot of programming in most projects. When they do write some code it is usually writing up scripts for designing a game level or things of that nature.

If you want to get into game design you should build your skills in the area of game documentation and practice making clear, informative, and practical documentation. Work on building any kind of prototype you can to get a feel for the things that may work well in your design and things that may need to be changed or eliminated. I don't understand why everyone is suggesting all of these different programming languages to someone who desires to get into game design.

Salem commented: Spot on!! Excellent. +25
SHWOO 25 Junior Poster in Training
while((board.getgXPos() != board.getXPos()) && (board.getgYPos() != board.getYPos()))
{
system("cls");
board.printBoard();
board.moveBall();
}

I would like this while statement to continue repeating until both gxPos equals XPos & gyPos equals YPos.

I can't seem to figure out why the statement exits if either both x's are the same or if both y's are the same.

SHWOO 25 Junior Poster in Training

My fogMap array was printing fine then I integrated the menu into it and now I am getting an error. When I select the option to play the game my mapFog array outputs, but after that the program breaks and says "No symbols are loaded for any call stack frame. The source code cannot be displayed" What does that mean?

Also, by that description, what would I be looking for in the disassembly?

TITLE MASM Template						(main.asm)

; Program: Maze Game
; Author: Jon Wayman
; Created Date: July 22nd,2008
; Revision date:

INCLUDE Irvine32.inc
INCLUDE Macros.inc


.data
PlNrame	byte 25 DUP(?)		; player's name
score	byte ?			; player's score

msgInput	byte	"Please enter your first name:",0

msgMenu	byte "|---------------------------|",0dh,0ah
          byte "|             MENU:         |",0dh,0ah
          byte "| 1. Play MASM MAZE MADNESS |",0dh,0ah
          byte "| 2. How To Play            |",0dh,0ah
          byte "| 3. Exit Program           |",0dh,0ah
          byte "|---------------------------|",0dh,0ah
		byte "Enter Selection: ",0

msgHelp	byte "|-----------------------------------------|",0dh,0ah
          byte "|                 HELP!                   |",0dh,0ah
		byte "|                                         |",0dh,0ah
		byte "|   Use the arrow keys to move around     |",0dh,0ah
		byte "|                                         |",0dh,0ah
		byte "|   collect these items to get points     |",0dh,0ah 
		byte "|   and get to the end of the maze.       |",0dh,0ah								   
		byte "|                                         |",0dh,0ah
		byte "|   $ = 100 Points      & = 25 Points     |",0dh,0ah
		byte "|   * = 50 Points       + = 10 Points     |",0dh,0ah
		byte "|                                         |",0dh,0ah
		byte "|   But watch out for these ones.         |",0dh,0ah
		byte "|                                         |",0dh,0ah
		byte "|   ! = -50 Points      ^ = -15 Points    |",0dh,0ah
		byte "|-----------------------------------------|",0

COLS …
SHWOO 25 Junior Poster in Training

Visual C++ 2005 Express

SHWOO 25 Junior Poster in Training

I am trying to print a two-dimensional array to the screen. My algorithm probably isn't correct but I am having trouble even getting the process to work.

on the call I get ----error A2206: missing operator in expression
This line add ebx,tmpRowSize * rowIndex I get ------error A2026: constant expected

Thanks in advance for any input

TITLE MASM Template						(main.asm)

; Program: Maze Game
; Author: Jon Wayman
; Created Date: July 22nd,2008
; Revision date:

INCLUDE Irvine32.inc
INCLUDE Macros.inc


.data
COLS	= 20
ROWS	= 3
map		BYTE	23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h
RowSize	= ($ - map)
		BYTE 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h
		BYTE 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h, 23h
.code
main PROC

call	printMap RowSize


	exit
main ENDP

printMap PROC, tmpRowSize
LOCAL rowIndex, colIndex, count

	pushad
	mov	rowIndex,0
	mov	colIndex,0
	mov	ebx,OFFSET map
	add	ebx,tmpRowSize * rowIndex
	mov	esi,colIndex
	mov	ecx,ROWS				; outer loop count
	jmp	mapL2

mapL1:
	mov	count,ecx
	mov	ecx,COLS
	call crlf
mapL2:
	mov	al,[ebx + esi]
	call	writechar
	loop	mapL2
	
	mov	ecx,count				; outer loop count
	loop mapL1

	popad
	ret

printMap ENDP

END main
SHWOO 25 Junior Poster in Training

Why isn't the mReadkey macro outputting the string "Please enter...." ?

TITLE MASM Template						(main.asm)

; Program: Chapter 10 Problem 1-5
; Author: Jon Wayman
; Created Date: July 17th,2008
; Revision date:

INCLUDE Irvine32.inc
INCLUDE Macros.inc

;-------------------------------
mReadkey MACRO
;
; This macro asks user to press any key
; and it will store the ASCII and scan codes.

	mWriteLn "Please enter a key to output its ASCII & keyboard code: "

	mov	eax,10
	call Delay
	call Readkey

	ENDM
;-------------------------------

.data
ascii BYTE ?
scan BYTE ?
.code

mReadkey

main PROC


	exit
main ENDP

	; (insert addiitonal procedures here)
END main

mWriteLn & mWrite implementation

;------------------------------------------------------
mWrite MACRO text:REQ
;
; Writes a string literal to standard output.
; Receives: a string enclosed in single or double 
;   quotes (null terminator not required).
;------------------------------------------------------
LOCAL string
	.data		;; local data
	string BYTE text,0	;; define the string
	.code
	push	edx
	mov	edx,OFFSET string
	call	WriteString
	pop	edx
ENDM

;------------------------------------------------------
mWriteLn MACRO text:REQ
;
; Writes a string literal to standard output, followined by Crlf
; Receives: a string enclosed in single or double 
;   quotes (null terminator not required).
; DEPRECATED in the Fifth edition.
;------------------------------------------------------
	mWrite text
	call	Crlf
ENDM
SHWOO 25 Junior Poster in Training

I am stuck on problem 7 that is outlined clearly. I am trying to create a process that changes all of the non-prime number elements of a 65,000 element array to 1. Then I would like to verify that array was marked correctly so that only prime numbers have 0's at their location in the array. The displayArray process should display 1,3,5,7,11,13 etc. up to 65,000.


There is an include file also
Thanks for your help

TITLE MASM Template						(main.asm)

; Program: Chapter 9 Problems 1,2,7
; Author: Jon Wayman
; Created Date: July 11th,2008
; Revision date:

INCLUDE Irvine32.inc
.data
intVal DWORD ?
sString BYTE "This string is 34 characters long.",0
tString BYTE 100 DUP (?)
msgMaxStr BYTE "Enter the maximum string size to copy: ",0
targetStr BYTE "ABCED",10 DUP(0)
sourceStr BYTE "FGH",0

.data?
count = 65000				; 65,000 element array
sieve DWORD count DUP(?)

.code
main PROC

;------------- Problem 1 -----------------
mov	edx,OFFSET msgMaxStr		;move Max String size message
call writestring				;write message to console
call crlf

call readint					;Read an integer value for Str_copyN
mov	intVal,eax
mov	ebx,eax

push	OFFSET tString
push OFFSET sString
call Str_copyN	

mov edx,OFFSET tString
call writestring
call crlf
;------------- Problem 1 -----------------

;------------- Problem 2 -----------------

push OFFSET targetStr			; push the offest of the target
push OFFSET sourceStr			; push the offset of the source
call Str_concat

mov edx,OFFSET targetStr
call writeString
call crlf

;------------- Problem 2 -----------------

;------------- Problem 7 -----------------

push count
push OFFSET sieve …
SHWOO 25 Junior Poster in Training

The problem was that I was trying to use functions in the engine before I created the engine itself. I solved the problem by moving the new Engine( &setup) above the three functions I was testing.

SHWOO 25 Junior Poster in Training

I am trying to create a set of functions to allow the user to output a string to a file name EngineLog.txt

It compiles fine, but I get an Unhandled exception at 0x00444c36 in Test.exe: 0xC0000005: Access violation writing location 0x0000000d. This occurs in the EnableLogging() function.

//-----------------------------------------------------------------------------
// The primary engine header file. This file links the entire engine together
// and is the only header file that needs to be included in any project using
// the engine.
//
// Programming a Multiplayer First Person Shooter in DirectX
// Copyright (c) 2004 Vaughan Young
//-----------------------------------------------------------------------------
#ifndef ENGINE_H
#define ENGINE_H

//-----------------------------------------------------------------------------
// DirectInput Version Define
//-----------------------------------------------------------------------------
#define DIRECTINPUT_VERSION 0x0800

//-----------------------------------------------------------------------------
// System Includes
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <tchar.h>
#include <windowsx.h>

//-----------------------------------------------------------------------------
// DirectX Includes
//-----------------------------------------------------------------------------
#include <d3dx9.h>
#include <dinput.h>
#include <dplay8.h>
#include <dmusici.h>

//-----------------------------------------------------------------------------
// standard library Includes
//-----------------------------------------------------------------------------
#include <string>
#include <fstream>
using namespace std;

//-----------------------------------------------------------------------------
// Macros
//-----------------------------------------------------------------------------
#define SAFE_DELETE( p )       { if( p ) { delete ( p );     ( p ) = NULL; } }
#define SAFE_DELETE_ARRAY( p ) { if( p ) { delete[] ( p );   ( p ) = NULL; } }
#define SAFE_RELEASE( p )      { if( p ) { ( p )->Release(); ( p ) = NULL; } }

//-----------------------------------------------------------------------------
// Engine Includes
//-----------------------------------------------------------------------------
#include "LinkedList.h"
#include "ResourceManagement.h"
#include "Geometry.h"
#include "Input.h"
#include "State.h"
#include "LogicState.h"
#include "NetState.h"
#include "RenderState.h"
#include "SndState.h"
#include "UIState.h"
#include "Scripting.h"

//-----------------------------------------------------------------------------
// Engine Setup Structure
//-----------------------------------------------------------------------------
struct EngineSetup
{
	HINSTANCE instance; …
SHWOO 25 Junior Poster in Training

I made some changes to your smallest integer do while loop. I'll leave the rest for you to try to figure out.

#include <iostream>

using namespace std;

const int A_QUANTITY = 10;		// Amount of #'s entered for option A
const int B_SENTINEL = -99;		// Sentinal used to end option B

int main ()
{
	bool again = true;			// Used to control main source loop
	char choice;				// Stores the choice made
	int biggest = 0;			// Stores largest #
	int smallest = 0;			// Stores smallest #
	int temp;					// Stores next number for comparison
	int i;						// Controls the For loop
	
	

	while (again)
	{
							  // Displays instructions to user
		cout << "A - Find the largest # with a known quantity of numbers" << endl; 
		cout << "B - Find the smallest # with an unknown quantity of numbers" << endl;
		cout << "C - Exit" << endl;
		cout << "Please enter your choice" << endl;

							  // Gets input from user
		cin >> choice;

		if (choice == 'B' || 'b')	  // Beginning of if statement
		{
			i = 0;
			do 
			{
				cout << "Enter number: (-99 to exit)" ;
				//cin >> i;
				i++;

				cin >> temp;	//this sets temp to what the user inputs
				//cout << "You entered: " << temp << endl; //<< "\i"   <---What was this for?

				if(i == 1)
					smallest = temp;

				if(smallest > temp && temp !=-99)
					smallest = temp;

			}while (temp != B_SENTINEL);

			cout << endl << smallest << endl; …
SHWOO 25 Junior Poster in Training

Hi, I am trying to get a cat walking back and forth between the screen using a left and right tileset of bitmaps. Also, I am supposed to be able to control two caveman sprites that appear to walk left and right as you press the left and right keys.

I am having trouble with the movement of the caveman.

#include "game.h"

LPDIRECT3DTEXTURE9 catleft_image;
LPDIRECT3DTEXTURE9 catright_image;
LPDIRECT3DTEXTURE9 cavemanright_image;
LPDIRECT3DTEXTURE9 cavemanleft_image;
SPRITE catRight;
SPRITE catLeft;
SPRITE cavemanRight;
SPRITE cavemanLeft;

LPDIRECT3DSURFACE9 back;
LPD3DXSPRITE sprite_handler;


HRESULT result;

//timing variable
long start = GetTickCount();

//initialize the game
int Game_Init(HWND hwnd)
{
	//set random number seed
	srand(time(NULL));

	//create sprite handler object
	result = D3DXCreateSprite(d3ddev, &sprite_handler);
	if(result != D3D_OK)
		return 0;

	//load textures
	catleft_image = LoadTexture("catLeft.bmp", D3DCOLOR_XRGB(255,0,255));
	if(catleft_image == NULL)
		return 0;
	
	// initialize the sprite's properties
	// set catLeft's properties
	catLeft.x = 96;
	catLeft.y = 150;
	catLeft.width = 96;
	catLeft.height = 96;
	catLeft.curframe = 0;
	catLeft.lastframe = 5;
	catLeft.animdelay = 2;
	catLeft.animcount = 0;
	catLeft.movex = 8;
	catLeft.movey = 0;

	catright_image = LoadTexture("catRight.bmp", D3DCOLOR_XRGB(255,0,255));
	if(catright_image == NULL)
		return 0;

	// set catRight's properties
	catRight.x = 96;
	catRight.y = 150;
	catRight.width = 96;
	catRight.height = 96;
	catRight.curframe = 0;
	catRight.lastframe = 5;
	catRight.animdelay = 2;
	catRight.animcount = 0;
	catRight.movex = 8;
	catRight.movey = 0;

	cavemanright_image = LoadTexture("cavemanRight.bmp", D3DCOLOR_XRGB(255,0,255));
	if(cavemanright_image == NULL)
		return 0;

	cavemanRight.x = 100;
	cavemanRight.y = 180;
	cavemanRight.width = 50;
	cavemanRight.height = 64;
	cavemanRight.curframe = 1;
	cavemanRight.lastframe = 11;
	cavemanRight.animdelay = 3;
	cavemanRight.animcount = 0;
	cavemanRight.movex = 5;
	cavemanRight.movey = 0;

	cavemanleft_image …
SHWOO 25 Junior Poster in Training

Hi, I am trying to get a cat walking back and forth between the screen using a left and right tileset of bitmaps. Also, I am supposed to be able to control two caveman sprites that appear to walk left and right as you press the left and right keys.

I am having trouble with the movement of the caveman.

#include "game.h"

LPDIRECT3DTEXTURE9 catleft_image;
LPDIRECT3DTEXTURE9 catright_image;
LPDIRECT3DTEXTURE9 cavemanright_image;
LPDIRECT3DTEXTURE9 cavemanleft_image;
SPRITE catRight;
SPRITE catLeft;
SPRITE cavemanRight;
SPRITE cavemanLeft;

LPDIRECT3DSURFACE9 back;
LPD3DXSPRITE sprite_handler;


HRESULT result;

//timing variable
long start = GetTickCount();

//initialize the game
int Game_Init(HWND hwnd)
{
	//set random number seed
	srand(time(NULL));

	//create sprite handler object
	result = D3DXCreateSprite(d3ddev, &sprite_handler);
	if(result != D3D_OK)
		return 0;

	//load textures
	catleft_image = LoadTexture("catLeft.bmp", D3DCOLOR_XRGB(255,0,255));
	if(catleft_image == NULL)
		return 0;
	
	// initialize the sprite's properties
	// set catLeft's properties
	catLeft.x = 96;
	catLeft.y = 150;
	catLeft.width = 96;
	catLeft.height = 96;
	catLeft.curframe = 0;
	catLeft.lastframe = 5;
	catLeft.animdelay = 2;
	catLeft.animcount = 0;
	catLeft.movex = 8;
	catLeft.movey = 0;

	catright_image = LoadTexture("catRight.bmp", D3DCOLOR_XRGB(255,0,255));
	if(catright_image == NULL)
		return 0;

	// set catRight's properties
	catRight.x = 96;
	catRight.y = 150;
	catRight.width = 96;
	catRight.height = 96;
	catRight.curframe = 0;
	catRight.lastframe = 5;
	catRight.animdelay = 2;
	catRight.animcount = 0;
	catRight.movex = 8;
	catRight.movey = 0;

	cavemanright_image = LoadTexture("cavemanRight.bmp", D3DCOLOR_XRGB(255,0,255));
	if(cavemanright_image == NULL)
		return 0;

	cavemanRight.x = 100;
	cavemanRight.y = 180;
	cavemanRight.width = 50;
	cavemanRight.height = 64;
	cavemanRight.curframe = 1;
	cavemanRight.lastframe = 11;
	cavemanRight.animdelay = 3;
	cavemanRight.animcount = 0;
	cavemanRight.movex = 5;
	cavemanRight.movey = 0;

	cavemanleft_image = …
SHWOO 25 Junior Poster in Training

I am trying to animate a bitmap in a window. I am able to load the bitmap in random locations multiple times, but I would like to have the previous instance of the bitmap erased each redraw, as I would like it to be a smoother animation instead of thousands of bitmaps on the screen.

I also do not quite understand how to change the random drawing of the bitmap below into a smooth linear animation.

if (rect.right > 0)
    {
        _sleep(50);
        x = rand() % (rect.right - rect.left);
        y = rand() % (rect.bottom - rect.top);
        DrawBitmap(global_hdc, "asteroid.bmp", x, y);
    }
#include <windows.h>
#include <winuser.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define APPTITLE "Game Loop"

//function prototypes
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);
ATOM MyRegisterClass(HINSTANCE);
BOOL InitInstance(HINSTANCE,int);
void DrawBitmap(HDC,char*,int,int);
void Game_Init();
void Game_Run();
void Game_End();


//local variables
HWND global_hwnd;
HDC global_hdc;


//the window event callback function
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    global_hwnd = hWnd;
    global_hdc = GetDC(hWnd);

    switch (message) 
    {
        case WM_DESTROY:
            Game_End();
            PostQuitMessage(0);
            break;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}

//helper function to set up the window properties
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    //create the window class structure
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX); 

    //fill the struct with info
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)WinProc;
    wc.cbClsExtra     = 0;
    wc.cbWndExtra     = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = APPTITLE;
    wc.hIconSm       = NULL;

    //set up the window with the class info
    return …
SHWOO 25 Junior Poster in Training

bump

SHWOO 25 Junior Poster in Training

The copyList function here is not working working. Anyone have any ideas?

// header file

#ifndef H_orderedLinkedList
#define H_orderedLinkedList

#include <list>
#include <iostream>

using namespace std;

struct coordinates
{
    int xValue;            //variable to hold x coordinate
    int yValue;            //variable to hold y coordinate
};

struct node
{
    coordinates info;
    node *link;
};

class orderedLinkedList
{
        //Overload the stream insertion operator.
    friend ostream& operator<< (ostream&, const orderedLinkedList&);

public:
    void initializeList();
        //Function to initialize the list to an empty state.
        //Postcondition: first = NULL; count = 0

    bool isEmptyList();
        //Function to determine whether the list is empty.
        //Postcondition: Returns true if the list is empty;
        //                 otherwise, returns false.

    int length();
        //Function to return the number of nodes in the list.
        //Postcondition: The value of count is returned.

    void destroyList();
        //Function to delete all the nodes of the list.
        //Postcondition: first = NULL; count = 0

    void insertNode(int, int);
        //Function to insert newItem in the list.
        //Postcondition: first points to the new list and newItem is 
        //                 inserted at the proper place in the list, count++

    void deleteNode(int, int);
        //Function to delete deleteItem from the list.
        //Postcondition: If found, the node containing deleteItem
        //                 is deleted from the list; first points to
        //                 the first node of the new list, count++
        //                 If deleteItem isn't in the list, an error message displays.

    orderedLinkedList();
        //default constructor
        //Initializes the list to an empty state.
        //Postcondition: first = NULL; count = 0

    orderedLinkedList(const orderedLinkedList& otherList);
        //copy constructor

    ~orderedLinkedList();
        //destructor
        //Deletes all the nodes …
SHWOO 25 Junior Poster in Training

The first iterator isn't getting assigned the correct number. instead of size - 1, it is being assigned to -842150451. Then obviously that number is being copied to the new stack.

void linkedStack::copyStack(linkedStack& otherStack)
{
    node* currNode = stackTop;
    int* stackContents = new int[stackSize()];
    otherStack.initialize();

    for( int i = size - 1; i < 0; i--)
    {
        assert( currNode != NULL );
        stackContents[i] = currNode->number;
        currNode = currNode->link;
     }

     for( int j = size -1; j >= 0; j--)
        otherStack.push( stackContents[j] );

} //end copyStack
SHWOO 25 Junior Poster in Training

I'm trying to implement a function to copy one instance of a stack into another instance of a stack.

The result should be two identical stacks. It only outputs blank lines. I

Implementation

#include <cassert>
#include <iostream>
#include <string>

#include "linkedStack.h"

using namespace std;

void linkedStack::initialize()
{
    destroyStack();
} //end initialize

void linkedStack::push(int newNumber)
{
    node *newNode;                    //pointer to create the new node

    newNode = new node;                //creats a new node
    assert( newNode != NULL);
    
    newNode->number = newNumber;    //new integer stored in newNode
    newNode->link = stackTop;        //isert newNode before stackTop
    stackTop = newNode;                //set stackTop to point to the top node
}

void linkedStack::pop()
{
    node *temp;

    if(stackTop != NULL)            //if stack is not empty
    {
        temp = stackTop;            //set temp to stackTop
        stackTop = stackTop->link;    //advance stackTop to the next node
        delete temp;                //delete temp node
    }
    else
        cerr << "Cannot remove from an empty stack." << endl;
} //end pop

void linkedStack::printStack()
{
    node *current;
    node *temp;

    temp = stackTop;
    while(stackTop != NULL)
    {
        cout << stackTop->number << " ";    //print letter on top of stack
        
        current = stackTop->link;    //set current to stackTops link
        stackTop = current;            //set stackTop to current

    }
    
    stackTop = temp;
    cout << endl << endl;
}    

void linkedStack::destroyStack()
{
    node *temp;                //pointer to delete a node

    while (stackTop != NULL)
    {
        temp = stackTop;

        stackTop = stackTop->link;

        delete temp;        // delet temp pointer
    }
} // end destroy

void linkedStack::displayMenu()
{
    cout << "***************************************" << endl << endl;
    cout << …
SHWOO 25 Junior Poster in Training

I am writing a class character for an assignment. The class relates to a role playing game. I am getting an error which I don't understand. This error occurs in the default constructor of the implementation file. The dynamic help says that I created an object without creating a pointer to that object.


I am using Visual C++ .NET 2003

CharClass.cpp(8) : error C3149: 'CharClass' : illegal use of managed type 'CharClass'; did you forget a '*'?
CharClass.cpp(8) : error C2533: 'CharClass::__ctor' : constructors not allowed a return type
CharClass.cpp(8) : fatal error C1903: unable to recover from previous error(s); stopping compilation

// CharClass header
// Base class for Characters of a game

#pragma once

#using <mscorlib.dll>
using namespace System;

public __gc class CharClass
{
public:
    CharClass();
    CharClass(String *, int, bool, int);
    ~CharClass();
    void SetChar(String *, int, bool, int);
    
    //return string representation of CharClass
    String *ToString();

    // property Name
    __property String *get__Name()
    {
        return Name;
    }

    __property void set__Name(String * charName)
    {
        Name = charName;
    }

    // property charAge
    __property int get__CharAge()
    {
        return Age;
    }

    __property set__CharAge(int charAge)
    {
        Age = ( (charAge >= 16 && <= 250 ) ? charAge : 16 );
    }

    // property charHitP
    __property void set__HitPoints()
    {
        calcPoints(int charHitP);
    }

    __property int get__HitPoints()
    {
        return hitPoints;
    }

private:
    bool isCharAlive(bool alive);    //utility function to check wheter the char is alive
    int calcPoints();                

    String *Name;                    //String to store the character's name
    int Age;                        //variable to hold the character's …
SHWOO 25 Junior Poster in Training

Can anyone explain why I am not getting any output from this code

int _tmain()
{
    String *sym[] = {S"BA", S"CA", S"MS"};     
    int shares __gc[] = {25, 100, 30},           
    price __gc[] = {25, 31, 37};              

    Random *randomCurVal = new Random();      

    int purVal, curVal;                           
    int totalPurVal = 0,                       
        totalCurVal = 0,
        totalNetVal = 0;

            
    for (int i = 0; i < shares->Length; i++){
        purVal = price[i] * shares[i];
        curVal = shares[i] * randomCurVal->Next( 15, 55);
        
    }

    Console::Write(S"\n", curVal.ToString());
    return 0;
}
SHWOO 25 Junior Poster in Training

yeah but if the strings dont compare then the found = true; statement isn't executed and found should be false still

SHWOO 25 Junior Poster in Training

How do I search through an array of objects to see if a player name is in the array of objects? The code I have in main I know is incorrect cause I get "Player is in database!" whether or not the player is in the database and it obviously prints six times.

bool playerType::searchPlayer(string searchFirst, string searchLast)
{
    bool found = false;
            if (getFirstName() == searchFirst && getLastName() == searchLast)
            {
                found = true;
            }
            
        if (found = true)
            cout << "Player is in database! ";
        else
            return false;
}

Here is the code in main that I have in a switch statement to access the search function

int n;
        cout << "Enter the first and last name of the player to search for." << endl;
        cin >> fname >> lname;
        for (n = 0; n < 6; n++)
            player[n].searchPlayer(fname, lname);
      break;
SHWOO 25 Junior Poster in Training

Well I would be searching for two different strings

SHWOO 25 Junior Poster in Training

IF I have seven objects of playerType player, player1, player2, player3...etc and I want to search to see if there is a certain player in these objects, how would I do that. I know my code isnt complete and is quite off but if someone could take my blindfold off and point in the right direction, I would appreciate it.

bool playerType::searchPlayer(string searchFirst, string searchLast)
{
    int i;
    bool found = false;
        for (i = 0; i < 6; i++)
            if (name.getFirstName == searchFirst && name.getLastName == searchLast)
            {
                found = true;
                break;
            }
            
        if (found)
            cout << "Player is in database! ";
        else
            return false;
}
SHWOO 25 Junior Poster in Training

So im new to vectors and I'm trying to create an addTeam function, The ultimate outcome should be an object with a division name, 5 teams in a division and 5 players on each team. Here is what I have so far. Please advise on whether I am on the right track or not.


Getting these errors

team.h(22) : error C2059: syntax error : 'constant'
team.cpp(9) : error C2373: 'team::addTeam' : redefinition; different type modifiers
team.h(17) : see declaration of 'team::addTeam'
team.cpp(11) : error C2228: left of '.push_back' must have class/struct/union

#ifndef H_team
#define H_team

#include <string>
#include <vector>
#include "division.h"
#include "personType.h"


using namespace std;

class team : public division , public personType
{
public:
    void printTeam(); const

    void addTeam(string divName, vector<string> name);    //Line 17
        //Function to store a team with a division name and player names
        //Postcondition:    divisionName = divName; firstName = fName; lastName = lName

private:
    vector<string> playerName(5);       //Line 22
    string divisionName;

};

#endif
#include "team.h"
#include <string>
#include <iostream>
#include <vector>


void team::addTeam(string divName, vector<string> name)
{
    divisionName = divName;
    playerName.push_back(name);
}
SHWOO 25 Junior Poster in Training

So if I were to only write one team class and used a menu that the user chose to (C)reate a team. would I use a local static variable to create a team object within the switch where a new object could be create incrementally. i.e.

switch (x)
       case 'c' case 'C'
       static int t = 1;
       team team[t]  //where this is a created object
       ++t;
       team1.createTeam();
      break;
SHWOO 25 Junior Poster in Training

Wouldn't it be better to simply write one team class and just instantiate 5 teams from that one class? What would be the benifit to the 5 different team classes?

SHWOO 25 Junior Poster in Training

I am writing a program which has these require ments
1.Program must be command-line based and interactive, allowing the user to control its operation by entering commands.
2. ability to accept new data
3. ability to search for specific previously entered data
4. ability to save data to a file
5. ability to retrieve data from a file
6. at least 5 classes
7. must show inheritance and polymorphism
8. must read and write a file

I am writing a program to store a basketball league. I have two classes already called personType and PlayerType, one of which is inherited from the other.

I am now brainstorming for the part of my program which will store 3 different divisions. Each division will have 5 teams and each team will have 5 players.

I was going to have the division class be the base class and team class will be derived from division and player's derived from team.

Would it be best to have division object which have a string for the division name, an array for the team names and each team would have an array of players?

#ifndef H_playerType
#define H_playerType

#include <fstream>
#include "personType.h"


class playerType : public personType
{
public:
    void print();
        //Function to print player's first and last name
        //and also their number and position

    void printFile(ostream& outF);
      //Function to print the player information.
      //This function sends the player information to the
      //output …
SHWOO 25 Junior Poster in Training

Can anyone point out why I am getting these errors two errors.

#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>


using namespace std;

#include "playerType.h"

playerType::playerType(string first, string last, int num, string pos)

    : personType(first, last)
{
    playerNum = num;
    playerPos = pos;
    
} // end function playerType

void playerType::setPlayerNum(int num)
{
    try                    //Exception Handling
    {
        if(num < 0 )
            throw num;

        playerNum = num;
    }
    catch (int num)
    {
        cout << "Exception: Player's number must be positive. ";
    }

} //end function setPlayerNum

int getNum()
{
    return playerNum;       //Line (38)
} //end function getNum

void playerType::setPlayerPos(string pos)
{
    
    try                    //Exception handling
    {
        if (pos.length() > 2)
            throw string("Player's position must be PG, SG, G, SF, PF, F,, FC or C!");
        playerPos = pos;
    }
    catch (string str)
    {
        cout << "Exception handler: " << str << endl << endl;
    }
} //end function setPlayerPos

string getPos()
{
    return playerPos;          //line (58)
} //end getNum function

void playerType::print()
{
    personType::print();
    cout << "Player's Number: " << playerNum << endl
        << "Player's Position: " << playerPos << endl << endl;
} //end function print


void playerType::printFile(ostream& outF)
{
    outF << left;
    outF << setw(14) << getFirstName() << "   ";
    outF << setw(4) << getNum();
    outF << setw(5) << getPos();
}

ERROR

playertype.cpp(38) : error C2065: 'playerNum' : undeclared identifier
playertype.cpp(58) : error C2065: 'playerPos' : undeclared identifier
SHWOO 25 Junior Poster in Training

I am coding a class project where I will have a basketball league. The league will include 3 divisions and each division will have 5 teams. Each team will have a number of players and one coach. I must have 5 seperate classes. I already have two classes called person and player and will also add coach. I think my next two classes will be division and team. My question is how should I implement these two classes? I must be able to add players and a coach to a team and add teams to a division. Should I use arrays for only 3 divisions and for the teams? I'm just a little confused on how to set everything up and how everything will interact.

SHWOO 25 Junior Poster in Training

Well I used the jump function that you wrote and I tried to add the loop that prints the top half of the diamond where you have the going up code, then I put the code for the bottom half where you have the going down in inches code. No matter where I put the code for the bottom half of the diamond it doesn't print.

I tried it after the recursive call, I tried it before the recursive call, I tried it with a else after the recursive call. Every time I just get the first half of the diamond. I don't really understand where to put the loop for the bottom half so it will execute.

SHWOO 25 Junior Poster in Training

Well that brings a whole new light to the subject. I didn't understand that the function stepped back out. I've been messing around with my code and I can't figure out where to put the loop to print the bottom half. I attempted to use your example code but that didn't seem to work for me. Any more hints for the newb?

SHWOO 25 Junior Poster in Training

I don't understand how that works. The Jump (n + 1) recursively calls Jump up to n =8 then why does going down keep getting called? there is no recursive call there

SHWOO 25 Junior Poster in Training

I made a mistake here, I used a static int x in the topDiamond function but this doesn't work obviously. How do use a variable in a recursive function that is only static within the function?

SHWOO 25 Junior Poster in Training

So here is what I have so far. This Recursive function prints the top half of the diamond. For the bottom half should I create another recursive function to print the bottom half of the diamond and call it indirectly by the topDiamond function?

#include <iomanip>
#include <iostream>
#include "diamond.h"

using namespace std;

int diamond::botDiamond(int num)
{
    return 0;
}

int diamond::topDiamond(int num)
{
    static int x = 1;
        if (num == 0) return 0;
    
        cout << setw(num + 1);
        for (int i = 0; i < x; i++)
            cout << "* ";
        x++;
            cout << endl;
        if (num == 1)
        return botDiamond(num);

        return num = topDiamond(--num);
}

        diamond::diamond(int num)
        {
            if (num <= 0)
                cout << "Width of diamond must be greater than 0.";
            rows = num;
        }

        diamond::diamond()
        {
            rows = 10;
        }
SHWOO 25 Junior Poster in Training


if (month < 0 || month > 12 || day < 0 || day >31 || year > 1900 ||| year < 2099 )

I believe you have 3 mistakes here in this line

SHWOO 25 Junior Poster in Training

So I was going to write a function to print "* " one astrick and a space and then depending on the parameter of the recursive function, which is an int to identify the number of astricks in the largest row. It would call the function to print "* " in the body of the recursive function depending on that parameter. If anyone can provide any more help I would greatful as I am still struggling on how to accomplish this task.

SHWOO 25 Junior Poster in Training

I was given an assignment to write a recursive function to print a diamond comprised of astrisks (less the dashes) such as:

---*
--* *
-* * *
* * * *
-* * *
--* *
---*

The parameter is the number of astricks in the largest row. I have written the function which works fine but, I am lost when it comes to converting this function to a recursive function. Any help would be appreciated.

#include <iostream>
#include <iomanip>
using namespace std;



void diamond(int row);

int main()
{
    diamond(12);
}

void diamond(int row)
{

int spaces = row * 2;



    for (int i = 0; i <= row + 1; i++)
    {
        cout << setw(spaces);
        for (int j = 0 ; j < i - 1; j++)
            cout << "* ";
            cout << endl;
            --spaces;
    }    
         for (int i = 0; i < row; i++)
        {
            cout << setw(spaces+2);
            for (int j = row - 1 ; j > i; j--)
            cout << "* ";
            cout << endl;
            ++spaces;
        }
}
SHWOO 25 Junior Poster in Training

You get cheese.

I put in a Qur'an

SHWOO 25 Junior Poster in Training

Hey thanks that was the problem. Now my inherited print() function works just fine. The text I am using defines constructors the way I have coded it so I think I will just stick with that way for now.

Are there any benefits to including the constructor in the declaration like that?

SHWOO 25 Junior Poster in Training

I have implemented inheritance and in the print function for class playertype I have called the print function from personType. When I call the playerType fucntion print() with a playerType object only the playerType variables are printed and not the personType variable firstName and lastName.

#ifndef H_personType
#define H_personType

#include <string>
 
using namespace std;

class personType
{

    friend ostream& operator<<(ostream& , const personType& );
    friend istream& operator>>(istream& , personType& );
public:
    void print() const;
       //Function to output the first name and last name
       //in the form firstName lastName.
  
    void setName(string first, string last);
       //Function to set firstName and lastName according 
       //to the parameters.
       //Postcondition: firstName = first; lastName = last

    string getFirstName() const;
       //Function to return the first name.
       //Postcondition: The value of the firstName is returned.

    string getLastName() const;
       //Function to return the last name.
       //Postcondition: The value of the lastName is returned.

    personType(string first = "", string last = "");
       //constructor
       //Sets firstName and lastName according to the parameters.
       //The default values of the parameters are empty strings.
       //Postcondition: firstName = first; lastName = last  

 private:
    string firstName; //variable to store the first name
    string lastName;  //variable to store the last name
};

#endif




#include <iostream>
#include <string>
#include "personType.h"

using namespace std;

    //Overloaded extration << operator
ostream& operator<<(ostream& osObject, const personType& name)
{
    osObject << name.firstName << " " << name.lastName << endl;

    return osObject;
}

    //Overloaded insertion >> operator
istream& operator>>(istream& isObject, personType& name)
{
    cout << "Please enter Person's first and last names: " …
SHWOO 25 Junior Poster in Training

When overloading the insertion and extraction operators they must be nonmember functions because cout and cin are not objects of the class

SHWOO 25 Junior Poster in Training

Another gentleman said he input my code into .net 2003 and it compiled fine, he then converted it to VS 2005 and still compiled ok. He also stated that there were no significant changes in the conversion. I am still seeking input on this problem, so if anyone can help I would greatly appreciate it.

SHWOO 25 Junior Poster in Training

That is the exact same final I have in my C++ programming class at Westwood Online

SHWOO 25 Junior Poster in Training

Well I dont understand that I have the exact same code in VS 05 and I get the dern errors

SHWOO 25 Junior Poster in Training

You get a Virus.

I put in my neighbor's dog

SHWOO 25 Junior Poster in Training

I use Visual studio 2005.

SHWOO 25 Junior Poster in Training

Thats how my textbook coded this particular constructor. The program was working fine until I added the two overloaded operators. I am only having the problem with those two funcitons. I thought friend functions could directly access the private member variables!

SHWOO 25 Junior Poster in Training

default constructor which creates two empty strings

SHWOO 25 Junior Poster in Training

persontype.cpp(10) : error C2248: 'personType::firstName' : cannot access private member declared in class 'personType'
persontype.h(37) : see declaration of 'personType::firstName'
persontype.h(11) : see declaration of 'personType'
persontype.cpp(10) : error C2248: 'personType::lastName' : cannot access private member declared in class 'personType'
persontype.h(38) : see declaration of 'personType::lastName'
persontype.h(11) : see declaration of 'personType'
persontype.cpp(17) : error C2248: 'personType::firstName' : cannot access private member declared in class 'personType'
persontype.h(37) : see declaration of 'personType::firstName'
persontype.h(11) : see declaration of 'personType'
persontype.cpp(17) : error C2248: 'personType::lastName' : cannot access private member declared in class 'personType'
persontype.h(38) : see declaration of 'personType::lastName'
persontype.h(11) : see declaration of 'personType'