Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program for a shopping list. Use the listed items and add one addition

ID: 3784686 • Letter: W

Question

Write a C program for a shopping list. Use the listed items and add one additional item to the list. . Code should be nicely indented and commented. All the field values should be in variables although an array does not have to be used. The Item Num should be a number, not a string The extended price should be calculated in a formula with multiplication right while printing it out. It should not be stored as a variable. Create a simple Makefile to compile your program into an executable called shopping. You should submit the source code, your Makefile and a screenshot of the output file compressed into a zip file named FirstNameLastNameL1.zip. The screenshot should be named with your name as well. The Makefile should be called Makefile with no extension. I should be able to type make at the command line to compile your program. Do not include any other files or folders in the zipfile.

Item Num Description Price Count Extended Price

000345 Bookshelf $ 78.50 4 $ 314.00

007474 Pen $ 2.99 100 $ 299.00

000987 Chair $ 129.99 6 $ 779.94

002342 Camera $ 1295.40 3 $ 3886.20

Explanation / Answer

PROGRAM CODE:

#include <stdio.h>
#include<string.h>
#include <stdlib.h>
struct ShoppingList
{
   int itemNum;
   char description[40];
   double price;
   int count;
   double extendedPrice;
};

int main(void) {
   struct ShoppingList list[5];
   //Item Num 1
   list[0].itemNum = 345;
   strcpy(list[0].description, "Bookshelf");
   list[0].price = 78.50;
   list[0].count = 4;
   //Item num 2
   list[1].itemNum = 7474;
   strcpy(list[1].description ,"Pen");
   list[1].price = 2.99;
   list[1].count = 100;
   //Item num 3
   list[2].itemNum = 987;
   strcpy(list[2].description,"Chair");
   list[2].price = 129.99;
   list[2].count = 6;
   //Item num 4
   list[3].itemNum = 2342;
   strcpy(list[3].description ,"Camera");
   list[3].price = 1295.40;
   list[3].count = 3;
   //Item num 5
   list[4].itemNum = 2731;
   strcpy(list[4].description, "Table");
   list[4].price = 185.40;
   list[4].count = 2;
   printf("Item Num Description Price Count Extended Price ");
   for(int i=0; i<5; i++)
   {
       int counter = 0;
       char buffer[7];
       snprintf(buffer, 10, "%d", list[i].itemNum);
       counter = strlen(buffer);
       char zeros[7] = "";
       while(counter<6)
       {
           strcat(zeros,"0");
           counter++;
       }
       printf("%s%d %s $%.2f %d $%.2f ",zeros,list[i].itemNum, list[i].description,list[i].price,
       list[i].count, list[i].price*list[i].count);
   }
   return 0;
}

OUTPUT:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote