📄 graph.cc
字号:
#include <iostream>using namespace std;class Graph{protected: int x; int y;public: Graph(int x=0, int y=0) :x(x),y(y) {} virtual void input(); virtual void draw()=0; virtual ~Graph(){}};void Graph::input(){ cout << "input x and y:"; cin >> x >> y;}class Line : public Graph{protected: int endx; int endy;public: Line( int a=0, int b=0, int c=0, int d=0 ) :Graph(a,b),endx(c),endy(d) {} virtual void input(); virtual void draw(); virtual ~Line(){}};void Line::input(){ cout << "Line, "; Graph::input(); cout << "input x and y of endpoint:"; cin >> endx >> endy;}void Line::draw(){ cout << "Line:(" << x << ',' << y << ")-(" << endx << ',' << endy << ')' << endl;}class Circle : public Graph{protected: int r;public: Circle(int a=0, int b=0, int c=0) :Graph(a,b),r(c) {} void input(); void draw(); ~Circle(){}};void Circle::input(){ cout << "Circle, "; Graph::input(); cout << "input radius:"; cin >> r;}void Circle::draw(){ cout << "Circle:(" << x << ',' << y << ")*" << r << endl;}int main(int argc, char* argv[]){ Line ol; Circle oc; Graph* p=NULL; p = &ol; p->input(); p->draw(); p = &oc; p->input(); p->draw(); for(;;) { cout << "(1)Line\t(2)Circle" <<endl; cout << "choose 1 or 2:"; int choice; cin >> choice; if( choice==1 ) p = new Line; else if( choice==2 ) p = new Circle; else return 0; p->input(); p->draw(); delete p; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -