Ok. So the split function is a likely candidate. Again, as I said above, use the debugger to trace the code to see where the issue is. That's what it's there for - to assist in the identification of run-time errors. All programmers need to get to grips with it. The sooner you start the better IMO.
template<class T>
Node<T>* LinkedList<T>::searching(T item)
{
if(head==0)//list empty
{
cerr<<"There is nothing to search \n";
}
else
{
Node<T> *ptr=head;
Node<T>* loc=0;
while(ptr!=0)
{
if(item==ptr->getInfo()->getId())
{
loc=ptr;
return loc;//loc contains the address of specific node where the value exist
}
ptr=ptr->getNext();
}
return loc;//loc contains 0 which indicates value not found
}
}//searching
Ok so now it is reading text file fine with a little bit of problem that it is reading last line 2 times and size on output is 9 instead of 8 and Kindly guide me I have searching function in my linked list and what logic will be used to add items in cart from product by getting ID and Quantity from user and Also deletion of item from cart by getting ID from user and at end to generate bill containing selected items, quantity, price per item and total amount to pay What logic will be used for all these?
Output
Enter FileName
grocery.txt
grocery.txt Opened
size9
ID Name Description Price
1 Bread BreakFast 50
2 Butter Used with bread 60
3 Milk Gives calcium 80
4 Eggs Gives protein 64
5 Carrot Vegetable 90
6 Tomato Vegetable 100
7 Apple Fruit 120
Apple Fruit 120
Kindly tell me what logic will be used for these tasks
• If user presses 1, the system should ask user to enter item ID and quantity and should add it into the cart.
• If user presses 2, the system should ask for item ID and then it should delete that item from the cart.
• If user presses 3, list of items with item ID, name, description and price per item should be displayed again.
• If user presses 0, the system should generate bill containing selected item, quantity, price per item and total amount to pay.
1) Ask the use to enter ID and quantity. Then add to cart.
This is the basic logic. This should be part of the program design which is preferable to do before you start coding. You're trying to design after part of the program has already been coded. This is not really the way to do it. First design the program, then code from the design. Code in small parts and compile and test frequently. When you're coded/tested the whole design then you should have a working program that conforms to the requirements.
What don't you understand about this? How is cart represented? You seem to have it as a LinkedList of Item? I would contend that this isn't right. You have a struct for cart items something like:
1 2 3 4
struct cart_item {
int id {};
unsigned qty {};
};
and then have a LinkedList of this type:
LinkedList<cart_item> cart;
id would reference the Item id. So to add an item to cart, obtain the id and check that it's present in product. If not then display a message. If it is present then ask for quantity and verify input (eg not neg or 0 etc). Then add a new item to cart.
Similar for 2. Ask for id, check that it exists in the cart and if so ask for deletion verification and then erase from cart list.
but how will bill be generated because In bill I have to display bill containing selected item, quantity, price per item and total amount to pay.
Whereas I have created separate class for qty
You iterate the cart container to get id and qty. For each id you obtain the item details (price etc) from product container and do a calculation to get cart price per item (item price * qty). Sum all the cart prices to get the bill total.