SphereClass S(2.0);
ballClass B(6.0, "Beachball");
cout << S.diameter(); cout << B.diameter();
class planetClass : public ballClass { private: double soldist; // Distance to the sun public: double getSolDist(); void setSolDist(double); planetClass(double, const char*, double); };
aClassC; C.SetData('c'); cout << C.Data();
double Eval(algExprClass); ... //Assuming we now have an infix expression in InE, let's evaluate it: cout << InE << " = " << Eval(InE);
struct listNode; // defined later typedef listNode* ptrType; class frontListClass : public baseListClass { private: ptrType head; public: bool ListIsEmpty() {return ((head!=NULL)? true : false);}; int ListLength() { int i=0; ptrType t=head; for(; t; t=t->next, i++); t=0; return i; } void DisplayList() { ptrType t=head; while(t) { cout << t->data << ", "; t=t->next; } } bool Insert(ptrType); ptrType Remove(); // Always from head of list, so don't need arg. ptrType Retrieve(); };
class stack : private frontListClass { public: bool empty() {return IsEmpty();}; bool Push(ptrType) {return Insert(ptrType);}; ptrType Pop() {return Remove();}; }
#includeclass personClass { private: char fname[], lname[], minitial; char SSN[9]; public: personClass(char* f, char* l, char m, char *s) { strcpy(fname, f); strcpy(lname, l); minitial=m; strcpy(SSN, s); }; virtual ostream& print(ostream&) = 0; }; class studentClass : public personClass { private: char studentID[9]; public: studentClass(char*f, char*l, char m, char*s, char* sid) : personClass(f, l, m, s) {strcpy(studentID, sid);}; virtual ostream& print(ostream& os) { os << fname << " " << minitial << ". " << lname << endl << "SSN: " << SSN << ", StudentID: " << studentID << endl; }; } class gradStudentClass : public studentClass { private: bool TA; // Is the person a TA? public: gradStudentClass(char*f, char*l, char m, char*s, char* sid, bool t) : studentClass(f, l, m, s, sid), TA(t) {;}; ostream& print(ostream& os) { os << fname << " " << minitial << ". " << lname << endl << "SSN: " << SSN << ", StudentID: " << studentID << endl; if (TA) os << "And is a TA." << endl; }; };