-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pyramid.hpp
executable file
·130 lines (100 loc) · 1.9 KB
/
Pyramid.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Pyramid.hpp
*
* Li-Yi Wei
* 6/21/2002
*
*/
#ifndef _PYRAMID_HPP
#define _PYRAMID_HPP
#include <string>
#include <fstream>
#include "Exception.hpp"
#include "Array.hpp"
template<class T>
class Pyramid
{
public:
Pyramid(void);
Pyramid(const int numLevels) throw(Exception);
virtual ~Pyramid(void);
T & operator[](const int level);
const T & operator[](const int level) const;
int NumLevels(void) const;
int Read(const char * fileName);
int Write(const char * fileName) const;
protected:
virtual int Read_a(istream & input);
virtual int Write_a(ostream & output) const;
protected:
Array1D<T> _data;
};
template<class T>
Pyramid<T>::Pyramid(void)
{
// nothing to do
}
template<class T>
Pyramid<T>::Pyramid(const int numLevels) throw(Exception) : _data(numLevels)
{
// nothing to do
}
template<class T>
Pyramid<T>::~Pyramid(void)
{
// nothing to do
}
template<class T>
T & Pyramid<T>::operator[](const int level)
{
return _data[level];
}
template<class T>
const T & Pyramid<T>::operator[](const int level) const
{
return _data[level];
}
template<class T>
int Pyramid<T>::NumLevels(void) const
{
return _data.Size(0);
}
template<class T>
int Pyramid<T>::Read(const char * fileName)
{
int result;
ifstream input(fileName);
if(! input )
{
return 0;
}
result = Read_a(input);
input.close();
return result;
}
template<class T>
int Pyramid<T>::Write(const char * fileName) const
{
int result;
ofstream output(fileName);
if(! output )
{
return 0;
}
result = Write_a(output);
output.close();
return result;
}
template<class T>
int Pyramid<T>::Read_a(istream & input)
{
// shouldn't be called
return 0;
}
template<class T>
int Pyramid<T>::Write_a(ostream & output) const
{
// shouldn't be called
return 0;
}
#endif