Live2D

实验3

part2

#ifndef GRAPH_H
#define GRAPH_H

// 类Graph的声明 
class Graph {
    public:
        Graph(char ch, int n);   // 带有参数的构造函数 
        void draw();     // 绘制图形 
    private:
        char symbol;
        int size;
};


#endif
graph.h
#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; 
} 
main.cpp
// 类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;
 }
}
graph.cpp

 

 

posted @ 2019-04-23 21:29  仁昌  阅读(100)  评论(0)    收藏  举报