Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Bryan Abrams

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Perfect Numbers

// School project

/*
	Bryan Abrams
	Prof Bioano
	Struct Programming TR at 11
	Homework Five (perfect numbers)
	For Description, see Explain();
*/

#include <iostream>
using namespace std;

//-----start prototypes-----//
void Explain();
int GatherUserData(int,int);
int AnalyzeNumber(int);
void PrintResults(int,int,int);
//-----end   prototypes-----//

int main()
{
	int num1, numRet, numRet2;
	char cont = 'Y';

	Explain();

	do {
		cout << "\nPlease, enter an integer: ";
		cin >> num1;

		numRet = AnalyzeNumber(num1);
		numRet2 = GatherUserData(num1,numRet);
		PrintResults(num1,numRet,numRet2);

		cout << "Do you wish to continue? ";
		cin >> cont;
	}while(toupper(cont) == 'Y');

	return 0;
}

void Explain()
{
	cout << "A number is said to be perfect if the sum of its divisors (except for itself)\n"
		 << "is equal to itself. For example 6, is a perfect number because the sum of its\n"
		 << "divisors (1 + 2 + 3) is equal to 6. The number 8 is said to be defiecient\n"
		 << "because the sum of its divisors (1 + 2 + 4) is only 7. The Number 12 is said\n"
		 << "to be abudant because the sum of its divisors (1 + 2 + 3 + 4 + 5 + 6) is 16.\n\n";
	return;
}

int GatherUserData(int num1, int num2)
{
	if(num2 > num1)
		return 3; // abudant
	else if(num2 < num1)
		return 2; // deficient
	else
		return 1; // perfect
}

int AnalyzeNumber(int num)
{
	int numberTot = 0;
	int numberReturn = 0;

	for(int i = 1; i <= num; i++)
	{
		numberTot = num % i;
		if((numberTot == 0) && (i != num))
		{
			numberReturn += i;
		}
	}

	return numberReturn;
}

void PrintResults(int num1, int retNum, int retNum2)
{
	cout << "The sum of the factors of " << num1 << " is " << retNum << endl;
	if(retNum2 == 1)
		cout << num1 << " is a perfect number." << endl;
	else if(retNum2 == 2)
		cout << num1 << " is a deficient number." << endl;
	else if(retNum2 == 3)
		cout << num1 << " is a abundant number." << endl;

	return;
}


Irrlicht 8bit chara problem

GAHHH

#include <iostream>
#include <cstring>
#include <irrlicht.h>

using namespace irr;
using namespace video;
using namespace gui;
using namespace core;
using namespace std;

#pragma comment(lib, "Irrlicht.lib")

//---------START ENEMY CLASS-----------------//
class cEnemy {
	int iHealth, iDamage;
	float fPosX, fPosY;
	char sImage[64];
public:
	void set_Health(int,int);
	void set_Damage(int);
	void startingPos(float,float);
	void sImgMonster(char[64]);

};

void cEnemy::set_Health(int hp,int handi)
{
	iHealth = (hp * handi);
	return;
}

void cEnemy::set_Damage(int dmg)
{
	iDamage = dmg;
	return;
}

void cEnemy::startingPos(float xPos,float yPos)
{
	fPosX = xPos;
	fPosY = yPos;
	return;
}

void cEnemy::sImgMonster(char path[64])
{
	sImage[64] = path[64];
	return;
}
//---------END ENEMY CLASS-----------------//

//---------START PLAYER CLASS-----------------//
class cPlayer {
	int iHealth, iDamage;
	float fPosX, fPosY;
	
public:
	void set_Health(int,int);
	void set_Damage(int);
	void startingPos(float,float);
	void sImg(char[8]);	
	char sImage[8];
	
};

void cPlayer::set_Health(int hp,int handi)
{
	iHealth = (hp * handi);
	return;
}

void cPlayer::set_Damage(int dmg)
{
	iDamage = dmg;
}

void cPlayer::startingPos(float xPos,float yPos)
{
	fPosX = xPos;
	fPosY = yPos;
}

void cPlayer::sImg(char path[8])
{
	sImage[8] = path[8];
}
//---------END PLAYER CLASS-----------------//


int main()
{
	cout << "Welcome to Space Invaders! A clone made by Bryan Abrams!"
		 << "There are only 6 ships, mainly because I'm lazy, so deal"
		 << "with it for now, once you are ready press any key and get"
		 << "ready to play!" << endl;
	system("PAUSE");

	//class variables stuff
	
	cPlayer player1;
	cEnemy ship1, ship2, ship3, ship4, ship5, ship6;

	player1.set_Health(100,1);
	player1.set_Damage(10);
	player1.sImg("shp.bmp");
	player1.startingPos(400,500);
	

	IrrlichtDevice *device = createDevice(EDT_OPENGL,dimension2d<s32>(800, 600));

	if (device == 0)
		return 1;

	device->setWindowCaption(L"Space Invaders!");

	IVideoDriver* driver = device->getVideoDriver();

	IGUIFont* font = device->getGUIEnvironment()->getFont("fonthaettenschweiler.bmp");

	driver->beginScene(true, true, SColor(0,0,0,0));

	ITexture* images = driver->getTexture( player1.sImage );
	driver->makeColorKeyTexture(images, SColor(255,255,255,255));
	driver->draw2DImage(images,core::position2d<s32>(400,500));
	

	while(device->run() && driver)
	{
		if (device->isWindowActive())
		{
			u32 time = device->getTimer()->getTime();

			// draw some text
			if (font)
				font->draw(L"Welcome to Space Invaders!",rect<s32>(0,0,300,50),SColor(255,255,255,255));

			driver->endScene();
		}
	}

	device->drop();
	return 0;
}




« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS