实验三
Posted hi-ypy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验三相关的知识,希望对你有一定的参考价值。
#ifndef GRAPH_H #define GRAPH_H class Graph { public: Graph(char ch, int n); void draw(); private: char symbol; int size; }; #endif #include "graph.h" #include <iostream> using namespace std; Graph::Graph(char ch, int n): symbol(ch), size(n) { } void Graph::draw() { int i, j, k; for(i=1;i<=size;i++) { for (j = 1; j <= size - i; j++) cout << " "; for (k = 1; k <= 2 * i - 1; k++) cout << symbol; cout << endl; } } #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; }
以上是关于实验三的主要内容,如果未能解决你的问题,请参考以下文章