Question

In: Computer Science

I need write a small "c" program that has locations of items on a shelving unit....

I need write a small "c" program that has locations of items on a shelving unit. Im not familiar with this language. Can you guys give me some hint so I could start writing one or as example. This is my first time learning programming C.

Specifically, your program should:

  • Contain a struct representing an item on the shelf. It needs only contain the item's name and price.
  • Ask the user for the number of shelves in the unit, and the number of "slots" available on each shelf which can hold items.
  • From the above, build a two dimensional array of item structs. The array represents locations on the shelving unit (rows = shelves, columns = slots on the shelves).
  • Allow the user to add items to the shelves by giving the name, price, and location by reading input in the format: <name>, <price>, <shelf>, <slot>
  • Allow the user to indicate they are done adding items. At this point the user should be able to enter the coordinate of an item in the shelving unit and the program should print out the information about the selected item (or some message if that slot is empty).

Solutions

Expert Solution

Solution(Code):

#include<stdio.h>
#include<string.h>
struct item
{
   char name[20];
   int price;
};
int main()
{
   int nsl,ns,i,j,price,shelf,slot;
   char choice,name[20],dummy;
  
   printf("Enter number of shelves in the unit:");
   scanf("%d",&ns);
   printf("Enter number of slots for each shelf:");
   scanf("%d",&nsl);
   struct item items[ns][nsl];  
  
   for(i=0;i<ns;i++)
   {
       for(j=0;j<nsl;j++){
           strcpy(items[i][j].name,"");
           items[i][j].price=-1;
       }
   }
   printf("Enter -1 for name to stop adding items\n");
   while(1)
   {
       scanf("%s%d%d%d",name,&price,&shelf,&slot);
       scanf("%c",&dummy);
       if(strcmp(name,"-1")==0)
           break;
       strcpy(items[shelf-1][slot-1].name,name);
       items[shelf-1][slot-1].price=price;      
   }
   printf("Enter the co-ordinate of an item in the shelving unit:");
   scanf("%d%d",&shelf,&slot);
   if(items[shelf-1][slot-1].price!=-1)
       printf("Item details\nItem name:%s\nItem price:%d\n",items[shelf-1][slot-1].name,items[shelf-1][slot-1].price);
   else
       printf("Empty slot\n");

   return 0;
}

Output:


Related Solutions

I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
I need to write a C++ program that appends "not" into the string without using the...
I need to write a C++ program that appends "not" into the string without using the append method or any standard libraries. It should return the string if there isn't an "is" in it. Examples: is is = is not is not This is me = This is not me What is yellow? = What is not yellow? The sky is pink = The sky is not pink isis = isis What happened to you? = What happened to you?
I need to write a program in C with the following specification * ​​​​​​​Line one of...
I need to write a program in C with the following specification * ​​​​​​​Line one of the standard input will have the total number of people which must not be greater than 10 * Each of the subsequent lines of input will be the first name of a person and their number (ex. "Adam 85") one space between name and number * Each name must be a maximum of 14 characters * Put the first names into an array called...
Write a C++ program: The local taqueria has decided they need to raise their prices. In...
Write a C++ program: The local taqueria has decided they need to raise their prices. In order to soften the blow to their customers, they also want to rename all their burritos to make them sound more desirable. Your program should create two arrays in main() - one string array with 3 burrito types and one float array with 3 associated prices, defined below: string names[] = {"Carnitas", "Pollo", "Veggie"}; float prices[] = {6.95, 6.25, 5.95}; Now, main should declare...
For this assignment, I need to write a c program named stick which plays a matchstick-picking...
For this assignment, I need to write a c program named stick which plays a matchstick-picking game. Given an initial number of sticks, players take turns picking either 1, 2, 3 or 4 sticks from a pile. Whoever picks the last stick wins. Usage The user can run stick with or without command line arguments. i.e. somebody can enter the number of sticks to begin play when the program is launched or they can be prompted after the program begins...
For this assignment, I need to write a c program named stick which plays a matchstick-picking...
For this assignment, I need to write a c program named stick which plays a matchstick-picking game. Given an initial number of sticks, players take turns picking either 1, 2, 3 or 4 sticks from a pile. Whoever picks the last stick wins. Usage You run stick with or without command line arguments. i.e. somebody can enter the number of sticks to begin play when the program is launched or they can be prompted after the program begins running. Print...
For this assignment, I need to write a c program named stick which plays a matchstick-picking...
For this assignment, I need to write a c program named stick which plays a matchstick-picking game. Given an initial number of sticks, players take turns picking either 1, 2, 3 or 4 sticks from a pile. Whoever picks the last stick wins. Usage You run stick with or without command line arguments. i.e. somebody can enter the number of sticks to begin play when the program is launched or they can be prompted after the program begins running. Print...
A company has two retail locations that carry 12000 and 16000 items respectively. The average unit...
A company has two retail locations that carry 12000 and 16000 items respectively. The average unit costs $1.15 . What is the approximate total value (across both warehouses) of the most valuable 20% of the items.
Write a C++ die roller program. We need you to write a program that will roll...
Write a C++ die roller program. We need you to write a program that will roll dice for them, but not just six-sided dice. Your program needs to be able to take an input in for form nDx or ndx where the d is the letter d or D. n may or not be present. If it is, it represents the number of dice. If not, assume it is a 1. x may or may not be present. If it...
I need to write a program in python for a restaurant. The program should let the...
I need to write a program in python for a restaurant. The program should let the user enter a meal number, then it should display the meal name, meal price, and meal calories. Also, needs the appropriate output if the user enters an invalid meal number. I am supposed to use a dictionary, but my problem is it keeps giving me an error and telling me my menu is not defined. Not sure what I am doing wrong. print ("Welcome...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT