Am I on the right track/help with set/get functions.

Hey ive been working on this assignment for a little bit and im having some trouble. I know theres some aspects of the program that has been left out which was because i want to make sure my get/set functions work properly first. Heres the assignment.

Implement a fixed size container class that encapsulates a statically sized array and test it using a suitable driver program (break the program into 3 files- definition, implementation and driver). Use a typedef statement to create a synonym for the instance variable’s (the array) data type to make your code more flexible (see the PlainBox class in Chapter 3). Test your program with an array of ints and an array of doubles (you should only have to make one change in the typedef statement to do this).

Your class should include the following data members:
• An array (of size 10 by default)
• A variable to hold the array capacity (capacity).
• A variable to keep track of the number of elements currently being used (num_used).

A constructor:
• The default constructor initializes capacity to 10 and num_used to 0.

Include functions to:
• Determine if the array is full (return a bool value)
• Determine if the array is empty (return a bool value)
• Return the array capacity
• Return the number of elements currently being used

Additional member functions:
• A one argument function to return an element at a given position (get)
• A one argument function to overwrite an element at a given position (set)
• A one argument function to add a given element to the array at the next available location. (at the back)
• A function to return the position of an element passed as an argument. Return a -1 if not found.

Note: Make sure you check for out of bounds conditions and the cases when the array is full.

Your driver program should declare an array object; input values from the keyboard; manipulate the array elements by making calls to get, set and add; test the full, empty and array capacity methods; and print the contents of the partially filled array after the initial input and after all the manipulations are performed. The main method should implement a menu system with a quit option so the user can make selections for add, set, get, etc.

lab1.cpp
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
#include "elements.h"

PlainBox::PlainBox ()
{
	capacity=10;
	  num_used=0;
}   // end default constructor

PlainBox::PlainBox (const ItemType& Entry){  }   // end constructor

bool PlainBox::isFull(){return 0;}
bool PlainBox::isEmpty(){return num_used==0;}
int PlainBox::arrayCapacity(){return capacity;}
int PlainBox::numUsed(const ItemType& Entry){return 0;}
void PlainBox::setItem (const ItemType& Entry){
	
}  

ItemType PlainBox::getItem() const{
  
}  
int PlainBox::ADD(const ItemType& Entry){
	bool ExtraRoom= (num_used < capacity);
	if (ExtraRoom){
		vStore[num_used] = Entry;
		num_used++;
	}
	return ExtraRoom;
}
int PlainBox::PosOfElem(const ItemType& Entry){return 0;}


elements.h
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
#ifndef _PLAIN_BOX
#define _PLAIN_BOX

// Set the type of data stored in the box
typedef double ItemType;

// Declaration for the class PlainBox
class PlainBox
{
  private:
// Data field
  static const int Default_Size=10;
  ItemType vStore[Default_Size];
  int capacity; 
  int num_used;
  public:
// Default constructor
	PlainBox ();
	bool isFull();
	bool isEmpty();
	int arrayCapacity();
	int numUsed(const ItemType& Entry);
	PlainBox (const ItemType&  Entry);
	void setItem (const ItemType& Entry);
	ItemType getItem () const;
	int ADD(const ItemType& Entry);
	int PosOfElem(const ItemType& Entry);

};  
#endif 

How can i setup my get/set functions to work with this program?
Doing the lab1 on the last day before due? Ah CSI.... I am on the same boat lol
lol the struggle
Topic archived. No new replies allowed.