Tom Kelliher, CS 320
Mar. 10, 2000
Don't forget \\ phoenix
.
Jill's environment class???
Save copies of files before making changes.
Make a few changes; test.
Implement stack class, as defined by stack.h. Develop a set of tests for the class.
Maze design.
Project | Settings | Debug | Program argumentsExample: 20 30
int main(int argc, char *argv[]) { /* ... */ return 0; /* "Normal" return value. */ }argc, argv (
argv[0]
--- program name)?
Why?
sum.h:
#ifndef SUM_H #define SUM_H class sum { private: // Default protection. Also protected. int theSum; public: sum(int, int); int get(void); }; #endif
sum.cpp:
#include "sum.h" sum::sum(int a, int b) { theSum = a + b; } int sum::get(void) { return theSum; }
main.cpp:
#include <iostream.h> #include "sum.h" int main() { sum s(12, 34); sum t(-90, 85); cout << "sum s: " << s.get() << endl; cout << "sum t: " << t.get() << endl; return 0; }
Implement, build, and run.
push and pop should use full and empty, respectively.
// In the class declaration: int *s; // In the constructor: if (!(s = new int[size])) // Should always check return values!!! die("Couldn't allocate space for stack.\n"); // In the destructor: delete [] s; // Remind compiler that s is a pointer.
void stack::die(char *s) { cout << s; exit(1); // "Abnormal" return value. exit() from stdlib.h. // Why can't I just use return? }
stack.h:
#ifndef STACK_H #define STACK_H class stack { private: int* s; int size; int tos; void die(char *); public: stack(int); ~stack(); void push(int); int pop(void); int full(void); int empty(void); }; #endif