i have my code for the project and it has one problem only
the problem in the print function
first of all, the following should be a pointer in Customer class:
Product *item; Now, the Print function, in general, should look something like this: void Print(Customer *h){while(h){//here you should print all the details of a customerProduct * p = h->item;while(p){//here you should print a product’s details//move to the next product as below:p=p->next;}//move to the next customer as below:h=h->next;}}
#include
#include
using namespace std;
//Product class
class Product {
public:
string name;
float price;
Product *next;
};
//Customer class
class Customer
{
public:
string firstname;
string lastname;
string type;
Customer *next;
Product item;
Customer();
};
Customer::Customer()
{
firstname=””;
lastname=””;
type=””;
item.name=””;
item.price=0.0;
}
int main()
{
Customer* addNewCust(Customer *);
string delCust(Customer *,string);
string addProduct(Customer *,string,string,float);
string delProduct(Customer *,string);
void printCustDetails(Customer *);
string delAllProduct(Customer *);
Customer* delAllCust(Customer *);
Customer *db = NULL;
Customer *head=NULL;
Customer *curr=NULL;
db = new Customer;
if(!head)
{
head = new Customer;
curr = head;
}
else
{
curr = head;
while(curr -> next)
curr = curr -> next;
}
db->next = head;
head->next = NULL;
int option;
char ch;
do
{
cout<<"\n Please select any item from the following menu:"<
string fname;
string pname;
float price;
switch(option)
{
case 1:
curr = addNewCust(curr);
break;
case 2:
cout<<"Enter Customer First name: ";
cin>>fname;
cout<
cout<<"Enter Product Name: ";
cin>>pname;
cout<<"Enter Product Price: ";
cin>>price;
cout<
}while(ch!=’n’);
return 0;
}
Customer* addNewCust(Customer *cur)
{
Customer *c;
c = new Customer();
cur->next = c;
string f,l;
cout<<"Adding New Customer"<
cout<<"Enter Last Name:";
cin>>l;
c->firstname = f;
c->lastname = l;
c->next = NULL;
c->item.name = ” “;
return c;
}
string delCust(Customer *hd,string fname)
{
cout<<"Deleting Customer"<
{
//free(hd);
cout<
hd=NULL;
return “\nCustomer deleted!!”;
}
else
hd = hd->next;
}
return “\nNo Customer Found”;
}
string addProduct(Customer *hd,string fname,string pname, float price)
{
cout<<"Adding New Product"<
{
hd->item.name = pname;
hd->item.price = price;
return “\nProduct added!!”;
}
else
hd = hd->next;
}
return “\nCustomer not found”;
}
string delProduct(Customer *hd, string fname)
{
cout<<"Delete Product"<
{
hd->item.name = ” “;
hd->item.price = 0.0;
return “\nProduct deleted!!”;
}
else
hd = hd->next;
}
return “\nCustomer not found”;
}
void printCustDetails(Customer *hd)
{
cout<<"Printing Customer and Product"<
{
cout<<"No Data to print";
return;
}
string f,l;
string type="normal";
string pname;
float price;
cout<<"\n Customer Details "<
l = hd->lastname;
cout<
{
if(hd->item.price > 1000)
type = “excellent”;
else if((hd->item.price < 1000) && (hd->item.price >100))
type = “good”;
else
type = “normal”;
cout<<"Type :"<
price = hd->item.price;
cout<<"\n Products "<<"Name "<
break;
}
hd = hd->next;
}
}
string delAllProduct(Customer *hd)
{
cout<<"Delete All Products"<
string l = hd->lastname;
cout<<"\n Customer Details: "<
{
hd->item.name =” “;
return “\nItems deleted”;
break;
}
hd = hd->next;
}
return “\n No items to delete for customer”;
}
Customer* delAllCust(Customer *hd)
{
cout<<"Delete All Customer"<