Answer to Question #111527 in C for sara

Question #111527
Perform this in C language
Q1. Create a struct called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four data members—a part number (type string), a part description (type string), a quantity of the item being purchased (type int) and a price per item (type float). Your program should initialize the four data members. In addition, it should calculate the invoice amount (i.e., multiplies the quantity by the price per item), If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a test program that demonstrates struct Invoice’s capabilities. Note: Perform this work using 1. 2d array 2. pointer to 2d arrays 3. design function for calculating the results by passing array to function by value and by reference.
Expert's answer
1
Expert's answer
2020-04-30T13:37:15-0400
#include <stdio.h>

struct invoice {
    char partNumber[25];
    char partDescription[25];
    int itemQuantity;
    float itemPrice;
};

float invoice_amount(int quantity, float price) {
    if (quantity < 0) { quantity = 0; }
    return quantity * price;
}

int main() {
    struct invoice Invoice1 = {"ed34", "Screw Guage", 2, 30};
    struct invoice Invoice2 = {"e322", "Screws", 10, 3};
    printf("Invoice1's initial part number is: %s,"
           "\npart description is: %s, "
           "\nquantity per item is: %d, "
           "\nprice per item is: %f, "
           "\ninvoice amount: %f ",
           Invoice1.partNumber,
           Invoice1.partDescription,
           Invoice1.itemQuantity,
           Invoice1.itemPrice,
           invoice_amount(Invoice1.itemQuantity, Invoice1.itemPrice));

    printf("\n\nInvoice2's initial part number is: %s,"
           "\npart description is: %s, "
           "\nquantity per item is: %d, "
           "\nprice per item is: %f, "
           "\ninvoice amount: %f ",
           Invoice2.partNumber,
           Invoice2.partDescription,
           Invoice2.itemQuantity,
           Invoice2.itemPrice,
           invoice_amount(Invoice2.itemQuantity, Invoice2.itemPrice));
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

sara
29.04.20, 10:30

Convert this code in C language.

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS