I don't really understand the actual usage of static variables in the code. and
The algorithm of this question I use the direct method, output a certain number of spaces and characters one by one to form a centered form, I want to know if there is a better algorithm representation.
// The implementation of class graph #include " graph.h " #include <iostream> using namespace std; // Implementation of constructor with parameters Graph::Graph( char ch, int n): symbol(ch), size(n) { } // implementation of member function draw() // Function: draw size line, display the specified graphic style with the character as symbol // size and symbol are private member data of class Graph void Graph::draw() { for ( int i= 1 ;i<=size;i++ ) { for(int j=1;j<=size-i;j++) { cout<<' '; } for(int j=1;j<=2*i-1;j++) { cout<<symbol; } cout<<endl; } // Complement the code to realize the graphic style shown in the "Experiment 4.pdf" document }