实验四
声明 #ifndef GRAPH_H #define GRAPH_H // 类Graph的声明 class Graph { public: Graph(char ch, int n); // 带有参数的构造函数 void draw(); // 绘制图形 private: char symbol; int size; }; 2.cpp #include "graph.h" #include <iostream> using namespace std; // 带参数的构造函数的实现 Graph::Graph(char ch, int n): symbol(ch), size(n) { } // 成员函数draw()的实现 // 功能:绘制size行,显示字符为symbol的指定图形样式 // size和symbol是类Graph的私有成员数据 void Graph::draw() { for(int i=0;i<size;i++) { for(int j=1;j<size-i;j++) { cout<<' '; } for(int k=1;k<2*(i+1);k++) { cout<<symbol; } cout<<endl; } // 补足代码,实现「实验4.pdf」文档中展示的图形样式 } 3.mian #include <iostream> #include "graph.h"