Part2
#ifndef GRAPH_H #define GRAPH_H // 类Graph的声明 class Graph { public: Graph(char ch, int n); // 带有参数的构造函数 void draw(); // 绘制图形 private: char symbol; int size; }; #endif
#include <iostream> #include "graph.h" using namespace std; int main() { Graph graph1(‘*‘,5); graph1.draw(); system("pause"); system("cls"); Graph graph2(‘$‘,7); graph2.draw(); system("pause"); return 0; }
// 类graph的实现 #include "graph.h" #include <iostream> using namespace std; // 带参数的构造函数的实现 Graph::Graph(char ch, int n): symbol(ch), size(n) { } // 成员函数draw()的实现 // 功能:绘制size行,显示字符为symbol的指定图形样式 void Graph::draw() { int i,j,k; for( i=0;i<size;i++) { for( j=0;j<=size-i;j++) cout<<" "; for( k=0;k<2*i-1;k++) cout<<symbol; cout<<endl; } }
Part3
原文:https://www.cnblogs.com/fifi1224/p/10753767.html