Question

In: Computer Science

Write a code in c++ using dynamic array of structure and dynamic array list. Make a...

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

Solutions

Expert Solution

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;
}
}
}


Related Solutions

Write a code using c# Maximum Sub Array.
Write a code using c# Maximum Sub Array.
Implement a stack in C++ using an array, not an array list. Make your stack size...
Implement a stack in C++ using an array, not an array list. Make your stack size 5 when you test it, but do not hardcode this! You should be able to change the size for testing purposes with the change of one variable. DO NOT use Stack class defined in C++ Implement the following methods in your stack class. stack() creates an empty stacks, stack s is new and empty. push(item) adds a new item to the stack s, stacks...
C++ Write the code to implement a complete binary heap using an array ( Not a...
C++ Write the code to implement a complete binary heap using an array ( Not a vector ). Code for Max heap. Implement: AddElement, GetMax, HeapSort, ShuffleUp, ShuffleDown, etc Set array size to 31 possible integers. Add 15 elements 1,3,27,22,18,4,11,26,42,19,6,2,15,16,13 Have a default constructor that initializes the array to zeros.. The data in the heap will be double datatype. PART 2 Convert to the program to a template, test with integers, double and char please provide screenshots thank you so...
Explain this code: The structure used is max heap using array. C++ (i is the index...
Explain this code: The structure used is max heap using array. C++ (i is the index of the element to be deleted) void del(int i) {    int left,right,temp;    arr[i]=arr[n-1];    n=n-1;    left=2*i+1; /*left child of i*/    right=2*i+2; /* right child of i*/    while(right < n)    {        if( arr[i]>=arr[left] && arr[i]>=arr[right] )            return;        if( arr[right]<=arr[left] )        {            temp=arr[i];            arr[i]=arr[left];   ...
write code to manage a linked list using recursive approach. (Using this code) C++ IN Unix....
write code to manage a linked list using recursive approach. (Using this code) C++ IN Unix. // app.cpp #include <iostream> #include "linkedlist.h" using namespace std; void find(LinkedList& list, char ch) {    if (list.find(ch))        cout << "found ";    else        cout << "did not find ";    cout << ch << endl; } int main() {    LinkedList   list;    list.add('x');    list.add('y');    list.add('z');    cout << list;    find(list, 'y');    list.del('y');    cout...
Written in C code: Using a structure called person, write a C function called compare_age that...
Written in C code: Using a structure called person, write a C function called compare_age that takes two person structure pointers as input and returns 1 if the first person is older, -1 if the second person is older, or 0 if they have exactly the same birthday. Hint: Compare the years first, then if equal compare months, if they are equal compare days. The structure called person should contain the following; has fields for name (50 char array), dateOfBirth...
Write a C++ function that takes a two dimensional dynamic array (matrix) and its sizes and...
Write a C++ function that takes a two dimensional dynamic array (matrix) and its sizes and returns true if the matrix is an upper matrix and returns false otherwise. Remark: A matrix M is an upper matrix if it is a square matrix (row size = column size) and every element M[i][j] = 0 for all i > j. That is all the elements of the matrix below the main diagonal are zero.
Implement a Bag ADT using Dynamic Array structure as underlying data storage for Bag ADT. RESTRICTIONS:...
Implement a Bag ADT using Dynamic Array structure as underlying data storage for Bag ADT. RESTRICTIONS: Not allowed to use ANY built-in Python data structures and their methods. You must solve by importing the DynamicArray class and using class methods to write solution. Also not allowed to directly access any variables of the DynamicArray class (like self.size, self.capacity and self.data in part 1). All work must be done by only using class methods. Below is the Bag ADT starter code...
Python. The array C has multibel peaks (+ , -). write a code that detect the...
Python. The array C has multibel peaks (+ , -). write a code that detect the vlaues of all those peaks. C = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0011 -0.0031 0.0011 0.0034 -0.0039 0.0004 0.0052 -0.0045 -0.0025 0.0067 -0.0038 -0.0034 0.0077 -0.0034 -0.0054 0.0076 -0.0011 -0.0063 0.0068 0.0004 -0.0084 0.0061 0.0037 -0.0086 0.0018 0.0063 -0.0045 -0.0069 0.0078 0.0027 -0.0132 0.0054 0.0133 -0.0131 -0.0060 0.0180 -0.0037 -0.0169 0.0140 0.0128 -0.0210...
IN C++ (THIS IS A REPOST) Design a class, Array, that encapsulates a fixed-size dynamic array...
IN C++ (THIS IS A REPOST) Design a class, Array, that encapsulates a fixed-size dynamic array of signed integers. Write a program that creates an Array container of size 100 and fills it with random numbers in the range [1..999]. (Use std::rand() with std::srand(1).) When building the array, if the random number is evenly divisible by 3 or 5, store it as a negative number. Within your main.cpp source code file, write a function for each of the following processes....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT