Public Group

# C++ activity books?

This topic is 5257 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

does anyone know any c++ activity books or websites cause i have a big lack of creativity right now and woldnt know where to start programming

##### Share on other sites
Depends on what your skill level is, and what you are interested in. Here is

BEN'S GUIDE TO PROGRAMMING FOR BEGINNERS

1) Program pong. An excellent beginner's project - making that first game is a real morale boost. Also teaches many of the fundamentals for game making, beyond basic syntax.

2) After that, program connect four. More complicated and showier.

3) You can also choose from this list of board games:

Othello
Checkers (probably, for beginners, PvP without AI)
Blackjack
Solitare

4) Practice things like recursion. Here are some exercises that I got from Berkely when I visited the campus. Don't be intimidated. Just think them through.

Write a __recursive__ function that will take two numbers, and return their sum. You cannot use any of the arithmetic operators. You can only use three functions on them - Add1(int argument), which adds 1 to its argument, Sub1(int argument), which subtracts one from its argument, and IsZero(int argument), which returns true only if its argument is equal to zero. Define these functions yourself.

MORE CHALLENGING:

Write a __recursive__ function "Ancestors" that, given a person's name/ID number/whatever, will display each ancestor of that person, including the person himself, and return the total number of ancestors. The family tree will have each ancestor on it, and you have these, and only these functions that you can use to find the mother/father: Mother(PERSON person), which returns the mother of the person you entered, or -1 if there is no mother defined, and Father(PERSON person), which returns the father in the same fashion. You can do whatever you like with the adding up of parents. I wrote the "ancestors" function in 7 lines. If you like, here is the code that you can use (uncommented, just create and paste into the specified files, and call DefineFamilyTree() before you do anything else in your main function. The functions are called "MOTHER(PERSON person)", and "FATHER(PERSON person)".

family.h
#ifndef FAMILYTREE_HPP#define FAMILYTREE_HPP#include "famtree.h"#include <iostream>#include <cstdio>//////////////////////////////////////////////////////////////////// DefineFamilyTree(): Gets user input for creation of family tree//// ancestors(): Recursively gets all ancestors of original PERSON// passed to it, and returns total number of ancestors, including// itself.void DefineFamilyTree(){     PERSON p=0, m=0, f=0;     while (p!=-1)     {         std::cout << "Enter family member id number [-1 to finish family tree]: ";         std::cin >> p;         if (p==-1)             break;         std::cout << "\n\tFamily member " << p << " mother's id (-1 for unknown)    : ";         std::cin >> m;         std::cout << "\n\tFamily member " << p << " father's id (-1 for unknown)    : ";         std::cin >> f;         family_tree = RELATION_DATA(m, f);         family_tree[m] = RELATION_DATA(-1, -1);         family_tree[f] = RELATION_DATA(-1, -1);         std::system("cls");     }     std::cout << "Done.\n";     std::cin.ignore();     std::cin.get();}#endif

famtree.h
#ifndef FAMILYTREEBASIC_HPP#define FAMILYTREEBASIC_HPP#include <map>typedef int PERSON;typedef struct RELATION_DATA{    RELATION_DATA():mother_id(-1), father_id(-1){}    RELATION_DATA(int m_id, int f_id);    PERSON mother_id;    PERSON father_id;} RELATION_DATA;RELATION_DATA::RELATION_DATA(int m_id, int f_id): mother_id(m_id), father_id(f_id){}std::map<int, RELATION_DATA> family_tree;PERSON MOTHER(PERSON p){    return family_tree.mother_id;}PERSON FATHER(PERSON p){    return family_tree.father_id;}#endif

Include "family.h" in your main.cpp or whatever you call the file with the main() function in it.

Enough for now - that should occupy you for awhile.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11