This assignment is building on the attached shop program in C programming language. There are two parts to this assignment. The first part should be written in C and the second part in Java. The...

1 answer below »


This assignment is building on the attached shop program in C programming language. There are two parts to this assignment. The first part should be written in C and the second part in Java. The following functionality should be added to the existing C code:







·
Read in the customer name and budget from Orders.csv




·
Read in the customer orders (product & quantity) from Orders.csv




·
Process the customer order




·
Update the cash in the shop based on money received




·
Read in Orders_Test_File.csv which cannot be completed because order quantity is to large and show an appropriate error.




·
Know if an order can be completed based on shop stock.




·
Operate in a live mode, allowing the user to enter a product by name, specify a quantity and pay for it.












The second part of the assignment involves replicating the functionality in Java. This should be done in an appropriately Object Orientated manner.

Answered Same DayNov 09, 2021

Answer To: This assignment is building on the attached shop program in C programming language. There are two...

Arun Shankar answered on Nov 16 2021
152 Votes
customer.csv
James,1000
Coke Can,10
Bread,3
Spagetti,5
Tomato Sauce,1
Bin Bags,2
main.c
#include
#include
#include
char chunk[128];
struct Product
{
    int pid;
// Product id - unique to the product.
char* name; // Name of the product
    double price; // Price of one unit of the product.
int quantity; // How many units of this pdt. in the shop ?
};
struct Shop
{
    double cash; // Cash in the shop
    struct Product stock[20]; // Stock info
int count; // Number of items in the inventory.
};
struct CartEntry
{
int pid;
int qty;
};
struct Customer
{
    char* name; // Customer name
    double budget; // Customer's budget
    struct CartEntry shoppingList[10]; // Shopping cart.
    int cart_size; // Number of items in the cart
double cart_value; // Value of the cart
};
void printProduct(struct Product p)
{
    printf("PRODUCT ID: %d\tNAME: %s\tPRICE: %.2f\n", p.pid, p.name, p.price);
}
struct Shop createAndStockShop()
{
    FILE * fp;
char * line = NULL;
size_t len = 0;
ssize_t read;
fp = fopen("stock.csv", "r");
if (fp == NULL)
exit(EXIT_FAILURE);
//read in first line from csv
fgets(chunk, sizeof(chunk), fp);
double cashInShop = atof(chunk);
struct Shop shop = { cashInShop };
shop.count = 0;
//while loop reads in subsequent lines
int id = 0;
while((fgets(chunk, sizeof(chunk), fp)) != NULL)
{
char *n = strtok(chunk, ",");
char *p = strtok(NULL, ",");
char *q = strtok(NULL, ",");
int quantity = atoi(q);
double price = atof(p);
char *name = malloc(sizeof(char) * 50);
strcpy(name, n);
struct Product product = { id++, name, price, quantity };
shop.stock[shop.count++] = product;
}
    return shop;
}
double GetStock(struct Shop* sptr, int pid)
{
for(int i=0;icount;i++)
if(sptr->stock[i].pid==pid)
return sptr->stock[i].quantity;
return 0;
}
void DecreaseStock(struct Shop* sptr, int pid, int qty)
{
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here