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.
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...
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...
How do I write a C# and a C++ code for creating a character array containing...
How do I write a C# and a C++ code for creating a character array containing the characters 'p', 'i', 'n','e','P','I','N','E' only and then using these lower and capital case letter character generate all possible combinations like PInE or PinE or PIne or PINE or piNE etc. and only in this order so if this order is created eg. NeIP or EnPi or NeIP or IPnE and on. You can generate all the combinations randomly by creating the word pine...
Given the following array, write a program in C++ to sort the array using a selection...
Given the following array, write a program in C++ to sort the array using a selection sort and display the number of scores that are less than 500 and those greater than 500. Scores[0] = 198 Scores[3] = 85 Scores[6] = 73 Scores[9] = 989 Scores[1] = 486 Scores[4] = 216 Scores[7] = 319 Scores[2] = 651 Scores[5] = 912 Scores[8] = 846
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....
a) Write C code initialize an array of ints to the last four digits of your...
a) Write C code initialize an array of ints to the last four digits of your phone number. Use a loop to add the digits. Calculate and display the average of the digits. b) Write C code using a struct to hold student information: integer id integer number of hours taken integer number of hours passed double gpa
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT