In: Computer Science
Write a code in c++ using dynamic array of structure
and dynamic array list.
Make a dummy list for a company which stores following information
about its customers.
Customer ID
Customer Name
Gender
Total items purchased
Item category
20% discount in percentage of total purchase amount.
Use dynamic array to save at least 20 items by dividing them into 3
different categories.
Make a dummy list of items that company sells by dividing them into
two categorizes. Items has following attributes
Item number
Item price
Item name
Item quantity
Manufacturer
Expire date
Also allow customer to purchase these items. Suppose that the
company has unlimited stock of items.
Note.
No element in a list would duplicate.
Each list have following functions
Create
Display
Isfull
Isempty
Islength
Clear
Delete
Copy
Find by value
Find by position
Swap by value
Swap by position
Add by value
Add by position
Delete by value
Delete by position
Update by value
Update by position
Source code:-
----------------------------
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
struct customer_Details{
int Customer_ID;
char Customer_Name[100];
char Gender[100];
int Total_items;
int discount;
struct Item_category{
int Item_number;
int Item_price;
char Item_name[100];
int Item_quantity;
char Expire_date[11];
};
struct Item_category category_array[20];
}cust;
struct customer_Details cust_array[20];
class Company{
public:
int size;
int CustomerID;
char CustomerName[100];
char gender[100];
int Totalitems;
int Discount;
char ItemName[10];
int ItemNo,price,quantity;
char Date[100];
public:
void create()
{
cout<<"\n----------------------"<<endl;
cout<<"\nPlease Enter The How many Details you want to
Record:"<<endl;
cin>>size;
for(int i=0;i<size;i++)
{
cout<<"\nPlease Enter The Customer Id:"<<endl;
cin>>CustomerID;
cust_array[i].Customer_ID=CustomerID;
cout<<"\nPlease Enter The Customer Name:"<<endl;
cin>>CustomerName;
strcpy(cust_array[i].Customer_Name,CustomerName);
cout<<"\nPlease Enter The Gender:"<<endl;
cin>>gender;
strcpy(cust_array[i].Gender,gender);
cout<<"\nPlease Item Category:"<<endl;
cin>>ItemName;
strcpy(cust.category_array[i].Item_name,ItemName);
cout<<"\nPlease Enter the ItemNumber:"<<endl;
cin>>ItemNo;
cust.category_array[i].Item_number=ItemNo;
cout<<"\nPlease Enter The Item Price:"<<endl;
cin>>price;
cust.category_array[i].Item_price=price;
cout<<"\nPlease Enter The Item Quantity:"<<endl;
cin>>quantity;
cust.category_array[i].Item_quantity=quantity;
cout<<"\nPlease Enter The Expiry Date:"<<endl;
cin>>Date;
strcpy(cust.category_array[i].Expire_date,Date);
}
}
public:
void deletebyvalue(int next,int id)
{
cust_array[next].Customer_ID=0;
size--;
}
public:
void add()
{
size++;
cout<<"\nPlease Enter The Customer Id:"<<endl;
cin>>CustomerID;
cust_array[size].Customer_ID=CustomerID;
cout<<"\nPlease Enter The Customer Name:"<<endl;
cin>>CustomerName;
strcpy(cust_array[size].Customer_Name,CustomerName);
cout<<"\nPlease Enter The Gender:"<<endl;
cin>>gender;
strcpy(cust_array[size].Gender,gender);
cout<<"\nPlease Item Category:"<<endl;
cin>>ItemName;
strcpy(cust.category_array[size].Item_name,ItemName);
cout<<"\nPlease Enter the ItemNumber:"<<endl;
cin>>ItemNo;
cust.category_array[size].Item_number=ItemNo;
cout<<"\nPlease Enter The Item Price:"<<endl;
cin>>price;
cust.category_array[size].Item_price=price;
cout<<"\nPlease Enter The Item Quantity:"<<endl;
cin>>quantity;
cust.category_array[size].Item_quantity=quantity;
cout<<"\nPlease Enter The Expiry Date:"<<endl;
cin>>Date;
strcpy(cust.category_array[size].Expire_date,Date);
}
public:
void Display()
{
cout<<"\n---------------------------------------------------------"<<endl;
cout<<"\n*******************Customer
Information:******************"<<endl;
cout<<"\n---------------------------------------------------------"<<endl;
cout<<"\nCustomerid\t\tCustomer_Name\t\tGender\t\tPurchased_Item\t\tItem_Price\n"<<endl;
for(int i=0;i<size;i++)
{
cout<<cust_array[i].Customer_ID<<"\t"<<cust_array[i].Customer_Name<<"\t\t"<<cust_array[i].Gender<<"\t\t"<<cust.category_array[i].Item_name<<"\t\t"<<cust.category_array[i].Item_price<<endl;
}
}
public:
int Find(int id)
{
for(int i=0;i<size;i++)
{
if(id==cust_array[i].Customer_ID)
{
cout<<"\nCustomer
id:\t"<<cust_array[i].Customer_ID<<endl;
cout<<"\nCustomer
Name:\t"<<cust_array[i].Customer_Name<<endl;
cout<<"\nCustomer Purchased Item
is:"<<cust.category_array[i].Item_name<<endl;
return 1;
}
}
return -1;
}
public:
void copy()
{
}
public:
int Length()
{
return size;
}
public:
void update(int id,int pos)
{
cout<<"\n-----------------------------------"<<endl;
cout<<"\nPlease Enter New Update Values:"<<endl;
cout<<"\nPlease Enter The Customer Name:"<<endl;
cin>>CustomerName;
strcpy(cust_array[pos].Customer_Name,CustomerName);
cout<<"\nPlease Enter The Gender:"<<endl;
cin>>gender;
strcpy(cust_array[pos].Gender,gender);
cout<<"\nPlease Item Category:"<<endl;
cin>>ItemName;
strcpy(cust.category_array[pos].Item_name,ItemName);
cout<<"\nPlease Enter the ItemNumber:"<<endl;
cin>>ItemNo;
cust.category_array[pos].Item_number=ItemNo;
cout<<"\nPlease Enter The Item Price:"<<endl;
cin>>price;
cust.category_array[pos].Item_price=price;
cout<<"\nPlease Enter The Item Quantity:"<<endl;
cin>>quantity;
cust.category_array[pos].Item_quantity=quantity;
cout<<"\nPlease Enter The Expiry Date:"<<endl;
cin>>Date;
strcpy(cust.category_array[pos].Expire_date,Date);
cout<<"\nNew Details are Updated
Successfully:"<<endl;
}
};
int main()
{
int option;
int customer_id,retval;
Company obj;
cout<<"\n-------------------------"<<endl;
cout<<"\nKeep Track of Company And Customer
Details:"<<endl;
while(1){
cout<<"\n***** MENU *******"<<endl;
cout<<"\n1.Create"<<endl;
cout<<"\n2.Display"<<endl;
cout<<"\n3.Add"<<endl;
cout<<"\n4.Delete"<<endl;
cout<<"\n5.Update"<<endl;
cout<<"\n6.Find/Search"<<endl;
cout<<"\n7.copy"<<endl;
cout<<"\n8.Length/Size"<<endl;
cout<<"\n9.Clear\n"<<endl;
cout<<"\n10.Exit"<<endl;
cout<<"\nSelect any Option:"<<endl;
cin>>option;
switch(option)
{
case 1:
obj.create();
break;
case 2:
obj.Display();
break;
case 3:
cout<<"\nAdd New Details:"<<endl;
obj.add();
break;
case 4:
cout<<"\nPlease Enter The Customer id to
Delete:"<<endl;
cin>>customer_id;
retval=obj.Find(customer_id);
if(retval!=-1)
{
cout<<"\nThe Customer Deatails are Not
Found:"<<endl;
}
else
{
cout<<"\nDelete This Customer
Information:"<<endl;
obj.deletebyvalue(retval,customer_id);
}
break;
case 5:
cout<<"\nPlease Enter The Customer id to Update
Information:"<<endl;
cin>>customer_id;
retval=obj.Find(customer_id);
if(retval!=-1)
{
cout<<"\nThe Customer Deatails are Not
Found:"<<endl;
}
else
{
cout<<"\nDelete This Customer
Information:"<<endl;
obj.update(retval,customer_id);
}
break;
case 6:
cout<<"\nPlease Enter The Customer id:"<<endl;
cin>>customer_id;
retval=obj.Find(customer_id);
if(retval!=-1)
{
cout<<"\nThe Customer Deatails are Not
Found:"<<endl;
}
break;
case 7:
break;
case 8:
cout<<"\nThe Length
is:"<<obj.Length()<<endl;
break;
case 9:
break;
case 10:
exit(0);
default:
cout<<"\nWrong Option Try Again"<<endl;
}
}
}