实验三

part2

#include <iostream>
#include "graph.h"
using namespace std;

int main() {
    Graph graph1('*',5);
    graph1.draw();
    
    system("pause");
    system("cls");
    
    Graph graph2('$',7);
    graph2.draw();
    
    return 0; 
}
GRAPH.h
#ifndef GRAPH_H
#define GRAPH_H


class Graph {
    public:
        Graph(char ch, int n);  
        void draw();     
    private:
        char symbol;
        int size;
};


#endif
MAIN.cpp
#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(int i=1;i<=size;i++){
         for(int j=0;j<size-i;j++)
            cout<<" ";
         for(int k=0;k<2*i-1;k++)
            cout<<symbol;
        cout<<endl; 
    }
}

graph.cpp
GRAPH.cpp

PART3

属实不会做……

posted @ 2019-04-23 23:06  鸿崽  阅读(74)  评论(0编辑  收藏  举报