Connecting Tech Pros Worldwide Forums | Help | Site Map

inserting integers in a list and displaying their sum

Newbie
 
Join Date: Sep 2006
Posts: 11
#1: Sep 28 '06
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.

Familiar Sight
 
Join Date: Sep 2006
Posts: 144
#2: Sep 28 '06

re: inserting integers in a list and displaying their sum


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.
Newbie
 
Join Date: Sep 2006
Posts: 11
#3: Sep 29 '06

re: inserting integers in a list and displaying their sum


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];
}
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,179
#4: Sep 29 '06

re: inserting integers in a list and displaying their sum


Please don't double post!

Have you compiled this and tried to fix the errors?
Reply