Homework Help for Information Technology

1,532 results

IT encompasses the study, use, and service of coputers and communication systems for storing, sending, receiving and manipulation data and information

For unlimited access to Homework Help, a Homework+ subscription is required.

Lv1
in Information Technology·
12 Apr 2023

Can someone help me fix/edit my below C code to output everything from the attached assignment below my C code.  If you could please read the step by step in the project as its very detailed and long. I realy need a 100% completed code. Thx.

---------------------------------------------------------------------------------

#include <stdio.h>
#include <stdbool.h>
#include <string.h>

// Define constants for currency conversion rates
#define USD_TO_CAD 1.3
#define USD_TO_MXN 21.0

// Define structs for different features and specifications of a car
struct Engine {
    char type[20];
    int horsepower;
};

struct Chassis {
    int weight;
    int length;
};

struct Exterior {
    char color[20];
    bool upgradeableColor;
};

struct SeatingAndTrim { 
    char trim1[20];
    char trim2[20];
};

struct Dimensions {
    int height;
    int width;
};

struct FuelEconomy {
    int cityMPG;
    int highwayMPG;
};

struct Car {
    char model[20];
    char manufacturer[20];
    struct Exterior exterior;
    int mileage;
    bool isAutomatic;
    struct Engine engine;
    struct Chassis chassis;
    struct SeatingAndTrim seatingAndTrim;
    struct Dimensions dimensions;
    bool hasAirbags;
    int numAirbags;
    struct FuelEconomy fuelEconomy;
    bool isHybrid;
    bool isFullyElectrified;
    bool hasAutoParkingAssist;
    bool hasNightVisionAssist;
    bool hasCruiseControl;
    bool is2WD;
    bool hasHillAssist;
    bool hasTPMS;
    bool hasVoiceCommand;
    bool hasLaneChangeIndicator;
    bool hasForwardCollisionWarning;
    bool hasBlindSpotWarning;
    int numSeatHeaters;
    bool hasSteeringHeater;
};

sstruct Branch exampleBranch = {
    .address = "1234 Main St",
    .postalCode = "A1B 2C3",
    .phoneNumber = "123-456-7890",
    .faxNumber = "987-654-3210",
    .customerServiceEmail = "[email protected]",
    .gmName = "John Doe",
    .gmPhoneNumber = "111-222-3333",
    .gmCellPhoneNumber = "444-555-6666",
    .gmAddress = "5678 Elm St",
    .gmEmail = "[email protected]",
    .gmDateOfEmployment = "01/01/2010",
    .gmYearsOfExperience = 10,
    .financeManagerFirstName = "Jane",
    .financeManagerLastName = "Doe",
    .financeManagerPhoneNumber = "777-888-9999",
    .financeManagerCellPhoneNumber = "000-111-2222",
    .financeManagerAddress = "9876 Oak St",
    .financeManagerDateOfEmployment = "02/02/2015",
    .financeManagerYearsOfExperience = 6,
    .numAvailableCars = 10,
    .inventory = {exampleCar, exampleCar, exampleCar, exampleCar, exampleCar,
                  exampleCar, exampleCar, exampleCar, exampleCar, exampleCar}
};

// Calculate the price after applying rebate or promotion
double price = 50000;
const char* model = "Honda";
const char* manufacturer = "Honda";
const char* country = "Canada";
double convertedPrice = convertCurrency(price, country);
double finalPrice = applyRebateOrPromotion(convertedPrice, model, manufacturer, country);

