「实验 4 类和对象-2」
1.实验内容2 graph类 /*附加拓展1和2*/ draw()函数的话,因为每一行输出的是空格和规定字符,输出空格数等于 总行数-当前行数 ,输出字符数等于 当前行数*2-1 。 graph.h 1 #ifndef GRAPH_H 2 #define GRAPH_H 3 4 // 类Graph的声明 5 class Graph { 6 public: 7 Graph(char ch, int n); // 带有参数的构造函数 8 void draw(); // 绘制图形 9 void redraw(); //重绘图形 10 void changecolor(); //改变颜色 11 private: 12 char symbol; 13 int size; 14 }; 15 16 17 #endif graph.cpp 1 #include "graph.h" 2 #include <iostream> 3 #include<cstdlib> 4 using namespace std; 5 6 // 带参数的构造函数的实现 7 Graph::Graph(char ch, int n): symbol(ch), size(n) { 8 } 9 10 11 // 成员函数draw()的实现 12 // 功能:绘制size行,显示字符为symbol的指定图形样式 13 //