Comp 2673
Spring 2002
Homework 2 solutions
  1. chmod 750 *
  2. r----xrw-
    1.          111011100
            +  011001001
            = 1010100101 
    2.          0x60AC
            +  0x7D72
            =  0xDE1E
    3. 4*19 = 76 = 0x4C, 0x6060F0 + 0x4C = 0x60613C
  3. -rwxr-xr-x   1 ftl      faculty    16896 Apr  9 09:20 qs.xls
    -rwxr-xr-x   1 ftl      faculty     4114 Mar 24 12:19 qs.xls.Z
    
    Now we can calculate percentage of original size: 4114/16896 is about 24.35%, corresponding to the compression factor of 75.65% given by compress -v.
  4. studentdb: studentrec.o studentgroup.o studdb.o
    	g++ -o studdb studentrec.o studentgroup.o studdb.o
    
    studentrec.o: studentrec.cpp
    	g++ -c studentrec.cpp
    
    studentgroup.o: studentgroup.cpp
    	g++ -c studentgroup.cpp
    
    studdb.o: studdb.cpp
    	g++ -c studdb.cpp
    
    studentrec.o: studentrec.h
    studengroup.o: studentgroup.h
    studdb.o: studentrec.h studentgroup.h
    
  5. class Card {
        friend ostream &operator<<(ostream &, const Card &);
    public:
        Card();             // default constructor
        Card(int, int);     // give initial values for suit and rank
        Card(const Card &); // copy constructor
        ~Card();            // destructor
        void display(ostream &) const;
        bool operator==(const Card &) const;
        bool operator<(const Card &) const;
        bool operator>(const Card &) const;
        bool operator<=(const Card &) const;
        bool operator>=(const Card &) const;
        bool operator!=(const Card &) const;
        const Card &operator=(const Card &);
    private:
        int suit;           // takes value 0-3 (for clubs, diamonds, etc)
        int rank;           // takes value 0-12 (for deuce, three, etc.)
        static const char *suit_names[4];    // words for displaying suits
        static const char *rank_names[13];   // words for displaying ranks
    };
    
    class Deck {
        friend ostream &operator<<(ostream &, const Deck &);
    public:
        Deck();             // default constructor
        Deck(const Deck&);  // copy constructor
        ~Deck();            // destructor
        void shuffle();
        const Card &deal();
        bool operator==(const Deck &) const;
        const Deck &operator=(const Deck &);
        void display(ostream &) const;
    private:
        Card *cards[52];
        int deal_point;  // keeps track of which card to deal next
    };
    
  6. location 0: Joseph Smith, 08/24/1924, m: 1, f: 2, c: ()
    location 1: Mary Smith 03/13/1904, m: 0, f: 0, c: (0, 3, 4)
    location 2: Jeremy Smith 00/00/0000, m: 0, f:0, c: (0, 3, 4)
    location 3: Jason Smith 02/02/1926, m: 1, f:2, c: (7)
    location 4: Elizabeth Smith 07/14/1920, m: 1, f:2, c: (5)
    location 5: Katelynn Jones 10/31/1940, m: 4, f: 6: c: (9)
    location 6: "" Jones 09/26/1918, m: 0, f: 0, c: (5)
    location 7: Matilda Franklin 08/23/1962 m: 8, f: 3, c: ()
    location 8: Cassandra Merry 11/11/1927, m: 0, f: 0, c: (7)
    location 9: Nancy Walters 04/02/1965, m: 5, f: 10, c:(11)
    location 10: Geoff Walters 11/15/1935, m: 0, f: 0, c:(9)
    location 11: Peter Walters 05/16/2001, m: 9, f: 12, c:()
    location 12: Martin Tall 07/31/1970, m: 0, f: 0, c(11, 13)
    location 13: Darcy Emily 02/03/1998, m: 14, f: 12, c()
    location 14: Francine Godfrey 12/31/1968, m: 0, f:0, c(13)
    location 15: Percy Jones 08/19/2001, m: 16, f: 17, c()
    location 16: Sally "" 00/00/0000, m: 0, f: 0, c(15)
    location 17: Robert Lee 12/24/1960, m: 0, f:0, c(15)
    Finally, a vector of pointers holds a pointer to each of the 17 individuals, sorted by name:
    (13, 7, 14, 5, 15, 6, 17, 8, 4, 3, 2, 0, 1, 12, 10, 9, 11, 16)