1. ## The Thread of Information (C++)

Contents:Please PM one of the moderators if you have any comments or suggestions to make. Thanks.

Thanks goes to Ostamo, NetworkArchitek, Randywong, RJfox, Dynamit, RShadow, Sunnypalsingh, dek001, odoyle, Cookie24, AirJordan, Iced_Eagle, Notsosuperhero, thing2k, eRflol, rev'en, APLevitz, Percent20, Halma, Keith and Stealthcoder for their contributions.
Last edited by LizKimber; 12-03-2008 at 10:59 AM.

2. ## First Steps

Pick one program. You don't need all the listed ones.

Step 2:: Get Some C++ Tutorials

Step 3:: Practise, Practise, Practise

Note
• It is fine to use the console for learning. Graphical User Interfaces will come later.
• Not using code templates when learning can be a good way to start because you do more coding, you learn to type faster, get familiar with the basics of the framework/SDK you are working in and maybe even learn some tricks on how to make your code faster or smaller by not using something that isn't necessary, but is included in the code by default.
Please see the practice problems section.

Step 4:: Study Data Structures and Algorithms

Below is a list of some basic concepts you should try to learn (at least the simple ones). They serve as a data structure & algorithm box of tools. Also see the books section for a list of books on data structures and algorithms.

General Concepts:
• Recursion
• Sorting
• Graph Theory
• Pathfinding

Random stuff that comes in handy:
• Random number generation
• Random permutation generation
• Systematic generation of all permutations

Sorting algorithms:
• Very simple algorithms: Bubble Sort, Insertion Sort, Selection Sort - O(n^2)
• The really fast ones: Quick Sort (most common), Heap Sort, Merge Sort - O(n log n)
• Faster, but only work in special circumstances: Count Sort, Radix Sort, Bucket Sort - O(n) - (hash-based)

Divide & Conquer:
• Binary Search

Data structures:
• Heaps
• Binary Trees
• Binary Search Trees
• Hashing & Hash Tables

Path finding / Floodfill:
• DFS (Depth first search), BFS (Breadth first search)

Shortest-Path finding:
• BFS (nonweighted)
• Dijkstra (weighted, Single source)
• Floyd (weighted, All pairs)

String matching:
• Shift-AND
• KMP
• BM
• Trie data structure

Decision tree algorithms:
• Backtracking, Branch and Bound
• MiniMax (for game AI)
• Alpha-Beta pruning (for game AI)

Data Compression:
• RLE compression
• Huffman compression

If you're a beginner, don't worry about these. For now, just know that they exist and make a note to look into them when you're not a newbie anymore...
• Simple randomization-based optimization algorithms: Random Walk, Hill Climbing (especially the GSAT-type system)
• Better randomization-based optimization algorithms: Simulated Annealing (I love this one!), Genetic Algorithms
• Lesser known randomization-based optimization algorithms: Taboo Search, Grand Diluge, Lagrangean Relaxation
• Fuzzy Logic, Neural Networks, Markov Chains (Hidden Markov Models)
(Note that optimization algorithms can be used to solve constraint-problems; just set the cost function to be the amount of constraint-breaking you have, and try to get it to 0.)
Last edited by keithathaide; 01-23-2006 at 02:16 AM.

3. ## Frequent Issues

