CMPSC 32 Lecture Notes - Lecture 11: Abstract Type

13 views4 pages
8 Jan 2020
School
Course
Professor

Document Summary

Student r = student("richert", 21, 111); cout << r. tostring() << endl; // student. Person s = student("t", 12, 11112); cout << s. tostring() << endl; // person. Person* t = new student("r", 16, 2000); cout << t->tostring() << endl; // student. Base class has certain attributes, but don"t know how to implement that. Abstract class: a class with one or more pure virtual functions. // shape. h class shape { public: virtual double area(); #include "shape. h" class rectangle: public shape { public: Rectangle(double length, double width) { this->length = length; this->width = width; virtual double area() { return length * width; private: double length; double width; #include "shape. h" class square: public shape { public: Square(double side) { this->side = side; virtual double area() { return side * side; private: double side; Square *s = new square(4); cout << s->area() << endl; Shape *shape[2]; shape[0] = new square(10); shape[1] = new rectangle(3,4);

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents