The program asks the user to enter the inegers (up to 30) and display their sum, by using List.h and then List.cpp. Help please.
inserting integers in a list and displaying their sum
Collapse
X
-
Are List.h and List.cpp code supplied to you, or code that you are supposed to write yourself. I'm assuming probably write yourself. You should take a stab at writing the code yourself and asking for help once you become stuck. There are several ways to implement a list. As an array, as linked list of pointers, etc. You need to ask more specific questions, and supply code you are having problems with. -
help with list.h and list.cpp
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():si ze(0) {}
bool List::isEmpty() const
{
return bool (size==0);
}
int List::getLength () const{
return size;
}
void List::insert(in t index, double sum, bool & success)
{
sucess=(index>= 1)&&(index<=siz e+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];
}Comment
Comment