I wrote this listA.h and ListA.cpp. I am not sure if it is right or not. Anybody can offer some help. The user has to enter 30 integers and he program has to store and display the list as well as the sum of integers. Help.
# ifndef ListA_H
#define ListA_H
const int MAX_LIST=30;
typedef int ListItemType;
class List
{
public:
List();
bool IsEmpty();// const;
int Length() const;
void Insert (int NewPosition, int NewItem, bool& Success);
void Retrieve (int & DataItem, int Sum, bool& Success);
private:
ListItemType Items[MAX_LIST];
int Size;
int sum;
};
#endif
# include <iostream.h>
#include <conio.h>
# include <iomanip.h>
# include "f:\listA.h"
List::List():size(0) {}
bool List::isEmpty() const
{
return bool (size==0);
}
int List::getLength() const{
return size;
}
void List::insert(int index, double sum, bool & success)
{
sucess=(index>=1)&&(index<=size+1) && (size<MAX_LIST);
if (success)
{
for (int position=size; position>=index; --position)
++size;
}
void List::retrieve(int index, sum, bool & success) const{
success=(index>=1) && (indexx<=size);
if (success)
sum= sum[sum];
}