Assignment 2 Code Review

27 February 2003 - CS 509


Assignment 2 Code Review


Design


Top-Down Design and Stepwise Refinement


Top-Down Design Problems


Design by Wishful Thinking


What's the Problem?


At the Wishing Well


What's the Solution?


Now what?


Finding Computed Values


Storage


Values


Values as Strings

class value 

  string rep;

  value(string v) : rep(v) { }

  value(value left, string op, value right)
    : v(left.rep + op + right.rep) { }

  bool operator != (value v)
    return rep != v.rep


Values as Trees


Implementing twiddle()


Canonical Trees


Line Statistics - Newlines

10020030040050060070080090010001100120013001400
0
10
2011
301
401
50
6011
70111
8012
901
Totals12221200001002


Line Statistics - Semicolons

000100200300400500
02
101
20
301
4012
501
601
70
80112
90
Totals146002


Procedure Statistics

totalpages per procedure
procs1234
4211
431
10721
15114
171241
2121
22175
373241


Follow Directions


Do Not Use char Arrays

char buf[4096];

while (cin.getline(buf, sizeof(buf), '\n'))
  // whatever.


No Really - Don't Use char Arrays

static char tokens[4][100];

int chk_input(const char * line) 

  istringstream iss(line);
  unsigned i;

  for (i = 0; i < 4; i++) { 
    if (!(iss >> tokens[i])) break;
    }


Understand Your Code


Points to Remember


This page last modified on 11 March 2003.