SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Pointers And Linked Lists
Exercise:
Programming Projects
Question:5 | ISBN:9780321531346 | Edition: 7

Question

A harder version of Programming Project 4 would be to write a class named List, similar to Project 4, but with all the following member functions:

Default constructor, List();

double List::front();, which returns the first item in the list

double List::back();, which returns the last item in the list

double List::current();, which returns the “current” item

void List::advance();, which advances the item that current() returns

void List::reset(); to make current() return the first item in the list

void List::insert(double after_me, double insert_me);, which inserts

insert_me into the list after after_me and increments the private: variable

count.

int size();, which returns the number of items in the list

friend istream& operator<< ( istream& ins, double write_me);

The private data members should include the following:

node* head;

node* current;

int count;

and possibly one more pointer.

You will need the following struct (outside the list class) for the linked

list nodes:

struct node

{

double item;

node *next;

};

Incremental development is essential to all projects of any size, and this

is no exception. Write the definition for the List class, but do not

implement any members yet. Place this class definition in a file list.h.

Then #include "list.h" in a file that contains int main(){}. Compile

your file. This will find syntax errors and many typographical errors that

would cause untold difficulty if you attempted to implement members

without this check. Then you should implement and compile one

member at a time, until you have enough to write test code in your

main function.



TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.