Create a C++ based grocery application in which list of items along with their unique item ID, name, description and price per item will be displayed on screen for the user to add/delete items of his/choice in/from a cart (cart will be generated as a singular linked list). The application should behave as follow:
• System should load item ID, name, description and price per item from a text file in to a linked list (items) and then it should display all loaded details on screen.
• After that user should be provided with four options, i.e. 0,1,2,3 in an iterative manner.
• 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.
Note:
1. For this application you need to create a text file containing items detail (one item per line).
2. Both linked lists (items and cart) must be of type <item>.
I have tried to perform first task in main class But I don't know
how to pass data from text file into Linked List of type user defined Plz guide me on the first task Then kindly tell me what logic will be used on remaining tasks?
Item Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include<iostream>
using namespace std;
template<class T>
class Item{
private:
T id,name,description,price;
public:
Item()
{
id=0;
name=0;
description=0;
price=0;
}
void setId(T itm);
T getId();
void setName(T nam);
T getName();
void setDescription(T descrip);
T getDescription();
void setPrice(T pric);
T getPrice();
};
template<class T>
void Item<T>::setId(T itm)
{
id=itm;
}
template<class T>
void Item<T>::setName(T nam)
{
name=nam;
}
template<class T>
void Item<T>::setDescription(T descrip)
{
description=descrip;
}
template<class T>
void Item<T>::setPrice(T pric)
{
price=pric;
}
template<class T>
T Item<T>::getId()
{
return id;
}
template<class T>
T Item<T>::getName()
{
return name;
}
template<class T>
T Item<T>::getDescription()
{
return description;
}
template<class T>
T Item<T>::getPrice()
{
return price;
}
|
Node Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include<iostream>
using namespace std;
template<class T>
class Node{
private:
T info;
Node<T> *next;
public:
Node(T i=0,Node<T> *n=0)//or:info(i),next(n)
{
info=i;//the bracket will remain empty
next=n;
}
void setInfo(T item);
T getInfo();
void setNext(Node<T> *n);
Node<T> *getNext();
};
template<class T>
void Node<T>::setInfo(T item)
{
info=item;
}//setInfo
template<class T>
void Node<T>::setNext(Node<T> *n)
{
next=n;
}//setNext
template<class T>
T Node<T>::getInfo()
{
return info;
}//getInfo
template<class T>
Node<T>* Node<T>::getNext()
{
return next;
}//getNext
|
Linked List class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include<iostream>
#include "Node.h"
#include "Item.h"
using namespace std;
template<class T>
class LinkedList{
private:
Node<T> *head;
Node<T> *tail;
public:
LinkedList()
{
head=0;
tail=0;
}
}
I have not included functions which are used in main class but I have them in my IDE
|
Main Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
#include<fstream>
#include<string>
#include"LinkedList.h"
//#include"Item.h"
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
LinkedList<Item> items;
Item word;
ifstream obj;
obj.open("E:\\C++ NUML\\Assignment LinkedList\\txt1.txt");
if(!obj)
{
cout<<"File not found"<<endl;
}
else
{
while(getline(obj,word))
{
items.addToHead(word);
items.traversing();
cout<<endl;
}
obj.close();
}
return 0;
}
|