#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 ");
}
basic list objecti dont know how to expand my program pls help me
Page 1 of 1
4 Replies - 334 Views - Last Post: 09 December 2010 - 09:20 AM
#1
basic list object
Posted 09 December 2010 - 08:41 AM
Replies To: basic list object
#3
Re: basic list object
Posted 09 December 2010 - 08:59 AM
joy143, 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..
#4
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
or write std::cout every time instead.
int main() NOT void main
To use cout you will have to have
using namespace std;
or write std::cout every time instead.
int main() NOT void main
#5
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.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|