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...
i need C++ program with possible comments what is going on,(a) Write a program that reads...
i need C++ program with possible comments what is going on,(a) Write a program that reads a char as input, and determines if it is a lowercase letter, uppercase letter, a digit or something else (call the last one a special character).
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.
Hello I need a small fix in my program. I need to display the youngest student...
Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...
I need to write this program in Python. Write a program that displays a temperature conversion...
I need to write this program in Python. Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The tabular format of the result should include rows for all temperatures between 70 and 270 degrees Celsius that are multiples of 10 degrees Celsius (check the sample below). Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit is as follow F=(9/5C) +32 Celsius Fahrenheit 70 158 80 176 90...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT