User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 2 Dec 2002, 20:54   #1
DIABL0S
Guest
 
Posts: n/a
c++ linked list of classes thingy...

Basically:
You have been asked to write a prototype for a gym administration system to handle membership.

The program should be capable of storing information for a number of members.

The class 'Membership' contains the following data:

Account number - each account should be unique (use a static member variable to implement this)

Name
Address
Phone Number
Date of Birth
Date joined
Type of membership (Life, 1 year, 6 months)
Membership renewal date
Start date of current membership.
Membership is open or closed indicator ( 0 - closed, 1- open)
----------------------------------------------
i want to use a link list for this using the static data member to sort the list and search through it etc...
if any1 is interested in writing the code that inserts,deletes a new node, ill be greatful
  Reply With Quote
Unread 2 Dec 2002, 21:20   #2
Structural Integrity
Rawr rawr
 
Structural Integrity's Avatar
 
Join Date: Dec 2000
Location: Upside down
Posts: 5,300
Structural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriendStructural Integrity needs a job and a girlfriend
I have done this at school a year back or so.... I guess you just started with the concept of pointers. I don't have the code anymore tho.
It's not that hard, just DRAW (on paper) how you swap the pointers about. Don't just sit trying to imagine how you would do it, cause THAT WON'T WORK!!!!

If you don't HAVE to use pointers use a vector.... it will save you a lot of work!
__________________
"Yay"
Structural Integrity is offline   Reply With Quote
Unread 3 Dec 2002, 00:51   #3
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
Re: c++ linked list of classes thingy...

Quote:
Originally posted by DIABL0S
..if any1 is interested in writing the code that inserts,deletes a new node, ill be greatful
Two things ..

a) Google

b) I doubt you will find someone to do what is OBVIOUSLY your school or uni homework. Unless you pay us. Help is what we do here, not slave labour. Next time, have a try at doing it first, and start with "I've been trying to do XYZ, I started off trying this, and looking at ABC site, but I'm a bit stuck on doing EFG - heres what I thought would work, but it doesn't seem to be doing it."

http://www.tuxedo.org/~esr/faqs/smart-questions.html may be worth a read.
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 3 Dec 2002, 11:51   #4
meglamaniac
Born Sinful
 
meglamaniac's Avatar
 
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.meglamaniac has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Inserting a node is not hard - neither is deleting one.
Assuming you're using singly linked lists here, then in your class you'll have a pointer which points to the next instance (ie. the next node).
Diagramatically, all you do is this (assuming instance3 is the end of the list, but it makes no difference really):
Code:
instance1(ptr to instance2)   instance2(ptr to instance3)   instance3(ptr to NULL)
***insert***
instance1(ptr to instance 4)   instance4(ptr to instance2)   instance2(ptr to instance 3) instance3(ptr to NULL)
***delete***
instance1(ptr to instance4)   instance4(ptr to instance3)   instance3(ptr to NULL)
free(instance2)
For heavens sake remember to free any instances you delete. If you don't, congratulate yourself on writing your first program with a serious memory leak problem.

It's only a matter of updating pointers - how hard can it be?
All any "insert" or "remove" function needs to know is the address of the pointer to the "left" (diagramatically) of where you want to insert/remove.
Once you've built a system to keep track of the pointers it's easy. Obviously you have to keep a static pointer to the first instance (or you'll lose the start of your list) and keeping a pointer to where you are now is always a good plan.
__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
meglamaniac is offline   Reply With Quote
Unread 3 Dec 2002, 13:00   #5
Pitchfork
Tourist
 
Join Date: Jun 2001
Location: moon
Posts: 90
Pitchfork is an unknown quantity at this point
I assume you are using VC++? If so, have a look at CList resp. CArray Template classes. Really helpful for fast creation of linked lists without having to bother with memory leaks and so on
__________________
Quote:
Originally posted by Bloomers III
sex is dirty and for losers who can't masturbate properly
Pitchfork is offline   Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 06:07.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018