To test your compiler setup, compile and run the following program:
Code:
```#include <iostream>

using namespace std;

int main()
{
cout << "Hello World\n";
return 0;
}```
Console program closing before you can see the output?
Solution:
Include any of the following lines at the end of your program:
• Platform independant (#include <iostream>)
Code:
```int x;
cin >> x;```
or (this one doesn't require a temporary variable)
Code:
```cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cin.get();```
or
Code:
`cin.ignore(std::cin.rdbuf()->in_avail() +1);`
• Platform independant (#include <cstdio>)
Code:
`getchar();`
• Depends on a non-standard header
Code:
```#include <conio.h>  //include this header file
getch(); //use this function at the end of your program
//before the return 0 statement```
• Depends on the existence of a system command "pause"
Code:
`system("pause");`

Different ways of running a program in Visual C++
If you're using Visual C++, you can run a program in two ways:
• By pressing F5 (debugging mode): Immediately after your program finishes executing, the console window is closed.
• By pressing Ctrl+F5 (Run without debugger): After your program finishes executing, the console window stays open until a key is pressed.

Having problems with Windows.h? ("fatal error C1083: Cannot open include file: 'windows.h': No such file or directory")
Solution:
1. Install the Microsoft Platform SDK.
2. Update the the Visual C++ Directories in the Projects and Solutions section in the Options dialog box.

In that section, you'll want to add the paths to the appropriate subsection. If you installed the SDK to an alternate path, make sure to change these to match.
• Executable files - C:\Program Files\Microsoft SDK\Bin
• Include files - C:\Program Files\Microsoft SDK\include
• Library files - C:\Program Files\Microsoft SDK\lib

3. See the following question, "Configuring VC++ 2005 Express for Win32".
4. Generate and build a Win32 application to test your paths.
From the File menu, click New Project. In the New Project dialog box, expand the Visual C++ node in the Product Types tree and then click Win32. Click on the Win32 Template and then give your project a name and click OK. In the Win32 Application Wizard dialog box, make sure that Windows application is selected as the Application type and the ATL is not selected. Click the Finish button to generate the project.
5. You should test your project by clicking the Start button in the IDE or by pressing F5. Your Win32 application should build and run.

Configuring VC++ 2005 Express for Win32
• Update the corewin_express.vsprops file.
You just need to take one more step to make the Win32 template work in express. You need to edit the corewin_express.vsprops file (found in C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults) and change the string that reads:
to
• The Win32 Windows Application type is disabled in the Win32 Application Wizard. To enable that type, you need to edit the file AppSettings.htm file located in the folder “%ProgramFiles%\Microsoft Visual Studio 8\VC\VCWizards\AppWiz\Generic\Application\html\103 3\".

In a text editor comment out lines 441 - 444 by putting a // in front of them as shown here:

// WIN_APP.disabled = true;
// WIN_APP_LABEL.disabled = true;
// DLL_APP.disabled = true;
// DLL_APP_LABEL.disabled = true;

Save and close the file and open Visual C++ Express.

Setting up for wxWidgets
Microsoft Visual C++ .NET: http://www.wxwidgets.org/wiki/index....ET_Setup_Guide
Microsoft Visual C++ 2005 Express Edition: http://www.3dbuzz.com/vbforum/showth...99#post1009999
Last edited by keithathaide; 02-12-2006 at 03:52 PM.

4. ## Tools of the trade

Design tools:

Compilers and Integrated Development Environments (IDEs):
• Bloodshed Dev-C++
• Visual C++ 2005 Express Edition
• Eclipse and C/C++ Development Tools
• Code::Blocks Studio
If you have a compiler, download the version without the MinGW compiler. If you do not know what this means, you're safer off downloading "Code::Blocks IDE, with MINGW compiler".
• GNU Compiler Collection (GCC)
To compile single files use the following commands in the console.
First, navigate into the directory you have your file in, then type

Code:
`g++ [filename] -o [outputfilename]`
into the console. Your file will be compiled and the executable stored in the directory you're in.

To link in a library such as winmm, use something similar to:
Code:
`g++ [filename] -o [outputfilename] -lwinmm`
(that's a lowercase "L" before "winmm")
• MinGW - Minimalist GNU for Windows
Download MinGW-4.1.0.exe (installed first to c:\dev\Mingw) and MSYS-1.0.9.exe (installed second to c:\dev\MSYS\1.0)

Compile as shown above using g++.
• Borland C++ Builder.

Documentation tools:

Install creators:
Last edited by keithathaide; 02-18-2006 at 01:40 AM.

5. ## Books

Take the book ratings (beginner, intermediate, or advanced) with a grain of salt. It all depends on your skill set and thinking.

These books cover a range of topics, but I doubt you would find very many C++ coders that didn't have these books in there collection. However for a more complete list I would suggest you visit the ACCU.

General C++
• Accelerated C++ (Most recommended beginner book) by Koenig [Beginner]
• Modern C++ Design (great book for generic programming and design patterns. Part of the Stroustrup series) by Alexandrescu [Intermediate]
• Effective (and more effective) C++ by Scott Meyers (these are proably the most referred to books on C++ ever. Just about any mailing list or forum, will have a ton of "Look at items XX in Meyers book, it explains the issue" [Intermediate to Advanced]
• The C++ Standard Library by Josuttis [Intermediate]
• C++ Templates by Josuttis [Advanced]
• The C++ Programming Language (Get the "Special Edition" because it come with a cool bookmark ribbon) [Star Trek Advanced]
• Sams Data Structures and Algorithms (out of print so you will have to look, but its an excellent book) [Intermediate]
• Code Complete by Steve McConnell is good, it talks about software developement in general, time management, project design and development, as well as many of the industry trends, and gotchas you might run into. Good for people wanting help on big projects. [Beginner to Intermediate]
• Head First Design Patterns is a good intro book to design patterns (the important ones). Its Java based, but is presented in a way where its applicable to any OOP language. Very good for people who don't want a reference book. [Intermediate to Advanced]
• Design Patterns by Erich Gamma is a good book with most of the patterns you would expect, and is mostly a reference. It comes with 2 built in bookmarks (cloth ties) and is hardcover. Its really great, written for C++. [Intermediate to Advanced]

Data structures and algorithms
• Algorithmics: Theory and Practice, Gilles Brassard, Paul Bratley. A nice book to start with, though it does cover some pretty advanced topics. (I couldn't find the original 1988 book that I read.. I believe the book in the link is the newer version of the book.)
• Introduction to Algorithms: A Creative Approach, Udi Manber. Another excellent algorithm primer. Very well written, with some good exercises.
• Introduction to Algorithms, Second Edition, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein. A nice and in-depth book.. Very complete with over 1000 pages (though the basic stuff is only about maybe half of that or so). Used as a standard course textbook in universities all over the world.
• Design and Analysis of Algorithms, Jeffrey D. Smith. Nothing terribly special about this book, but I read it and it was an OK book.
• The Art of Computer Programming, Donald E. Knuth. This is THE BIBLE of data structures and algorithms. So far 3 volumes have been written. Knuth has said that he intends to write 7 volumes, but it doesn't look like the other 4 will be coming out anytime soon. (The first three were first published almost 30 years ago.) This is a very complete book, but difficult to plow through. Most people just use it as a reference.

Windows API
• Programming Windows by Charles Petzold (This is "THE" book on Win32 API) [Beginner to Intermediate]
• Programming Windows with MFC by Jeff Prosise (the MFC version of Petzolds book) [Beginner to Intermediate]

Game Programming and Design
• Data Structures for Game Programmers by Penton (The only book worth buying in Andre LaMothe's Game Dev series) [Intermediate]
• Programming Linux Games from No Startch Press (I believe you can download this one for free now, with the exception of the OpenAL code not working, because OpenAL is a mysterious force that changes from day to day and is impossible to program) [Beginner]
• 3D Game Engine Design by David Eberly, and it's pretty decent. It doesn't go into "design" as much as a true engineer would in terms of key concepts, design choices and tradeoffs, but he does go into maths and concept pretty well, though concrete examples are a bit lacking now and then. The chapters on scene graphs are a bit glossy. [Intermediate to Advanced]
• Programming Vertex and Pixel shaders by Woflgang Engel is pretty good though, if you're into that sort of thing. some great stuff at the end [Beginner to Intermediate]
• Game Coding Complete is a pretty good book, it is a lot more in depth into the business side of games than any other book I've read. The books webpage is very good too, the author regularly answers questions you have, he is very helpful. [Intermidate to Advanced]
• 3D Game Engine Programming, though I haven't read through the whole thing yet, is shaping up to be good, they take you through shaders and all that jazz, really good if you're looking to write a 3D engine. [Intermediate to Advanced]

Simple Direct Media Layer (SDL)
• Focus on SDL (good API reference book for SDL) [Beginner]

DirectX
• DirectX 9 Graphics by Alan Thorn is a good intro level to DirectX, how to isntantiate your device and do a few basic things with direct3d. Good examples, a little math in the front (so you know what is going on with matrices), and then some useful classes. Assumes you are fairly comfortable with Win32 (instantiating a window and such). Goes over the basics of rendering in D3D pretty well. [Beginner]

wxWidgets
• Cross-Platform GUI Programming with wxWidgets (the only book to chose from.. but it's not too bad) [Beginner]

Qt
• C++ GUI Programming with Qt 3 (I'm sure a 2nd edition has been or will be released to cover Qt 4) [Beginner]

A major part of this list has been borrowed from The Books. Book suggestions and rating comments should be posted in that thread.
Last edited by keithathaide; 01-05-2006 at 10:56 PM.

6. ## Tutorials & References

The C++ VTMs can be purchased from the 3D Buzz store.
Note: The first VTM is free and can be downloaded by visiting the C++ section in Video Training.

References::

Tutorials
General

Game programming and C++

Mathematics

Miscellaneous

wxWidgets

Win32 API

OpenGL

DirectX

XBOX Programming

I'm in the process of reorganising this list. Currently sites covering multiple topics are listed only under one heading. If you wish to help, please PM me.

To submit more tutorials, either PM one of the mods or reply in the tutorials thread.
Last edited by percent20; 01-02-2008 at 01:49 PM.

7. ## Practice problems

1. (very easy) Calculate the fibonacci sequence. (1,1,2,3,5,8,13,21,...)
The first two numbers are 1, and after that, each number is the sum of the last two numbers.
2. (easy) Compute prime numbers. See if you can find the first 100 prime numbers.

3. (quickie) Base conversion: Write a program to convert numbers to/from binary.
4. (easy/moderate) Write a program that reads 10 numbers, and can determine if they are a permutation of the numbers 1-10. A permutation means that each number from 1 to 10 comes exactly once in the sequence. (It also means that if you sort them, you will have 1,2,3,4,5,6,7,8,9,10.)
5. (moderate) Write a program that lets 2 people play a game of Tic-Tac-Toe...
Your program will display the board, and reads moves from the players.
It should know when they make an illegal move. As a bonus, your program should be able to know when somebody wins.
6. (somewhat difficult) Calculate all prime numbers between 1 and 10000 using your algorithm from #6. Use these to find all 7-digit prime numbers. (Don't output them, just count them.)
7. (Really good) Try to figure out and implement your own sorting routine. That is, write a program that reads 10 integers, and outputs them, sorted from smallest to largest. After that, try to make it work for N integers, where you get N from the user, too.
8. (Really good) Write a binary search. This is where you find a number based on queries in which you guess a number and are told if the real value is less than that or greater than that. A nice way to write it would be this:

You ask the user to pick a number between 1 and 100. Your program tries to figure this number out, by giving you its "guess"es. When it gives you a guess, you tell it the guess is smaller, than the number, or larger, or if it's correct. (This can be done by giving the program a 0, 1, or 2.)
Your program would always keep a range of numbers it knows your number to be in.
It gives you the number in the middle.. Then it either wins, or it can divide it's range in half. (So for example, it starts by asking 50, you say it's lower than 50, then it asks 25, you say it's higher than 25, then it asks 37, and so on.)
This is a very good exercise, and I really recommend that you try it.
9. (difficult and a bit tiresome) Implement large-number functions. For example, write a program that can multiply 100-digit numbers together.
10. (Very very difficult!) Write a program that prints itself. (Just kidding! Don't try to do this! (But note that it is possible.. It's called a quine))

8. ## Missing code from the VTMs

Note: It would be a good exercise to try and find/fix the code yourself.

Common
iterator can't be decremented
This is an issue with Visual Studio 2005 as compared to Visual Studio 2003. Even if you're running VS 2003, do make these changes, otherwise the code might break under other compilers. It is invalid to decrement the iterator returned by begin(), an operation that silently fails in VS 2003.

Modify the code so that it conforms to the following structure:
Code:
```for (it = collection.begin(); it != collection.end();)
{
// ...
if (/* the current iterator should be deleted */)
{
// ...
it = erase(it);
}
else
++it;
}```
Examples:
• Level::update()
From VTMs
Code:
```void Level::update()
{
for(iter = npc.begin(); iter != npc.end(); iter++)
{
// ...
if((*iter)->isAlive() == false)
{
Sprite *temp = *iter;

iter--;
delete temp;
npc.remove(temp);
}
}
}```
Converted
Code:
```void Level::update()
{
for(iter = npc.begin(); iter != npc.end();)
{
// ...
if((*iter)->isAlive() == false)
{
Sprite *temp = *iter;

delete temp;
iter = npc.erase(iter);
}
else
iter++;
}
}```
• Particle Engine:
From VTMs
Code:
```for (list<Particle *>::iterator it = particles.begin(); it != particles.end(); it++)
{
...
if ( particle->active == false )
{
delete particle;

list<Particle *>::iterator pTemp = it--;
particles.erase(pTemp);
}
}```
Converted
Code:
```for (list<Particle *>::iterator it = particles.begin(); it != particles.end();)
{
// ...
if ( particle->active == false )
{
delete particle;

it = particles.erase(it);
}
else
++it;
}```

Cannot convert from 'const char[]' to 'const wxString'
Solution: Wrap strings with "_T()", or construct a "wxString" first.

Example: Change code such as the following:

Code:
`wxImage myImage("test.bmp");`

to either
Code:
`wxImage myImage(_T("test.bmp"));`
or
Code:
```wxString imageFile(_T("test.bmp"));
wxImage myImage(imageFile);```

VTM 1
The code used in the VTM is as follows:
Code:
```#include <iostream>

main()
{
std::cout << "Hello World!" << std::endl;
}```
This code is not standard C++ and only works under Visual C++ 2003 and lower. Please change it to the following:

Code:
```#include <iostream>

int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}```
The difference is the inclusion of "int" and "return 0;". When a program ends, it must inform the operating system if it ended in a good or bad state and then the operating system can inform the user of this or simply pass the information on to other programs. The extra code supports this. When saying, "return 0", we are telling the operating system how the program performed. In this case "0", means "everything went well". As you watch further VTMs, the need for the "int" will make sense. For now, accept it as it is. Do not use "void" instead of "int". The use of "void" is non-standard and is not supported across all compilers.

VTM 3
Level.cpp
Code:
```void Level::setPlayerStart(void)
{
player->setPosition(startX, startY);
}

int Level::numEnemies(void)
{
int num = 0;

for (Iter = npc.begin(); Iter != npc.end(); Iter++)
{
if ((*Iter)->getID() == ENEMY_CLASSID)
num++;
}

return num;
}

int Level::getWidth(void)
{
return width;
}

int Level::getHeight(void)
{
return height;
}```
Level.h
Code:
```public:
void setPlayerStart(void);
int numEnemies(void);
int getWidth(void);
int getHeight(void);

private:
int startX, startY;```
Mage.cpp
Code:
```void Mage::castSpell(void)
{
if (facingDirection.x == 0 && facingDirection.y == 0)
return;

if (facingDirection.y < -1 && facingDirection.y < -1)
return;

Fireball *temp = new Fireball(level, drawArea, SPRITE_FIREBALL, (int)pos.x + facingDirection.x,
(int)pos.y + facingDirection.y, facingDirection.x, facingDirection.y);

if (temp->move(facingDirection.x, facingDirection.y))
{
temp->update();
}
else
update();
}```
Sprite.cpp
Code:
```bool Sprite::isValidLevelMove(int xpos, int ypos)
{
if (xpos >= 0 && xpos < level->getWidth() &&
ypos >= 0 && ypos < level->getHeight() &&
level->level[xpos][ypos] != TILE_WALL )
return true;
return false;
}

void Sprite::setPosition(int x, int y)
{
// erase sprite
erase(pos.x, pos.y);
facingDirection.x = facingDirection.y = -100;
pos.x = x;
pos.y = y;

// draw sprite
draw(pos.x, pos.y);
}

void Sprite::setLevel(Level *newLevel)
{
level = newLevel;
}

void Sprite::update(void)
{
draw(pos.x, pos.y);
}

int Sprite::getID(void)
{
return classID;
}```
Sprite.h
Code:
```public:
void setLevel(Level *newLevel);
void setPosition(int x, int y);
int getID(void);
virtual void update(void);```
Character.cpp
Code:
```void Character::addLives(int num)
{

if (Sprite::isAlive())
{
level->setPlayerStart();
update();
}
}```
Fireball.cpp
Code:
```void Fireball::idleUpdate(void)
{
if ((isValidLevelMove((int)pos.x, (int)pos.y)) && ((facingDirection.x + facingDirection.y) != 0))
{
if (Sprite::move(facingDirection.x, facingDirection.y))
{
list <Sprite *>::iterator Iter;

for (Iter = level->npc.begin(); Iter != level->npc.end(); Iter++)
{
if ((*Iter)->classID != classID &&
(int)(*Iter)->getX() ==(int)pos.x && (int)(*Iter)->getY() ==(int)pos.y)
{
}
}
}
else
}
}```
VTM 6
Non zero ID field length
Use seekg() to skip past the ID field. Example:
Code:
```// read TGAheader

// skip image ID

Flipped TGAs
The TGA specification names a field not mentioned in the VTM - the Image Descriptor (field 5.6), under the Image Specification (field 5). Bits 4 and 5 are of interest.

What needs to be done:
• Add another byte at the end of the TGAHeader type defined by Joel:
Code:
`GLubyte ImageDescriptor;`
• Figure out if the image was flipped horizontally or vertically:
Code:
```    bool flipH = ((header.ImageDescriptor & 0x10) == 0x10);
bool flipV = ((header.ImageDescriptor & 0x20) == 0x20);
flipImage(imageData, flipH, flipV, width, height, bpp);```
Add this code before the call to createTexure() in the loadTGA() function.
• Flip the image when appropriate:
Code:
```void Texture::flipImage(unsigned char * image, bool flipHorizontal, bool flipVertical, GLushort width, GLushort height, GLbyte bpp){
GLbyte Bpp = bpp / 8;

if (flipHorizontal){
for (int h = 0; h < height; h++) {
for (int w = 0; w < width / 2; w++){
swap(image + (h * width + w) * Bpp, image + (h * width + width - w - 1)* Bpp, Bpp);
}
}
}

if (flipVertical){
for (int w = 0; w < width; w++){
for (int h = 0; h < height / 2; h++) {
swap(image + (h * width + w) * Bpp, image + ((height - h - 1) * width + w)* Bpp, Bpp);
}
}
}
}

void Texture::swap(unsigned char * ori, unsigned char * dest, GLint size){
GLubyte * temp = new unsigned char[size];

memcpy(temp, ori, size);
memcpy(ori, dest, size);
memcpy(dest, temp, size);

delete [] temp;
}```
Both these functions are added to Texture with private visibility.

Available resources: explanation of flipImage(), how flipH and flipV are calculated.

Generously provided by ostamo, randywong and KhaoticMind.
Last edited by keithathaide; 05-08-2006 at 04:27 PM.

9. ## The C++ class assignments

Module one assignments
Assignment One: Averaging Values
For this assignment you will create an Integer array that holds 10 RANDOM values.
Create a loop to find the average of those 10 values and print the result.

Assignment Two: Coke Machine revisisted
In this assignment we want you to expand upon the coke machine we did. What we want is a complete working coke machine that accepts input from the user on what coins you put in. You'll have to use the cin function to get this information from the user. So here is what each key should do:

'0' - Finished inserting Coins
'1' - Insert Quarter
'2' - Insert Dime
'3' - Insert Nickel
'4' - Insert Penny

Do not forget to print whether the user got a coke and if they did how much change,if any, they get back.

Assignment Three: Become an Electrical Engineer
So you're ready to become an Electrical Enginner? If not too bad,its time. In this Lesson you'll become very familiar with the color coding schemes of resistors. If you are not sure what a resistor is Use Google.

For those familiar with what a resistor is,they have 4 bands of color on them. Three of the bands determin what reistance they have in Ohms. The fourth band determines the toloerance of the resistor.

Your job is to take 3 inputs from the user for each band,the tolerance band is optional. The user will be expected to enter in a value between Zero and Nine and here is what each color will represent:

0 - black
1 - brown
2 - red
3 - orange
4 - yellow
5 - green
6 - blue
7 - violet
8 - gray
9 - white

When complete the program should print the Ohms value to the screen.

Module One FINAL project
For this Final Project you will be creating two integer arrays each holding 20 values.

The first array will hold 20 random values,and the second array will hold those same values but sorted. It does not matter which sorting algorithm you use as long as it works. If you have no idea how to create a sorting algorithm, time to use Google. We will also require a written document detailing the logic of your sorting code. It is truly important to us that you fully understand what you are doing and why you are doing it. The purpose of this assignment is to get you thinking...NOT hold your hand.

Module two assignments
Assignment 1
In this assignment you will create a function that asks the user for details about a person (first name, last name, age) and then passes them back to the main function which prints them out.

There are two ways of doing this - bonus points if you implement both.

Assignment 2
In this assignment you will create a class for storing and using information about a person. It will ask the user for information about a number of people and then print the information out.

The code for getting and printing out the information should all be in the class itself.

Assignment 3
In this assignment, you will create a number of classes - person, student and teacher. Student and teacher will be inherited from person. As much code as possible should be generalized in the person class.

Final Project: Vehicle Rental
For this project you will write a program that could be used by a vehicle hire company.

The company has a number of vehicles that can be cars, vans or Humvees. All vehicles have a make, model and top speed. Cars also have a number of doors and number of seats. Vans have a weight limit and Humvees have a weight limit and size.

When the program starts, it asks users to enter a number of vehicles of their choice (and asks the appropriate questions about the vehicles). Then the program gives the user various options, including sending a vehicle out with a hirer, taking a vehicle back in, listing all the available vehicles and a simple search (show all available Humvees with a weight limit over 3.5 tons, for example).

Module three assignments
Assignment 1: Show us your "Evil Monkeys"
In this assignment, you will present us with your own Evil Monkeys game. Now that you’ve seen the videos, you should be fully capable of recreating the game in its entirety as seen in the VTMs. Remember that you can always review the videos if you get confused. You must send us a RAR/ZIP file including your source code, fully ready to compile and run. Do not send your executable, as it will not be opened.

Assignment 2: Implementing Multiple Weapons (Spells)
This assignment will test your understanding of the content presented in the videos as you add the ability for the player (Mage) to fire a second type of weapon or spell. This second weapon will be an Ice Ball. The effect of this weapon is that it will freeze or incapacitate an Evil Monkey on contact. That monkey will remain frozen in place unable to move for 5 seconds, after which the Monkey will continue its pursuit.

If you strike a frozen Evil Monkey with an Ice Ball, the spell will have no effect. The internal timer will continue to count down as if nothing happened. Once the timer reaches zero, the monkey will become unfrozen, and you will have the opportunity to freeze it again, with the timer restarting at 5 seconds.

You will slave the F key to switch between the two different types of spell; Fireballs and Ice Balls. You must send us a RAR/ZIP file including your source code, fully ready to compile and run, along with a text file that provides an overview of all of the changes made to the original source. Do not send your executable, as it will not be opened.

Assignment 3: Implementing Teleportation
In this assignment, you will add a new ability for the player (Mage): The power to randomly teleport to an open area of the map. This ability will be slaved to the Z key, meaning that whenever your player becomes overwhelmed by Evil Monkeys, they can press Z to jump away, hopefully to safety. For now, there should be no limit on the number of times this can be done.

You must send us a RAR/ZIP file including your source code, fully ready to compile and run, along with a text file that provides an overview of all of the changes made to the original source code. Do not send your executable, as it will not be opened.

Generously provided by Ostamo.

10. ## Setting up wxWidgets on Visual C++ 2005 Express Edition

I followed the C++ VTM4 from the bundle I purchased and I had about 3-4 days of a struggle trying to get this wxWidgets thing to work. After a number of hours of research, reading and big help from Mr. Ostamo and a few others, I have come up with the perfect tutorial for you guys

So, let's BEGIN!!!

Compiling the wxWindows libraries

Once downloaded, install it. I installed it on my C: drive and the directory looked as follows:

C:/Program Files/wxWidgets 2.6.2/
Once done, go to the "src" folder in the wxWidgets Directory you installed, and open the "wxWindows" VC++ 6 Project. In my case the directory was the following:

C:/Program Files/wxWidgets 2.6.2/src/wxWindows
If it asks you it must convert the project to the latest Visual C++ Version just say yes to all. This is just a warning telling you that it will convert the project to your version and you can't open it with older versions like VC++ 6 or .NET 03.

Now, once the Project is open, go to the "Solution Explorer" (the window with all your files and project resources) and click on the "+" next to wxWindow, then click open the contents of the "Headers" folder, then "Setup" and finally double click on "Setup.h".

In the Setup.h header file you have to change two things. First look for the line that has the following:

#define wxUSE_UNICODE 0
And change the 0 to 1, so it looks like this:

#define wxUSE_UNICODE 1
Now in the same Setup.h file find the line that says:

#define wxUSE_GLCANVAS 0
And again change the 0 to a 1 as follows:

#define wxUSE_GLCANVAS 1
Once that is done pick the solution configuration to "Debug" and then go to the "Build" menu and pick "Build Solution". Once its complete you should see 7 succeeded and 0 failed. Do the same thing again, but instead of "Debug" pick a "Release" build...

Once this is done you are ready to use wxWidgets as it has compiled everything it needs. All that is left to do is set it up on Visual C++ Express 2005 and on your project.

Configuring VC++
Open your version of Visual C++ Express 2005 and in the "Tools" menu up above, open the "Options...". Once this is done open the "Projects and Solutions" option and then pick "VC++ Directories".

Inside VC++ Directories we are gonna add the directories for the Include and Lib files for wxWidgets. In the "Show directories for:" option make sure you have picked "Include Files". Once in the include directories add one by clicking on the yellow folder and put the include directory which is in the folder where you installed wxWidgets. In my case its as follows:

C:/Program Files/wxWidgets 2.6.2/include
Then change the directory to "Library Files" and inside do the same thing but instead of adding the Include directory add the Lib directory. In my case it looks like this:

C:/Program Files/wxWidgets 2.6.2/lib
Hit OK now and we are ready to make a project! As of now our Visual C++ Express 2005 knows about wxWidgets. It just doesn't know about everything it has, since we compiled wxWidgets for both when we are making Debug builds and Release builds. So what we do now is everytime you wanna make a wxWidgets project you must add some things manually to it, and these change a bit depending on whether we you are making a debug or release build.

Configuring a project
Now create a new project, pick a Win32 Console application and in the options make sure you pick "Windows Application" then an "Empty Project"

You must have the Platform SDK installed and setup in order to make Windows applications in Visual C++ Express 2005. You need to comment out 4 lines in a particular file to enable vc++ 05 to make a windows application not just a console application.

For more information on that please refer to www.msdn.com as this is a wxWidgets tutorial I won't bother teaching how to setup the PSDK.

Once we have our project, add a new source file, name it whatever you want, just make sure its a .cpp file. Mine is named like this "wxWidgetsApp.cpp".

Inside of it we are gonna create a basic window with a title. You can later use this project as a dummy for all the wxWidgets projects you make, that way you don't have to set all the things we will do in a little bit every single time.

Put in the following code in your .cpp file:

Code:
```#include "wx/wx.h"

class wxWidgetsApp : public wxApp
{
public:
virtual bool OnInit();
};

IMPLEMENT_APP(wxWidgetsApp)

bool wxWidgetsApp::OnInit()
{
wxFrame *frame = new wxFrame((wxFrame *) NULL, -1, _T("wxWidgets Application"), wxPoint(60, 70), wxSize(600, 400));

frame->Show(TRUE);

SetTopWindow(frame);

return true;
}```
Remember this is a tutorial on how to set up wxWidgets not how to use or learn it, so if you don't understand a thing of what that code does just copy it, test it so you know if wxWidgets works on your computer and go learn what it does .

Just a little bit to go

Go to the "Project" option in the top menu and select "Properties". Now in "Configuration Properties" go to the "General" option and make sure things are as follows under the "Project Defaults" title:

Use of MFC: Use Standard Windows Libraries
Use of ATL: Not Using ATL
Character Set: Unicode Character Set
Now in the properties for your project select the "C/C++" option and click on the "General" option. Inside of it we are going to include the locations of some directories where it says "Additional Include Directories".

We are gonna add the location to the "Include" directory, the "lib/mswd" directory and the "lib/mswd/wx" directory.

One thing to point out here is the name of these directories. IF you notice the D at the end of the mswd directories indicates that they are for Debug builds. If you want to make a release build you will need to change to the directory without the D which is the Release directory. So, add those three directories. In my case it looks as follows:

C:/Program Files/wxWidgets 2.6.2/include;C:/Program Files/wxWidgets 2.6.2/lib/mswd;C:/Program Files/wxWidgets 2.6.2/lib/mswd/wx
Just separate the directories using a semicolon like I did. Remember I am pointing to the mswd directories in the Lib folder because i am making a debug build. If you wanna make a release build make sure they don't have the "d" at the end.

Now in the "C/C++" option in your project properties go to "Preprocessor" and in "Preprocessor definitions", add the following:

WIN32;_DEBUG;WINDOWS;wxUSE_GUI=1;_WXDEBUG_;WXDEBUG =1;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPREC ATE
Ignore the space in "DEPRECATE". VBulletin inserts a space in lines that are too long

By default you should already have the "WIN32;_DEBUG" in there. Again we put in "WXDEBUG" but if you wanna make a release build you will have to come back and change that too. The final 2 definitions with the word DEPRECATE in them are used to prevent you from getting a warning. the thing is that some functions like "stdrup()" or "kbhit()" must have an underscore before their name now...So if we remove those 2 definitions at the end you will get a warning when you build your project saying that "stdrup" is a deprecated function and that it should be called as "_stdrup()"

It doesn't affect the performance or the build in any way...But still its anoying to get a warning every time so add those two lines and its one thign you don't have to worry about when you make a project and get tons of errors

Right below the "Preprocessor" option we should have "Code Generation". Inside change the "Runtime Library" to "Multi-threaded Debug DLL".

Finally, go to the "Linker" option in your project properties and pick the "Input" option.

comctl32.lib rpcrt4.lib wsock32.lib wxmswd.lib
These should be separated by spaces. Remember the wxmsd.lib library is used for the debug build...if you wanna make a release build remove the "d" at the end. And also change the Multithreaded Debug DLL to a MultiThreaded DLL...

THATS IT!!! You can now click OK and go to project, build solution! or just hit F7 on the keyboard and voila! Just hit Control + F5 and there you have it...your window with a title

The rest is up to you and trust me you will enjoy not having to struggle getting an error or a warning every time you tried to build a simple project like this
Last edited by keithathaide; 02-02-2006 at 02:36 AM.

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•