首页 > 其他 > 详细

实验三

时间:2019-04-23 23:05:50      阅读:122      评论:0      收藏:0      [点我收藏+]

#ifndef GRAPH_H

#define GRAPH_H

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

 

#include "graph.h"
#include <iostream>
using namespace std;
Graph::Graph(char ch, int n): symbol(ch), size(n) {
}

void Graph::draw() {
int x=size*2-1;
int i,line;
for(line=1;line<=size;line++)
{
for(i=1;i<=x;i++)
{
if(i>size-line&&i<size+line)
cout<<symbol;
else cout<<" ";
}
cout<<endl;
}
}

 

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

int main() {
Graph graph1(‘*‘,5);
graph1.draw();
Graph graph2(‘$‘,7);
graph2.draw();

return 0;
}

实验三

原文:https://www.cnblogs.com/q-z-y-0732/p/10759467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!