printf("Original Price

// Function to calculate price after applying rebate or promotion
double applyRebateOrPromotion(double price, const char* model, const char* manufacturer, const char* country) {
    if (strcmp(model, "Honda") == 0 && strcmp(country, "Canada") == 0) {
        return price * 0.98; // 2% rebate for Honda in Canada
    }
    else if (strcmp(manufacturer, "Volvo") == 0 && price > 60000 && strcmp(country, "Mexico") == 0) {
        return price * 0.97; // 3% rebate for Volvo above 60,000 in Mexico
    }
    else if ((strcmp(manufacturer, "BMW") == 0 || strcmp(manufacturer, "Volvo") == 0 ||
        strcmp(manufacturer, "Audi") == 0 || strcmp(manufacturer, "Bentley") == 0 ||
        strcmp(manufacturer, "Ferrari") == 0) && strcmp(country, "USA") == 0) {
        return price * 0.975; // 2.5% promotion for eligible brands in USA
    }
    return price;
}

--------------------------------------------------------------------------------

In this project, you are working on the back end of a famous car dealership website.

The name of the dealership you are working with is your first name and your last name.

Your dealership has 5 different branches in 5 different cities in North America including Canada, USA, and Mexico. Therefore, the offers and prices are in three different currencies.

In case, you need to implement a conversion rate, you can implement a fixed rate; however, implementing a variable rate would be an advantage and you will receive extra points.

As an example, the rate to convert the USD to CAD can be assumed as a fixed rate of 1.3; though in reality, this rate could change from 1.2 to 1.4 on daily basis.

The same as the previous project you have gone through, you need to deal with an inventory.

In this project, each of the branches holds a minimum of 5 cars and a maximum of 10 cars.

The dealership works with the following brands which are divided into three different categories:

Group 1:

- Kia

- Toyota

- Honda

- Mazda

- Nissan



Group 2:

- Ford

- Genesis

- Volvo

- Acura



Group 3:

- BMW

- Audi

- Bentley

- Ferrari

- Aston Martin

- Bugatti



Each car you define MUST have two different trims.



The features and specifications you need to define for the cars are listed below:

- Model

- Manufacturer

- Color (upgradable)

- Mileage

- Manual/Automatic Transmission (upgradable)

- Engine (Engine struct)

- Chassis (Chassis struct)

- Exterior (Exterior struct)

- Seating & Trim (Seating & Trim struct)

- Dimensions (Dimensions struct)

- Airbags (Yes/No)

- number of the Airbags

- Fuel Economy (Fues Struct)

- Hybrid (Yes/No)

- Fully Electrified (Yes/No)

- Automatic Parking Assistance (Yes/No - Upgradable)

- Night Vision Assistance (Yes/No)

- Cruise Control (Yes/No - Upgradable)

- 2WD/4WD

- Hill assist

- Tire Pressure Monitoring System (Yes/No - Upgradable)

- Voice Command

- Lane Change Indicator

- Forward Collision Warning Sensor

- Blind spot warning sensors

- Seat heater (numbers)

- Steering heater (Yes/No)





Each branch has the following public information :

- Address

- Postal Code

- Phone number

- Fax Number

- Customer Service Email

- Name of the General Manager



Each branch has the following confidential information:

- General Manager’s phone number

- General Manager’s cell phone number

- General Manager’s address

- General Manager’s Email

- General Manager’s date of employment

- General Manager’s years of experience

- Finance Manager’s first name and last name

- Finance Manager’s phone number

- Finance Manager’s cell phone number

- Finance Manager’s address

- Finance Manager’s date of employment

- Finance Manager’s years of experience

- Number of the available cars

- Complete Information about the available cars

There are four different stories that your code must represent:

1. One of the branches of the dealership sells a car (The inventory must be updated)

2. One of the branches of the dealership buys a car (The inventory must be updated)

3. One of the branches of the dealership transfers a car from one branch to the other (the transfer expenses and the currency rate must be taken into consideration.)

4. The dealership supplies brand-new cars to the different branches


- All brand-new Honda in Canada has a 2% rebate as a credit.

- All brand-new Volvo above 60,000 in Mexico have a 3% rebate as credit.

- In the USA, there is a loyalty program for BMW, VOLVO, AUDI, BENTLEY, and Ferrari - If the customer is eligible for the loyalty program then a 2.5% promotion will be implemented to their purchase (not a rebate).


Your website has a search engine based on your available inventories of all the branches and the following inputs could be inserted from the user as the search criteria:

1. Car Model

2. Car Manufacturer

3. Brand-new / Used / Both

4. Range of mileage 

5. Price range

6. Color

7. Availability in the country (In this case, you initially need to determine the location)

 

Your assignment will be working with the phonebook file. Out of country students without access to Atlas will need to install Ubuntu or other Linux on a VM on their desktop and email me for instructions.

Make a subdirectory of your home/SYST13416 called “assignment” and then make it your pwd.

In the  assignment directory make a file called “assign”. This will be your assignment shell script. Ensure others cannot read this file, remove the r permission for group.

Copy the phonebook file from /tmp/phonebook so it is in your pwd. Create a backup of it, call it phonebook.bk.

Copy /tmp/appendfile so it is in your pwd. The file looks as follows:

 

Edit the file using vi so that your first name and last name replace the FNAME LNAME text. You may need to change the security setting to do this.

Now, edit the script assign to do the following scenarios. You will find it works best if you do it iteratively, not all at once. DO one function at a time, test it/debug and fix it and then move to next:

  1. If you simply call the script without any parameters, it will ask the user for the LAST name of the person to pull the information for. You will display this record and exit the shell script with return code 1. If you do not find the record, provide an error message and such as “This Last Name was not found, sorry” and exit the script with return code 2.
  2. If you call the script with option -f , then this means the script will prompt the user for the FIRST name of the person you are looking for. If you find that person, display ONLY their phone extension (hint, use cut command). Exit with return code 3.
  3. If the script has option -c, then the system will make a campus phonebook for the user. It will prompt the user for the campus code such as NH. Look carefully where that campus code is in the file and create a regex that matches it. Your script will find all the people in that campus and create a file with the name of the campus.book. So, for NH it would be NH.book. Put this file in your pwd, but create a link to it which you put in your /tmp/`whoami` directory (the whoami is replaced by your username).
  4. If the script uses option -a, then prompt the user for a filename and then append that file to the phonebook. This will be used to add yours and my record to the phonebook. Then, exit the script.
  5. Otherwise, for each separate word that is passed to the script as a positional parameter, search for that regex int the file and append the records to a file you will call result. If you don’t find the name, add a line to result indicating that you could not find it.

After you are done with the script, create a link to the file result and put in your /tmp/`whoami` directory.

 

Note: the code to run the regular expressions needed for this assignment is no more than standard grep. If you find yourself using extended regular expressions and/or awk, you are likely doing something more complicated than need be. Do not take code and copy code from someone else without knowing exactly how it works. You may be challenged by the instructor to explain your code. Not being able to explain code you wrote, would be automatic “F”.

 

To exercise your script, run the following commands, capture the screen images and submit this file into the drop box.

 

At a high level, here is the test for your script:

  1. bash assign   (5 marks)
  2. bash assign -f (5 marks)
  3. bash assign -c (5 marks)
  4. bash assign -a (5 marks)
  5. bash assign Buchner Cheryl Joel Elvis <yourname>   (10 marks)

Tips:

  • ignore case for your greps
  • be careful to embed your strings with “ “
  • Use $? To check return codes and determine if a command worked
  • Look at the phonebook file carefully (in vi?) to see how it is structured so that you can grep the correct pattern/regex
  • Use echo and read to write and read from terminal session
  • Use exit to exit a script. If you put a number after it, the value of the number will be $?. If not, $? will be 0. So ,exit 2 will return $? value of 2
  • Use cut to select fields or characters in the output
  • Use pipe to make more complicated filters
  • You can redirect or append your output

 

Details for your submission:

  1. bash assign
  • shell will prompt for a last name
  • enter the last name Pangborn
  • type echo $? the result should be 2
  • type bash assign again
  • enter the last name Trudeau
  • Shell should present a message that it was not found
  • Type echo $? The result should be 1
  • Type whoami

It should look something like the following

 

 

  • Take a screen shot of above steps on your screen and paste below.

 

  1. bash assign -f

- shell will prompt for a first name

- enter the first name Mark

- The system should only get phone numbers for persons with Mark (not city Markham or last name Markovski). The result should be something like the following. You are welcome to make it look better.

--

  • Next if you type echo $? The result should be 3.
  • Last, type whoami so I can see this is your screen

 

 

Take a screen shot of above steps and paste below.

 

 

 

  1. bash assign -c
  • shell will tell you it is making a campus phonebook
  • enter     LE
  • the system will make a campus phonebook called LE.book
  • type ls and take a screen shot and paste it here

 

 

 

 

 

  • if you type cat LE.book, you will see only people in the LE campus (the second fields will only LE)

 

  • Type the command whoami so I can see this is your session
  • Take a screen shot of above steps and paste below.

 

 

 

 

 

  1. bash assign -a
  • The system should prompt you for the name of the file you want to append
  • Type the filename appendfile (or whatever you called the file)

 

Take a screen shot of above steps and paste the result below

 

 

  1. bash assign Buchner Cheryl Joel Elvis <yourname>

 

 

  •  

I would expect to see your name come up as a Linux Student along with mine, I would expect you not to find Elvis

As per above, dump the contents of file “found” and provide a screen shot.

 

Final Step:

Cut and paste the code for  your shell script here. I would like to see the code YOU wrote. I do not want screen shots of code.

TurnItIn is ON, and so I am not expecting you to submit your friends assignment. I may ask you to present your code to me via SLATE virtual classroom. This step is worth 20 marks.

Another way to submit the code for your shell script is to ftp it from the atlas server to your laptop and then submit it to the drop box directly as a .sh file. TO do that, you would install an FTP client on your laptop and then access your atlas account using [email protected].  Navigate your way to the directory contain the script and download it. It is best add extension .sh or .bash for it to work. You can now upload that file and add it as a second submission to the drop box. You will receive a bonus point if you do this. The process is similar to your webdev class where you have to upload .html files which you have developed on your laptop to your apache server.

 

 

 

 

 

 

Lv1
in Information Technology·
6 Apr 2023

Can someone please fix my errors in code?

 

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct person {
    char name[30];
    char last_name[30];
    int age;
    float wage;
} person1;

struct person {
    char name[30];
    char last_name[30];
    int age;
    float wage;
} person2;

struct person {
    int age;
    float wieght;
    char name[30];
};

typedef struct people {
    char name[30];
    char last_name[30];
    int age;
    float wage;
}person2;

struct pers {
    int age;
    double wieght;
};

int main() {
    //first Example:

    printf("Example 1: \n");
    scrcpt(person1.name, "James Bond");
    person1.age = 55;
    person1.wage = 17.7;

    printf("The name of this person is %s. \n", person1.name);
    printf("The age of this person is %s. \n", person1.age);
    printf("The wage of this person is %s. \n", person1.wage);
    printf("\n \n");
    //---------------------------------------------------------------------------------------------------
    // 2nd Example:
    printf("Example 2: \n");
    person2 student1;
    strcpy(student1.name, "James Bond");
    person1.age = 55;
    person1.wage = 17.7;

    printf("The name of this person is %s. \n", person1.name);
    printf("The age of this person is %s. \n", person1.age);
    printf("The wage of this person is %s. \n", person1.wage);
    printf("\n \n");
    //---------------------------------------------------------------------------------------------------
    // 3rd Example:
    // In this example, we would like to get access for menbers using Pointer
     // 2nd Example:
    printf("Example 3: \n");
    struct pers* personPtr, person11;
    personPtr = &person11;

    printf("Please insert thae age of this person: \n");
    scanf("%d", &personPtr->age);

    printf("Please insert the wieght of this person: \n");
    scanf("%d", &personPtr->wieght);

    printf("The age of this person is %d. \n", personPtr->age);
    printf("The wieght of this person is %s. \n", personPtr->wieght);
    
    
    struct person* ptr;

    int n;
        
    printf("Please, enter the number of the persons that are going to be in this struct: ");
    scanf("&d", &n);

    ptr = (struct persons*)malloc(n * sizeof(struct person));

    for (int i = 0; i < n; i++) {

        printf("Please insert the name followed by age of the person, serperated with a space: ");
        scanf("%s %d", (ptr + i)->age);
    }

    printf("Let's dispaly the inserted names and thier ages: ");

    for (int i = 0; i < n; i++) {
        printf("Name: %s - Age: %d \n", (ptr + i)->name, (ptr + i)->age);
    }

    return 0;
}

Lv1
in Information Technology·
3 Apr 2023

this is the assignment: Not sure if the code you sent outputs everything the assignment asks.

 

In this activity, you are designing an application for grocery stores and their inventories.

The items depending on their type are divided into the following categories:

Group A: Meat

Group B: Deli

Group C: Pharmacy

Group D: Seafood

Group E: Beverage

Group F: Canned

Group G: Jarred

Group H: Dry Food

Group I: Dairy

Group J: Bakery

Group K: Personal Care

Group L: Paper Goods

Your store must have at least 3 items in each category.

Your application as the first step needs to collect the following information before importing the items to the store:

1. The name of the product

2. The Category

3. The Company/Manufacturer name

4. The purchased price (What company has paid to buy this product)

5. The sale price (What customers will pay to buy this product)

6. The quantity of the purchased items

7. The date of the purchased items

8. The date of the production

9. The expiry date of the product

10. Store Code (a 4-digit number)

11. The currency of the country


12. Items will go on sale on different dates depending on their categories.

Your application is responsible to use encryption method 1 for #1, and #3. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 2 for #2. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 3 for #4, and #5. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 4 for #6. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 5 for #7, #8, and #9. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 6 for #10. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 7 for #11. (You have to define the suitable encryption method.)


The output of the encryptions will generate a number that will be known as the barcode of that specific item in this store.

Before selecting and implementing your encryption methods, you have to answer the following questions:

- Will all the generated barcodes have the same number of digits?

- How should we deal with barcodes that have different numbers of digits?

- Do you need to define decryption?

- Is there any other questions, aspects, complications, simplifications, etc. that I need to think about in advance?

Items will go on sale on different dates depending on their categories.

Group A, B, C, and D follow the following rules:

- Items will go on a 10% promotion when the date passes 50% of the durable life period - Yellow Tag

- Items will go on a 25% promotion when the date passes 65% of the durable life period - Green Tag

- Items will go on a 50% promotion when the date passes 75% of the durable life period - Red Tag

- Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag and Final Sale (Bring Me Home Today!)

- Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory

Group E, F, G, and H follow the following rules:

- Items will go on a 10% promotion when the date passes 60% of the durable life period - Yellow Tag

- Items will go on a 25% promotion when the date passes 70% of the durable life period - Green Tag

- Items will go on a 50% promotion when the date passes 80% of the durable life period - Red Tag

- Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag and Final Sale (Bring Me Home Today!)

- Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory


Groups I, J, and K follow the following rules:

- Items will go on a 10% promotion when the date passes 40% of the durable life period - Yellow Tag

- Items will go on a 25% promotion when the date passes 50% of the durable life period - Green Tag

- Items will go on a 50% promotion when the date passes 60% of the durable life period - Red Tag

- Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag (Bring Me Home Today!)

- Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory

Group L follows the following rules:

- Items will go on a 10% promotion when the date passes 70% of the durable life period - Yellow Tag

- Items will go on a 25% promotion when the date passes 80% of the durable life period - Green Tag

- Items will go on a 50% promotion when the date passes 90% of the durable life period - Red Tag

- Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag and Final Sale (Bring Me Home Today!)

- Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory

The output of your program will be a printed receipt that shows a list of 12 items (one item from each category), 8 items with the regular price, and 4 items on sale that a customer bought also the customer has 3 items to return from three different categories.

A receipt needs to include the following information on it:

- The price of each item that has a regular price

- If the price is reduced the reduction amount and sales percentage will be printed on the lines below the regular price; therefore the customer will see the regular price, the sales price, the reduced amount, and the sales percentage

- Each item has a unique barcode
- The date and the time of the purchase
- The store number along with the address of the store
- The final Balance
- The payment method

As per our discussion in class, your code needs to ask the following question from the user at the very beginning:
"Would you like to import any item to your store?"
The answer to this question is YES/NO.
If YES, there will be 12 steps to collect the information related to that specific item being imported to the store to fill in and then, the program will proceed with the following steps.
If No, 30 items (3*10, 3 items in each category) have already existed in our store and the program will proceed with the following steps.

Memory management, allocating, and deallocating memory are one of the most important aspects to be considered in this project.

Regarding the promotions tags available in different colors, your application must be able to generate a list of items with the proper color of the tag that depends on the percentage of the promotion.



In order to submit your final version, you need to record a video, a maximum of 4 minutes. In this video, you need to explain the different parts of the code you have written, the functions, the pointers, memory allocation, memory management, and encryption methods, and if available the decryption methods must be explained verbally. The steps you are taking in explaining your written code must follow the steps, line by line, of your main function. This video should clarify the approaches you have taken along with the fulfillment of the requirements of this project.

Lv1
in Information Technology·
3 Apr 2023

My instructor stated this code is only 15% done?

 

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h>


// Define the encryption methods for each item category 

int encrypt_method[] = { 1, 2, 1, 3, 3, 5, 5, 5, 6, 7, 7, 4 };

// Define the durable life period for each item category in days 

int life_period[] = { 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130 };

// Define the sale promotion percentage for each item category 

int promotion[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

// Define the regular price for each item category 

float regular_price[] = { 12.50, 10.20, 8.75, 6.99, 18.99, 15.55, 11.79, 9.99, 7.25, 5.49, 13.99, 23.99 };

// Define the items bought by the customer 

int bought_items[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

// Define the items returned by the customer 

int returned_items[] = { 3, 7, 11 };

int main()
{
    char barcode[20];
    int i, j;
    float price, sale_price, total_price = 0.0;

    // Generate barcodes for each item and print the receipt
    printf("Receipt:\n");

    for (i = 0; i < 12; i++) {
        // Encrypt the barcode using the appropriate encryption method
        switch (encrypt_method[i]) {
        case 1:
            sprintf(barcode, "ABC%d", bought_items[i]);
            break;
        case 2:
            sprintf(barcode, "DEF%d", bought_items[i]);
            break;
        case 3:
            sprintf(barcode, "GHI%d", bought_items[i]);
            break;
        case 4:
            sprintf(barcode, "JKL%d", bought_items[i]);
            break;
        case 5:
            sprintf(barcode, "MNO%d", bought_items[i]);
            break;
        case 6:
            sprintf(barcode, "PQR%d", bought_items[i]);
            break;
        case 7:
            sprintf(barcode, "STU%d", bought_items[i]);
            break;
        default:
            sprintf(barcode, "UNK%d", bought_items[i]);
            break;
        }

        // Calculate the sale price of the item based on the promotion percentage
        sale_price = regular_price[i] * (1 - promotion[i] / 100.0);

        // Check if the item was returned and adjust the total price accordingly
        for (j = 0; j < 3; j++) {
            if (returned_items[j] == bought_items[i]) {
                total_price -= sale_price;
                break;
            }
        }

        // Add the sale price of the item to the total price
        total_price += sale_price;

        // Print the barcode and sale price of the item
        printf("%s %.2f\n", barcode, sale_price);
    }

    // Print the total price of the items purchased
    printf("Total: %.2f\n", total_price);

    // Print the total price of the items bought
    printf("Total price: $%.2f\n", total_price);

    // Get user input for product information
    char name[50];
    char category;
    char manufacturer[50];
    float purchased_price;
    sale_price;
    int quantity;
    char purchase_date[11];
    char production_date[11];
    char expiry_date[11];
    int store_code;
    char currency[4];

    printf("\nEnter the name of the product: ");
    scanf("%s", name);
    printf("Enter the category: ");
    scanf(" %c", &category);
    printf("Enter the company/manufacturer name: ");
    scanf("%s", manufacturer);
    printf("Enter the purchased price: ");
    scanf("%f", &purchased_price);
    printf("Enter the sale price: ");
    scanf("%f", &sale_price);
    printf("Enter the quantity of purchased items: ");
    scanf("%d", &quantity);
    printf("Enter the date of purchase (yyyy-mm-dd): ");
    scanf("%s", purchase_date);
    printf("Enter the date of production (yyyy-mm-dd): ");
    scanf("%s", production_date);
    printf("Enter the expiry date (yyyy-mm-dd): ");
    scanf("%s", expiry_date);
    printf("Enter the store code: ");
    scanf("%d", &store_code);
    printf("Enter the currency of the country: ");
    scanf("%s", currency);

    // Encrypt the necessary fields to generate the barcode

    // Print the barcode
    printf("Barcode: %s\n", barcode);

    // Determine the discount and print the tag color
    float discount_percentage = (1.0 - (sale_price / purchased_price)) * 100.0;

    if (discount_percentage > 20) {
        printf("Tag color: Red\n");
    }
    else if (discount_percentage > 10) {
        printf("Tag color: Yellow\n");
    }
    else {
        printf("Tag color: Green\n");
    }

    return 0;
}

Lv1
in Information Technology·
3 Apr 2023

sorry..added unessesary info. heres the assignment i need a code for. Thx

 

In this activity, you are designing an application for grocery stores and their inventories.

The items depending on their type are divided into the following categories:

Group A: Meat

Group B: Deli

Group C: Pharmacy

Group D: Seafood

Group E: Beverage

Group F: Canned

Group G: Jarred

Group H: Dry Food

Group I: Dairy

Group J: Bakery

Group K: Personal Care

Group L: Paper Goods

Your store must have at least 3 items in each category.

Your application as the first step needs to collect the following information before importing the items to the store:

1. The name of the product

2. The Category

3. The Company/Manufacturer name

4. The purchased price (What company has paid to buy this product)

5. The sale price (What customers will pay to buy this product)

6. The quantity of the purchased items

7. The date of the purchased items

8. The date of the production

9. The expiry date of the product

10. Store Code (a 4-digit number)

11. The currency of the country


12. Items will go on sale on different dates depending on their categories.

Your application is responsible to use encryption method 1 for #1, and #3. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 2 for #2. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 3 for #4, and #5. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 4 for #6. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 5 for #7, #8, and #9. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 6 for #10. (You have to define the suitable encryption method.)

Your application is responsible to use encryption method 7 for #11. (You have to define the suitable encryption method.)


The output of the encryptions will generate a number that will be known as the barcode of that specific item in this store.

Before selecting and implementing your encryption methods, you have to answer the following questions:

- Will all the generated barcodes have the same number of digits?

- How should we deal with barcodes that have different numbers of digits?

- Do you need to define decryption?

- Is there any other questions, aspects, complications, simplifications, etc. that I need to think about in advance?

Items will go on sale on different dates depending on their categories.

Group A, B, C, and D follow the following rules:

- Items will go on a 10% promotion when the date passes 50% of the durable life period - Yellow Tag

- Items will go on a 25% promotion when the date passes 65% of the durable life period - Green Tag

- Items will go on a 50% promotion when the date passes 75% of the durable life period - Red Tag

- Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag and Final Sale (Bring Me Home Today!)

- Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory

Group E, F, G, and H follow the following rules:

- Items will go on a 10% promotion when the date passes 60% of the durable life period - Yellow Tag

- Items will go on a 25% promotion when the date passes 70% of the durable life period - Green Tag

- Items will go on a 50% promotion when the date passes 80% of the durable life period - Red Tag

- Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag and Final Sale (Bring Me Home Today!)

- Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory


Groups I, J, and K follow the following rules:

- Items will go on a 10% promotion when the date passes 40% of the durable life period - Yellow Tag

- Items will go on a 25% promotion when the date passes 50% of the durable life period - Green Tag

- Items will go on a 50% promotion when the date passes 60% of the durable life period - Red Tag

- Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag (Bring Me Home Today!)

- Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory

Group L follows the following rules:

- Items will go on a 10% promotion when the date passes 70% of the durable life period - Yellow Tag

- Items will go on a 25% promotion when the date passes 80% of the durable life period - Green Tag

- Items will go on a 50% promotion when the date passes 90% of the durable life period - Red Tag

- Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag and Final Sale (Bring Me Home Today!)

- Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory

The output of your program will be a printed receipt that shows a list of 12 items (one item from each category), 8 items with the regular price, and 4 items on sale that a customer bought also the customer has 3 items to return from three different categories.

A receipt needs to include the following information on it:

- The price of each item that has a regular price

- If the price is reduced the reduction amount and sales percentage will be printed on the lines below the regular price; therefore the customer will see the regular price, the sales price, the reduced amount, and the sales percentage

- Each item has a unique barcode
- The date and the time of the purchase
- The store number along with the address of the store
- The final Balance
- The payment method

As per our discussion in class, your code needs to ask the following question from the user at the very beginning:
"Would you like to import any item to your store?"
The answer to this question is YES/NO.
If YES, there will be 12 steps to collect the information related to that specific item being imported to the store to fill in and then, the program will proceed with the following steps.
If No, 30 items (3*10, 3 items in each category) have already existed in our store and the program will proceed with the following steps.

Memory management, allocating, and deallocating memory are one of the most important aspects to be considered in this project.

Regarding the promotions tags available in different colors, your application must be able to generate a list of items with the proper color of the tag that depends on the percentage of the promotion.

Avatar image
vietchanghg answered this question
Lv1
in Information Technology·
3 Apr 2023

here it is:

 

                        6 of 202     assignment 158     School ITD Canada         Michael Banville <[email protected]> Mar 23, 2023, 4:20 PM (11 days ago)     to Farid           Hello Farid.   Here's my assignment 158.    Regards. Michael Banville       4 Attachments • Scanned by Gmail                     Michael Banville   Mar 30, 2023, 9:14 AM (4 days ago)   ---------- Forwarded message --------- From: Michael Banville <[email protected]> Date: Thu, Mar 23, 2023 at 4:20 PM Subject: assignment 158 To: Farid   Farid Vahedi   Mar 30, 2023, 9:39 AM (4 days ago)   Hi Mike, The project you have submitted is missing a long list of the requirements of the assigned project. What is submitted at this point is about 15% of what   Michael Banville <[email protected]> Mar 30, 2023, 12:38 PM (4 days ago)     to Farid           Thank you, I will do that.      ReplyForward                                                                             #include <stdio.h> #include <stdlib.h> #include <string.h> // Define the encryption methods for each item category int encrypt_method[] = { 1, 2, 1, 3, 3, 5, 5, 5, 6, 7, 7, 4 }; // Define the durable life period for each item category in days int life_period[] = { 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130 }; // Define the sale promotion percentage for each item category int promotion[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Define the regular price for each item category float regular_price[] = { 12.50, 10.20, 8.75, 6.99, 18.99, 15.55, 11.79, 9.99, 7.25, 5.49, 13.99, 23.99 }; // Define the items bought by the customer int bought_items[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; // Define the items returned by the customer int returned_items[] = { 3, 7, 11 }; int main() { char barcode[20]; int i, j; float price, sale_price, total_price = 0.0; // Generate barcodes for each item and print the receipt printf("Receipt:\n"); for (i = 0; i < 12; i++) { // Encrypt the barcode using the appropriate encryption method switch (encrypt_method[i]) { case 1: sprintf(barcode, "ABC%d", bought_items[i]); break; case 2: sprintf(barcode, "DEF%d", bought_items[i]); break; case 3: sprintf(barcode, "GHI%d", bought_items[i]); break; case 4: sprintf(barcode, "JKL%d", bought_items[i]); break; case 5: sprintf(barcode, "MNO%d", bought_items[i]); break; case 6: sprintf(barcode, "PQR%d", bought_items[i]); break; case 7: sprintf(barcode, "STU%d", bought_items[i]); break; default: sprintf(barcode, "UNK%d", bought_items[i]); break; } // Calculate the sale price of the item based on the promotion percentage sale_price = regular_price[i] * (1 - promotion[i] / 100.0); // Check if the item was returned and adjust the total price accordingly for (j = 0; j < 3; j++) { if (returned_items[j] == bought_items[i]) { total_price -= sale_price; break; } } // Add the sale price of the item to the total price total_price += sale_price; // Print the barcode and sale price of the item printf("%s %.2f\n", barcode, sale_price); } // Print the total price of the items purchased printf("Total: %.2f\n", total_price); // Print the total price of the items bought printf("Total price: $%.2f\n", total_price); // Get user input for product information char name[50]; char category; char manufacturer[50]; float purchased_price; sale_price; int quantity; char purchase_date[11]; char production_date[11]; char expiry_date[11]; int store_code; char currency[4]; printf("\nEnter the name of the product: "); scanf("%s", name); printf("Enter the category: "); scanf(" %c", &category); printf("Enter the company/manufacturer name: "); scanf("%s", manufacturer); printf("Enter the purchased price: "); scanf("%f", &purchased_price); printf("Enter the sale price: "); scanf("%f", &sale_price); printf("Enter the quantity of purchased items: "); scanf("%d", &quantity); printf("Enter the date of purchase (yyyy-mm-dd): "); scanf("%s", purchase_date); printf("Enter the date of production (yyyy-mm-dd): "); scanf("%s", production_date); printf("Enter the expiry date (yyyy-mm-dd): "); scanf("%s", expiry_date); printf("Enter the store code: "); scanf("%d", &store_code); printf("Enter the currency of the country: "); scanf("%s", currency); // Encrypt the necessary fields to generate the barcode // Print the barcode printf("Barcode: %s\n", barcode); // Determine the discount and print the tag color float discount_percentage = (1.0 - (sale_price / purchased_price)) * 100.0; if (discount_percentage > 20) { printf("Tag color: Red\n"); } else if (discount_percentage > 10) { printf("Tag color: Yellow\n"); } else { printf("Tag color: Green\n"); } return 0; }
Avatar image
mehdotstorm answered this question
Lv1
in Information Technology·
3 Apr 2023

Please turn this into C program code

In this activity, you are designing an application for grocery stores and their inventories. The items depending on their type are divided into the following categories: Group A: Meat Group B: Deli Group C: Pharmacy Group D: Seafood Group E: Beverage Group F: Canned Group G: Jarred Group H: Dry Food Group I: Dairy Group J: Bakery Group K: Personal Care Group L: Paper Goods Your store must have at least 3 items in each category. Your application as the first step needs to collect the following information before importing the items to the store: 1. The name of the product 2. The Category 3. The Company/Manufacturer name 4. The purchased price (What company has paid to buy this product) 5. The sale price (What customers will pay to buy this product) 6. The quantity of the purchased items 7. The date of the purchased items 8. The date of the production 9. The expiry date of the product 10. Store Code (a 4-digit number) 11. The currency of the country 12. Items will go on sale on different dates depending on their categories. Your application is responsible to use encryption method 1 for #1, and #3. (You have to define the suitable encryption method.) Your application is responsible to use encryption method 2 for #2. (You have to define the suitable encryption method.) Your application is responsible to use encryption method 3 for #4, and #5. (You have to define the suitable encryption method.) Your application is responsible to use encryption method 4 for #6. (You have to define the suitable encryption method.) Your application is responsible to use encryption method 5 for #7, #8, and #9. (You have to define the suitable encryption method.) Your application is responsible to use encryption method 6 for #10. (You have to define the suitable encryption method.) Your application is responsible to use encryption method 7 for #11. (You have to define the suitable encryption method.) The output of the encryptions will generate a number that will be known as the barcode of that specific item in this store. Before selecting and implementing your encryption methods, you have to answer the following questions: - Will all the generated barcodes have the same number of digits? - How should we deal with barcodes that have different numbers of digits? - Do you need to define decryption? - Is there any other questions, aspects, complications, simplifications, etc. that I need to think about in advance? Items will go on sale on different dates depending on their categories. Group A, B, C, and D follow the following rules: - Items will go on a 10% promotion when the date passes 50% of the durable life period - Yellow Tag - Items will go on a 25% promotion when the date passes 65% of the durable life period - Green Tag - Items will go on a 50% promotion when the date passes 75% of the durable life period - Red Tag - Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag and Final Sale (Bring Me Home Today!) - Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory Group E, F, G, and H follow the following rules: - Items will go on a 10% promotion when the date passes 60% of the durable life period - Yellow Tag - Items will go on a 25% promotion when the date passes 70% of the durable life period - Green Tag - Items will go on a 50% promotion when the date passes 80% of the durable life period - Red Tag - Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag and Final Sale (Bring Me Home Today!) - Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory Groups I, J, and K follow the following rules: - Items will go on a 10% promotion when the date passes 40% of the durable life period - Yellow Tag - Items will go on a 25% promotion when the date passes 50% of the durable life period - Green Tag - Items will go on a 50% promotion when the date passes 60% of the durable life period - Red Tag - Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag (Bring Me Home Today!) - Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory Group L follows the following rules: - Items will go on a 10% promotion when the date passes 70% of the durable life period - Yellow Tag - Items will go on a 25% promotion when the date passes 80% of the durable life period - Green Tag - Items will go on a 50% promotion when the date passes 90% of the durable life period - Red Tag - Items will go on a 95% promotion when the date passes 95% of the durable life period - Star Tag and Final Sale (Bring Me Home Today!) - Items with less than one day of their durable life period must be removed from the shelves and storage to be removed from the inventory The output of your program will be a printed receipt that shows a list of 12 items (one item from each category), 8 items with the regular price, and 4 items on sale that a customer bought also the customer has 3 items to return from three different categories. A receipt needs to include the following information on it: - The price of each item that has a regular price - If the price is reduced the reduction amount and sales percentage will be printed on the lines below the regular price; therefore the customer will see the regular price, the sales price, the reduced amount, and the sales percentage - Each item has a unique barcode - The date and the time of the purchase - The store number along with the address of the store - The final Balance - The payment method As per our discussion in class, your code needs to ask the following question from the user at the very beginning: "Would you like to import any item to your store?" The answer to this question is YES/NO. If YES, there will be 12 steps to collect the information related to that specific item being imported to the store to fill in and then, the program will proceed with the following steps. If No, 30 items (3*10, 3 items in each category) have already existed in our store and the program will proceed with the following steps. Memory management, allocating, and deallocating memory are one of the most important aspects to be considered in this project. Regarding the promotions tags available in different colors, your application must be able to generate a list of items with the proper color of the tag that depends on the percentage of the promotion. In order to submit your final version, you need to record a video, a maximum of 4 minutes. In this video, you need to explain the different parts of the code you have written, the functions, the pointers, memory allocation, memory management, and encryption methods, and if available the decryption methods must be explained verbally. The steps you are taking in explaining your written code must follow the steps, line by line, of your main function. This video should clarify the approaches you have taken along with the fulfillment of the requirements of this project.

Lv1
in Information Technology·
3 Apr 2023

No, it didn't work. 

gcc /tmp/xKjeKfOPT6.c -lm
/tmp/xKjeKfOPT6.c: In function 'main':
/tmp/xKjeKfOPT6.c:16:13: error: '________________________' undeclared (first use in this function)
   16 |  headPtr = (________________________ *) malloc(____________(struct my_rec));
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
/tmp/xKjeKfOPT6.c:16:13: note: each undeclared identifier is reported only once for each function it appears in
/tmp/xKjeKfOPT6.c:16:39: error: expected expression before ')' token
   16 |  headPtr = (________________________ *) malloc(____________(struct my_rec));
      |                                       ^
/tmp/xKjeKfOPT6.c:23:2: error: unknown type name '_________________'
   23 |  _________________ employeeID = 123456789;
      |  ^~~~~~~~~~~~~~~~~
/tmp/xKjeKfOPT6.c:24:26: error: '_______________________' undeclared (first use in this function)
   24 |  new_rec_ptr->next_rec = _______________________;
      |                          ^~~~~~~~~~~~~~~~~~~~~~~
/tmp/xKjeKfOPT6.c:28:27: error: '____________________' undeclared (first use in this function)
   28 |  new_rec_ptr->next_rec = (____________________ *) malloc(_______________(struct my_rec));
      |                           ^~~~~~~~~~~~~~~~~~~~
/tmp/xKjeKfOPT6.c:28:49: error: expected expression before ')' token
   28 |  new_rec_ptr->next_rec = (____________________ *) malloc(_______________(struct my_rec));
      |                                                 ^
/tmp/xKjeKfOPT6.c:29:2: error: '_________________________' undeclared (first use in this function)
   29 |  _________________________ = new_rec_ptr->next_rec;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/xKjeKfOPT6.c:41:6: error: '___________________' undeclared (first use in this function)
   41 |  p = ___________________;
      |      ^~~~~~~~~~~~~~~~~~~

Avatar image
mehdotstorm answered this question
Lv1
in Information Technology·
3 Apr 2023

Hi. Can you please make this code work?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>

typedef struct {
    char name[50];
    char category;
    char manufacturer[50]; // Change company to manufacturer
    float purchased_price;
    float sale_price;
    int quantity;
    time_t purchased_date;
    time_t production_date;
    time_t expiry_date;
    int store_code;
    char currency[4];
    long barcode;
} Item;

typedef struct {
    time_t purchase_time;
    Item *items;
    int item_count;
} Receipt;

// Caesar cipher encryption
void encrypt_caesar_cipher(char *input, int key, char *output) {
    int i = 0;
    while (input[i] != '\0') {
        char c = input[i];
        if (isalpha(c)) {
            char base = isupper(c) ? 'A' : 'a';
            output[i] = (c - base + key) % 26 + base;
        } else {
            output[i] = c;
        }
        i++;
    }
    output[i] = '\0';
}

// Caesar cipher decryption
void decrypt_caesar_cipher(char *input, int key, char *output) {
    encrypt_caesar_cipher(input, 26 - key, output);
}

// Function to generate a random item
Item create_random_item() {
    Item item;

    // Set a random item name
    char *names[] = {"Apple", "Banana", "Orange", "Pear", "Grapes", "Pineapple", "Watermelon", "Strawberry", "Mango", "Kiwi"};
    int name_index = rand() % 10;
    strcpy(item.name, names[name_index]);

    // Set a random item category
    char categories[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'};
    int category_index = rand() % 12;
    item.category = categories[category_index];

    // Set a random item manufacturer
    char *manufacturers[] = {"Apple Inc.", "Samsung", "Microsoft", "Google", "Amazon", "Sony", "Nike", "Adidas", "Puma", "Reebok"};
    int manufacturer_index = rand() % 10;
    strcpy(item.manufacturer, manufacturers[manufacturer_index]);

    // Set a random purchased price
    item.purchased_price = (float) (rand() % 100 + 1);

    // Set a random sale price
    item.sale_price = item.purchased_price * (1.0 + ((float) (rand() % 20 + 1) / 100.0));

    // Set a random quantity
    item.quantity = rand() % 10 + 1;

    // Set a random purchased date
    item.purchased_date = time(NULL) - (rand() % (30 * 24 * 60 * 60)); // up to 30 days ago

    // Set a random production date
    item.production_date = time(NULL) - (rand() % (365 * 24 * 60 * 60)); // up to 1 year ago

    // Set a random expiry date (between 1 and 3 years from the production date)
    item.expiry_date = item.production_date + ((rand() % 730) + 365) * 24 * 60 * 60;

    // Set a random store code
    item.store_code = rand() % 10000;

int main() {
    int bought_items[12] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
    float regular_price[12] = { 2.99, 4.99, 1.99, 3.49, 0.99, 1.49, 2.99, 3.99, 5.49, 4.49, 1.99, 2.49 };
    int promotion[12] = { 20, 10, 30, 15, 0, 5, 10, 20, 25, 15, 0, 5 };
    int returned_items[3] = { 5, 8, 11 };
    int encrypt_method[12] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5 };
    int i, j;
    float sale_price, total_price = 0.0;
    char barcode[7];

    // Generate barcodes for each item and print the receipt
    printf("Receipt:\n");

    for (i = 0; i < 12; i++) {
        // Encrypt the barcode using the appropriate encryption method
        switch (encrypt_method[i]) {
        case 1:
            sprintf(barcode, "ABC%d", bought_items[i]);
            break;
        case 2:
            sprintf(barcode, "DEF%d", bought_items[i]);
            break;
        case 3:
            sprintf(barcode, "GHI%d", bought_items[i]);
            break;
        case 4:
            sprintf(barcode, "JKL%d", bought_items[i]);
            break;
        case 5:
            sprintf(barcode, "MNO%d", bought_items[i]);
            break;
        case 6:
            sprintf(barcode, "PQR%d", bought_items[i]);
            break;
        case 7:
            sprintf(barcode, "STU%d", bought_items[i]);
            break;
        default:
            sprintf(barcode, "UNK%d", bought_items[i]);
            break;
        }

        // Calculate the sale price of the item based on the promotion percentage
        sale_price = regular_price[i] * (1 - promotion[i] / 100.0);

        // Check if the item is being returned
        for (j = 0; j < 3; j++) {
            if (bought_items[i] == returned_items[j]) {
                sale_price = 0.0;
                break;
            }
        }

        // Print the barcode and the sale price of the item
        printf("Item %d: %s - $%.2f\n", i+1, barcode, sale_price);

        // Add the sale price to the total price
        total_price += sale_price;
    }

    // Print the total price
    printf("Total price: $%.2f\n", total_price);

    return 0;
}

Avatar image
sadiqnav answered this question
Avatar image
sadiqnav answered this question
Lv1
in Information Technology·
3 Apr 2023

Heres the two codes together but am getting error again

main.c: In function ‘create_random_item’: main.c:84:69: warning: missing terminating " character 84 | char *currencies[] = {"USD", "EUR", "GBP", "JPY", "CAD", "AUD", " | ^ main.c:84:69: error: missing terminating " character main.c:91:1: error: expected expression before ‘typedef’ 91 | typedef struct { | ^~~~~~~ main.c:263:1: error: expected declaration or statement at end of input 263 | } | ^

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>

typedef struct {
    char name[100];
    char category;
    char manufacturer[100];
    char company[100];
    float purchased_price;
    float sale_price;
    int quantity;
    time_t purchased_date;
    time_t production_date;
    time_t expiry_date;
    unsigned long barcode;
    int store_code;
    char currency[4];
} Item;

typedef struct {
    time_t purchase_time;
    Item *items;
    int item_count;
} Receipt;

void encrypt_caesar_cipher(char *input, int key, char *output) {
    int i = 0;
    while (input[i] != '\0') {
        char c = input[i];
        if (isalpha(c)) {
            char base = isupper(c) ? 'A' : 'a';
            output[i] = (c - base + key) % 26 + base;
        } else {
            output[i] = c;
        }
        i++;
    }
    output[i] = '\0';
}

unsigned long generate_barcode(Item *item) {
    char encrypted_name[100], encrypted_company[100];
    encrypt_caesar_cipher(item->name, 3, encrypted_name);
    encrypt_caesar_cipher(item->company, 3, encrypted_company);

    unsigned long barcode = 0;
    for (int i = 0; encrypted_name[i] != '\0'; i++) {
        barcode += encrypted_name[i];
    }
    for (int i = 0; encrypted_company[i] != '\0'; i++) {
        barcode += encrypted_company[i];
    }

    return barcode;
}

Item create_random_item() {
    Item item;

    char *names[] = {"Apple", "Banana", "Orange", "Pear", "Grapes", "Pineapple", "Watermelon", "Strawberry", "Mango", "Kiwi"};
    int name_index = rand() % 10;
    strcpy(item.name, names[name_index]);

    char categories[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'};
    int category_index = rand() % 12;
    item.category = categories[category_index];

    char *manufacturers[] = {"Apple Inc.", "Samsung", "Microsoft", "Google", "Amazon", "Sony", "Nike", "Adidas", "Puma", "Reebok"};
    int manufacturer_index = rand() % 10;
    strcpy(item.manufacturer, manufacturers[manufacturer_index]);

    strcpy(item.company, "ABC Company");
    item.purchased_price = (float) (rand() % 100 + 1);
    item.sale_price = item.purchased_price * (1.0 + ((float) (rand() % 20 + 1) / 100.0));
    item.quantity = rand() % 10 + 1;
    item.purchased_date = time(NULL);
    item.production_date = item.purchased_date - (rand() % 60) * 24 * 60 * 60;  // 0-60 days before purchase
    item.expiry_date = item.production_date + (rand() % 180) * 24 * 60 * 60;  // 0-180 days after production
    item.store_code = rand() % 10000 + 1;

    char *currencies[] = {"USD", "EUR", "GBP", "JPY", "CAD", "AUD", "

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

typedef struct {
    char name[50];
    char category;
    char company[50];
    float purchased_price;
    float sale_price;
    int quantity;
    time_t purchased_date;
    time_t production_date;
    time_t expiry_date;
    int store_code;
    char currency[4];
    long barcode;
} Item;

typedef struct {
    time_t purchase_time;
    Item *items;
    int item_count;
} Receipt;

// Caesar cipher encryption
void encrypt_caesar_cipher(char *input, int key, char *output) {
    int i = 0;
    while (input[i] != '\0') {
        char c = input[i];
        if (isalpha(c)) {
            char base = isupper(c) ? 'A' : 'a';
            output[i] = (c - base + key) % 26 + base;
        } else {
            output[i] = c;
        }
        i++;
    }
    output[i] = '\0';
}

// Caesar cipher decryption
void decrypt_caesar_cipher(char *input, int key, char *output) {
    encrypt_caesar_cipher(input, 26 - key, output);
}
// Function to generate a random item
Item create_random_item() {
    Item item;
    int category_random = rand() % 12;

    // Assign random category
    if (category_random <= 3) {
        item.category = 'A';
    } else if (category_random <= 7) {
        item.category = 'B';
    } else if (category_random <= 10) {
        item.category = 'C';
    } else {
        item.category = 'D';
    }

    // Generate random values for item fields
    char *names[4] = {"apple", "banana", "chocolate", "water bottle"};
    strcpy(item.name, names[rand() % 4]);
    strcpy(item.company, "ABC Company");
    item.purchased_price = ((rand() % 100) + 1) / 10.0;
    item.sale_price = item.purchased_price;
    item.quantity = rand() % 10 + 1;
    item.purchased_date = time(NULL);
    item.production_date = item.purchased_date - (rand() % 60) * 24 * 60 * 60;  // 0-60 days before purchase
    item.expiry_date = item.production_date + (rand() % 180) * 24 * 60 * 60;  // 0-180 days after production
    item.store_code = rand() % 10000 + 1;
    strcpy(item.currency, "USD");
    item.barcode = generate_barcode(&item);

    return item;
}
// Define function to create a random item
Item create_random_item() {
    Item item;

    // Set a random item name
    char *names[] = {"Apple", "Banana", "Orange", "Pear", "Grapes", "Pineapple", "Watermelon", "Strawberry", "Mango", "Kiwi"};
    int name_index = rand() % 10;
    strcpy(item.name, names[name_index]);

    // Set a random item category
    char categories[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'};
    int category_index = rand() % 12;
    item.category = categories[category_index];

    // Set a random item manufacturer
    char *manufacturers[] = {"Apple Inc.", "Samsung", "Microsoft", "Google", "Amazon", "Sony", "Nike", "Adidas", "Puma", "Reebok"};
    int manufacturer_index = rand() % 10;
    strcpy(item.manufacturer, manufacturers[manufacturer_index]);

    // Set a random purchased price
    item.purchased_price = (float) (rand() % 100 + 1);

    // Set a random sale price
    item.sale_price = item.purchased_price * (1.0 + ((float) (rand() % 20 + 1) / 100.0));

    // Set a random quantity
    item.quantity = rand() % 10 + 1;

    // Set a random purchased date
    item.purchased_date = time(NULL) - (rand() % (30 * 24 * 60 * 60)); // up to 30 days ago

    // Set a random production date
    item.production_date = time(NULL) - (rand() % (365 * 24 * 60 * 60)); // up to 1 year ago

    // Set a random expiry date (between 1 and 3 years from the production date)
    item.expiry_date = item.production_date + ((rand() % 730) + 365) * 24 * 60 * 60;

    // Set a random store code
    item.store_code = rand() % 10000;

    // Set a random currency
    char *currencies[] = {"USD", "EUR", "GBP", "JPY", "CAD", "AUD", "CHF", "CNY"};
    int currency_index = rand() % 8;
    strcpy(item.currency, currencies[currency_index]);

    // Set a random barcode
    item.barcode = generate_barcode(&item);

    return item;
}
void encrypt_caesar_cipher(char *input, int key, char *output) {
    int i = 0;
    while (input[i] != '\0') {
        char c = input[i];
        if (isalpha(c)) {
            char base = isupper(c) ? 'A' : 'a';
            output[i] = (c - base + key) % 26 + base;
        } else {
            output[i] = c;
        }
        i++;
    }
    output[i] = '\0';
}

unsigned long generate_barcode(Item *item) {
    // Encrypt the required fields
    char encrypted_name[100], encrypted_company[100];
    encrypt_caesar_cipher(item->name, 3, encrypted_name);
    encrypt_caesar_cipher(item->company, 3, encrypted_company);

    // Combine the encrypted information to generate a barcode (just as an example, not an actual barcode)
    unsigned long barcode = 0;
    for (int i = 0; encrypted_name[i] != '\0'; i++) {
        barcode += encrypted_name[i];
    }
    for (int i = 0; encrypted_company[i] != '\0'; i++) {
        barcode += encrypted_company[i];
    }

    return barcode;
}
void generate_receipt(Item* items, int num_items) {
    Receipt receipt;
    receipt.purchase_time = time(NULL);
    receipt.items = items;
    receipt.item_count = num_items;
    print_receipt(&receipt);
}

int main() {
    srand(time(NULL));
    int num_items = 5;
    Item items[num_items];
    for (int i = 0; i < num_items; i++) {
        items[i] = create_random_item();
        apply_discounts(&items[i], time(NULL));
    }
    generate_receipt(items, num_items);
    return 0;
}


Start filling in the gaps now
Log in