basic list object

i dont know how to expand my program pls help me

Page 1 of 1

4 Replies - 512 Views - Last Post: 09 December 2010 - 09:20 AM Rate Topic: -----

#1 joy143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-December 10

basic list object

Posted 09 December 2010 - 08:41 AM

#include<iostream.h>
#define TRUE 1
#define FALSE 0
#define MAX 10

typedef struct List {

int items[MAX];
int last;
List();
void add(int n); // add n to the list
void remove(int n);// remove n if n exists on the list
void removeAll();// remove all contents of the List
void display();// displays the contents of the list in format {x,y,z . . }
int getItemAt(int i);// return the number at index i if i is occupied else 0
int getCount();// return the number of items in the list
int contains(int i);// return TRUE if the list contains i value
};

// helper function to display the action performed on the list
void displayListInfo(List *list, char actionTaken[]){
cout<<"Last Action Performed on the List: "<<actionTaken<<"\n====================\n\n";
cout<<"This is the list: "; list->display();
cout<<"\n\nNo of Items: "<<list->getCount();
cout<<"\nList Contains 10 ? "<<(list->contains(10)? "Yes\n" : "No\n");

}

void main(){
List *a, *b;
a = new List();
b = new List();
a->add(4); a->add(5); a->add(6); a->add(2);
displayListInfo(a, "Adding 4, 5, 6, 2");
a->remove(4);
displayListInfo(a, " Removing 4 ");
a->removeAll();
displayListInfo(a, " Removing All ");


b->add(2); b->add(10); b->add(8); b->add(12);
b->add(1); b->add(40); b->add(23); b->add(12);
displayListInfo(b, "adding 2,10,8,12,1,40,23,12");

b->remove(12);
displayListInfo(b, "removing 12 ");

}




Is This A Good Question/Topic? 0
  • +

Replies To: basic list object

#2 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: basic list object

Posted 09 December 2010 - 08:46 AM

So... What's the problem?
Was This Post Helpful? 0
  • +
  • -

#3 joy143  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-December 10

Re: basic list object

Posted 09 December 2010 - 08:59 AM

View Postjoy143, on 09 December 2010 - 07:41 AM, said:

#include<iostream.h>
#define TRUE 1
#define FALSE 0
#define MAX 10

typedef struct List {

int items[MAX];
int last;
List();
void add(int n); // add n to the list
void remove(int n);// remove n if n exists on the list
void removeAll();// remove all contents of the List
void display();// displays the contents of the list in format {x,y,z . . }
int getItemAt(int i);// return the number at index i if i is occupied else 0
int getCount();// return the number of items in the list
int contains(int i);// return TRUE if the list contains i value
};

// helper function to display the action performed on the list
void displayListInfo(List *list, char actionTaken[]){
cout<<"Last Action Performed on the List: "<<actionTaken<<"\n====================\n\n";
cout<<"This is the list: "; list->display();
cout<<"\n\nNo of Items: "<<list->getCount();
cout<<"\nList Contains 10 ? "<<(list->contains(10)? "Yes\n" : "No\n");

}

void main(){
List *a, *b;
a = new List();
b = new List();
a->add(4); a->add(5); a->add(6); a->add(2);
displayListInfo(a, "Adding 4, 5, 6, 2");
a->remove(4);
displayListInfo(a, " Removing 4 ");
a->removeAll();
displayListInfo(a, " Removing All ");


b->add(2); b->add(10); b->add(8); b->add(12);
b->add(1); b->add(40); b->add(23); b->add(12);
displayListInfo(b, "adding 2,10,8,12,1,40,23,12");

b->remove(12);
displayListInfo(b, "removing 12 ");

}




im sorry this is my first time here..
im worried of my program..
The List is an object that is capable of storing or removing integer values.
The List object is defined by the structure definition below and it need to implement all the methods of the List object. The main function is already given together with a helper function displayListInfo. and the method prototype are the instructions colored in blue on what to do.
the problem is i dont know how to finish the program..

im sorry this is my first time here..
im worried of my program..
The List is an object that is capable of storing or removing integer values.
The List object is defined by the structure definition below and it need to implement all the methods of the List object. The main function is already given together with a helper function displayListInfo. and the method prototype are the instructions colored in blue on what to do.
the problem is i dont know how to finish the program..
Was This Post Helpful? 0
  • +
  • -

#4 simeesta  Icon User is offline

  • Deadly Ninja


Reputation: 219
  • View blog
  • Posts: 592
  • Joined: 04-August 09

Re: basic list object

Posted 09 December 2010 - 09:16 AM

You will need to define each of the functions you have declared.

To use cout you will have to have
using namespace std;

or write std::cout every time instead.

int main() NOT void main
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,603
  • Joined: 23-August 08

Re: basic list object

Posted 09 December 2010 - 09:20 AM

Quote

To use cout you will have to have
using namespace std;


Were the OP using a compiler from this century that would be the case, however I think it's safe to say that the user's inclusion of iostream.h, rather than #include <iostream> -- as well as void main() -- points to yet another student getting ripped off by being taught Turbo C++. using namespace std; was not required with that piece of ANCIENT HISTORY.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1