I need to change these files to be a template class instead of a typedef. #ifnde
ID: 3565132 • Letter: I
Question
I need to change these files to be a template class instead of a typedef.
#ifndef MAIN_SAVITCH_SEQUENCE_H
#define MAIN_SAVITCH_SEQUENCE_H
#include <cstdlib> //provides size_t
namespace main_savitch_3
{
class sequence
{
public:
//TYPEDEFS and MEMBER CONSTANTS
typedef double value_type;
typedef std::size_t size_type;
static const size_type CAPACITY = 30;
//CONSTRUCTOR
sequence();
//MODIFICATION MEMBER FUNCTIONS
void start();
void advance():
void insert(const value_type& entry);
void remove_current();
//CONSTANT MEMBER FUNCTIONS
size_type size() const;
bool is_item() const;
value_type current() const;
private:
value_type data[CAPACITY];
size_type used;
size_type current_index;
};
}
#endif
If it helps any this is number 2(c) on page 350 of "Data structures and other objects using C++".
Explanation / Answer
#include <iostream>
using namespace std;
#ifndef MAIN_SAVITCH_SEQUENCE_H
#define MAIN_SAVITCH_SEQUENCE_H
#include <cstdlib> //provides size_t
template <class T>
class sequence
{
public:
//TYPEDEFS and MEMBER CONSTANTS
T value_type;
T size_t, size_type;
static const T CAPACITY = 30;
//CONSTRUCTOR
sequence();
//MODIFICATION MEMBER FUNCTIONS
void start();
void advance();
void insert(const T & entry);
void remove_current();
//CONSTANT MEMBER FUNCTIONS
T size() const;
bool is_item() const;
T current() const;
private:
T data[CAPACITY];
T used;
T current_index;
};
#endif
int main()
{
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.