CSC112 Spring 2016 Examples
#include <iostream>1#include <cstdlib>2#include <time.h>3#include <vector>4#include <unistd.h>5#include "termmanip.h"6#include "cat.h"78using namespace std;910int main() {11vector <animal *> world; //the stuff that will struggle12int n;1314srand(time(0)); //start the random numbers1516//get the number of living things17cout << "Welcome to life, where none escape alive!" << endl;18cout << "How many living things? ";19cin >> n;2021//make that number of living things22while(n--) {23animal *t;2425//make a new cat26t = new cat();2728world.push_back(t);29}3031while(true) {32animal *eater, *eaten;3334//select to random living things35eater = world[rand()%world.size()];36eaten = world[rand()%world.size()];3738//they eat!39cout << clearScreen << cursorPosition(1,1);40cout << eater << " eats " << eaten << endl;41eater->eat(eaten);4243for(auto itr = world.begin(); itr != world.end(); itr++) {44cout << *itr;45(*itr)->print();46}4748sleep(1);49}50}515253