Skip to content

Instantly share code, notes, and snippets.

@chasinglogic
Last active December 27, 2015 21:18
Show Gist options
  • Save chasinglogic/7390390 to your computer and use it in GitHub Desktop.
Save chasinglogic/7390390 to your computer and use it in GitHub Desktop.
First CPP attempts
#include <iostream>
#include <map>
using namespace std;
struct Card {
string name;
};
struct Box {
int sz;
string name;
map <string, Card> cards;
};
void printCards(Box box) {
cout << "In print cards." << endl;
typedef std::map< string, Card >::iterator Iter;
for(Iter iter = box.cards.begin(); iter != box.cards.end(); ++iter) {
cout << "IN LOOP" << endl;
cout << iter->first << endl;
}
}
void createCard(Box box){
string name;
//char type;
//char color;
cout << "What is the cards name? ";
cin >> name;
Card card;
card.name = name;
box.cards[name] = card;
}
Box createBox() {
string name;
int sz;
Box box;
cout << "What is the name of your Box? ";
cin >> name;
cout << "What is the size of your Box? ";
cin >> sz;
box.name = name;
box.sz = sz;
return box;
}
int main(){
Box box;
box = createBox();
createCard(box);
cout << "Box's name is " << box.name << " and it has " << box.sz << " cards in it. Those cards are" << endl;
printCards(box);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment