#include "cd.h"
void RentalStore ::addRecord(string title){
RentalRecord *newRental;
newRental = new RentalRecord;
system( "cls" );
cout << "\tAdd New Record\n-----------------------------" << endl
<< "Enter title : ";
getline( cin, title );
//newRental->link = current->link;
}
how should i Allow new records to be added to the end of the list.? did i implement correctly? if wrong can someone help me to correct it in order to work for add record to the rental record please?
This string &title makes a little more sense. Well, stick to what works until you have a better grasp of what's going on.
line 3: RentalRecord *newRental = new RentalRecord;
remove line 2
line 9: RentalRecord *temp = theRental;
Again: it's absolutly vital to initialize pointer (with something valid or NULL). Otherwise your programm will crash and you might not even know why and where
It's not necessary that RentalRecord has a default constructor.
Place this RentalRecord *newRental = new RentalRecord(title) right after the getline() (and remove the original RentalRecord *newRental = new RentalRecord; line)
So first of all: did you understand the while loop in addRecord()? It is really important that you do. You need a loop similar to this each time you want to do something with a record.
link does not exists. use next
with while loop (similar to that) mentioned above you need to find the record which has to be deleted. In order to find that particular record you have to compare deleteRecord with probably RecordTitle within that while loop. If you found the record you may unlink it
deleteRecord is the string to find. deleteRental is the object to remove
Just give it a shot. And I tell you what you did wrong ;)
isn't like this?
but if for first i want to cout the CD title which are same title first , then only let user to enter choice whether edit or not edit . isn't the switch case should inside the while( deleteTheRecord == theRental->CDTitle )?
The deleteRecord is purposely when a customer Return a CD then only delete
so If the customer Name not inside the record it will be display that no record found , else it will go to second if to compare the title again. if both if are true , only delete the record .
i think I did it with this ? or any mistake i make again? T.T
and for your addRecord()
i thought it's should be while( temp->next != NULL )?
Don't put your "No any Record found ! " within that loop (It would appear to many times). Do this in the else of the if on line 53.
line 37: remove that ! before current_rental
Apart from that it looks right, but test it yourself.
You should be able by now to show all records (using such a loop)
i thought it's should be while( temp->next != NULL )?
Then you would exclude the last record from the comparison. The point of the addRecord() was just to find the last record. It is actually possible to use the one or other kind of loop to accomplish the task. Just try...
tested . but in deleteRecordthen when the CD it's found. it's successfull to print out . but in the else statement. my window will stuck at there and do nothing. ( for line 9 until 13 )
by the way . can help me or teach me how to use binary search tree to print out that of my CD collection base on my project?
my binary search tree have to read CDRecord.txt
1 2 3 4 5 6 7
Titanic
Hello World
Dancing world
Michael Jackson
Underground
Dive
Sorry , I'm Falling love on her
I can't get the concept. mind to provide some and i try to do and post to u to check?
i just know the Right side is bigger than the root side , the left Side is smaller than the Root Size , and use binary tree to print out the CD title. sorry
but in the else statement. my window will stuck at there and do nothing. ( for line 9 until 13 )
This looks like you didn't initialized next (or another pointer) properly and it gets into an infinite loop.
I strongly recommend something like showAll() just to check whether 'add' or 'remove' worked. It's easy: use your delete while loop where only line 11 and an appropriate cout << ...->RecordTitle << endl is left.
By the way: addRecord() could be implemented easier (if it is not required that the record is appended):
1 2 3 4 5 6 7 8 9 10
void RentalStore :: addRecord(string &title){
system( "cls" );
cout << "\tAdd New Record\n-----------------------------" << endl
<< "Enter title : ";
getline( cin, title );
RentalRecord *newRental = new RentalRecord( title );
newRental->next = theRental;theRental = newRental;
}
I can't get the concept.
This concept is usually based on recursion. So do you know recursion?
Based on addRecord() above addNode() could be implemented like so:
1 2 3 4 5 6 7 8
create new TreeNode tn
if node
if node->cdTitle < addtitle
true: tn->left = node
false: tn->right = node
else
node = tn
}
everything less than goes to the left the other to the right. You can decide the other way round
struct TreeNode{
string cdTitle;
TreeNode *left;
TreeNode *right;
};
class Tree{
private:
TreeNode *root;
public:
Tree();
~Tree();
bool Empty();
void Display();
};
Tree :: Tree (){
root = NULL;
}
bool Tree :: Empty(){
if ( root == NULL )
returntrue;
elsereturnfalse;
}
void addNode( TreeNode*& tree , string title ){
if( tree == NULL ){
tree = new TreeNode;
tree->left = NULL;
tree->right = NULL;
tree->cdTitle = title;
}
elseif( title < tree->cdTitle )
addNode( tree->left , title );
else
addNode( tree->right , title );
}
void Print( TreeNode*& tree ){
if( tree != NULL ){
Print( tree->left );
cout << tree->cdTitle;
Print( tree->right );
}
}
void Tree :: Display(){
Print ( root );
}
did i implement correctly for addNode? and mind to show me that how my BST have to read the title from my txt and show it? not really know the BST . i know what is recursive , keep call back the function . as i did the implementation right now
Besides that, I get an error for my BST implementation
1 2 3 4 5 6
1>main.obj : error LNK2005: "public: __thiscall Tree::Tree(void)" (??0Tree@@QAE@XZ) already defined in cd.obj
1>main.obj : error LNK2005: "public: bool __thiscall Tree::Empty(void)" (?Empty@Tree@@QAE_NXZ) already defined in cd.obj
1>main.obj : error LNK2005: "void __cdecl addNode(struct TreeNode * &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?addNode@@YAXAAPAUTreeNode@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in cd.obj
1>main.obj : error LNK2005: "void __cdecl Print(struct TreeNode * &)" (?Print@@YAXAAPAUTreeNode@@@Z) already defined in cd.obj
1>main.obj : error LNK2005: "public: void __thiscall Tree::Display(void)" (?Display@Tree@@QAEXXZ) already defined in cd.obj
1>C:\Users\User\Desktop\Inti\Applied\Assignment 5\Debug\Assignment 5.exe : fatal error LNK1169: one or more multiply defined symbols found