实验三
part2:
#ifndef GRAPH_H
#define GRAPH_H
#define GRAPH_H
class Graph {
public:
Graph(char ch, int n);
void draw();
private:
char symbol;
int size;
};
public:
Graph(char ch, int n);
void draw();
private:
char symbol;
int size;
};
#endif
Graph.h
#include "graph.h"
#include <iostream>
using namespace std;
Graph::Graph(char ch, int n) : symbol(ch), size(n) {
}
void Graph::draw() {
int line, j, k;
for (line=1;line<= size;line++)
{
for (j=1; j<=size-line;j++)
cout << " ";
for (k=1;k<=2*line-1;k++)
cout<<symbol;
cout<<endl;
}
}
#include <iostream>
using namespace std;
Graph::Graph(char ch, int n) : symbol(ch), size(n) {
}
void Graph::draw() {
int line, j, k;
for (line=1;line<= size;line++)
{
for (j=1; j<=size-line;j++)
cout << " ";
for (k=1;k<=2*line-1;k++)
cout<<symbol;
cout<<endl;
}
}
Graph.cpp
#include <iostream>
#include "graph.h"
using namespace std;
int main() {
Graph graph1('*', 5);
graph1.draw();
system("pause");
Graph graph2('$', 7);
graph2.draw();
system("pause");
return 0;
}
#include "graph.h"
using namespace std;
int main() {
Graph graph1('*', 5);
graph1.draw();
system("pause");
Graph graph2('$', 7);
graph2.draw();
system("pause");
return 0;
}
main.cpp

part3
不会

浙公网安备 33010602011771号