Skip to main content

Zoho Interview Round three ( inventory stock list )

1) To form a structure which has few elements:
struct product {
   char productname[20];
   int product_price;
   int product_id;
}
Get the product name, price and id and display the product name and price in descending of the price.
2) For the same above structure, now add another structure which is the category. That category will have products in it.
Struct category
{
   char category_name[20];
   int cat_id;
} 
According the category get the product name, product price and id, then display all the products category wise in descending order.
3) For the same structure which as category and product, get the category id from the user in the product structure and save to the category list. Then display them all in category wise.

4) A sheet full of data will be given with inventory stock list, which as different categories and different products as input with category capacity and product availability in the structure. Now we need to add a new category or new product with capacity and availability. Need to check whether the product availability is exceeding the category capacity, if yes the output rack is full or else tell how much free space is available and add the product to list.



My Solution :::

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define N 4
#define M 3

int availableCategory = 0;

struct Product{
 char product_name[20];
 int product_price;
 int product_id;
 int isallocated;

};

struct Category{
 char category_name[20];
 char category_id;
 struct Product product[N];
 int isallocated;
 int number_of_product;
};
void insertCategory(struct Category *);
void insertProduct(struct Product *);
void swapProduct(struct Product *, struct Product *);
void swapCategory(struct Category *, struct Category *);
void sortProduct(struct Product [N]);
void sortCategory(struct Category [M]);
void displayAllProduct(struct Product [N]);
void displayProduct(struct Product);
void displayCategory(struct Category);
void displayAllCategory(struct Category [M]);
int find(struct Category *, int);
void search();

void search(struct Category *root){
int id;
printf("\n\n Enter the Category ID:");
scanf("%d",&id);
if(find(root,id) != -1)
 displayCategory(root[find(root,id)]);
else
 printf("\n\n\t\tOops ...! Not Found");

}

void insertProduct(struct Product *newnode){
printf("\n\n\t\tEnter the Product Name :: ");
 scanf(" %s",newnode->product_name);
printf("\n\n\t\tEnter the Product ID :: ");
 scanf(" %d",&newnode->product_id);
printf("\n\n\t\tEnter the Product Price :: ");
 scanf(" %d",&newnode->product_price);
}


void insertCategory(struct Category *newnode){
  int id,i;

  printf("\n\n Enter the Category ID:");
 scanf("%d",&id);
  if( ( i = find(newnode,id) ) != -1){
 if(newnode[i].number_of_product > N){
  printf("\n\n\t\tNo More Capacity for Category");
  return;
 }
 insertProduct(&newnode[i].product[newnode[i].number_of_product]);
 newnode[i].number_of_product++;
  }

  else{
 if(availableCategory > M){
  printf("\n\n\t\tNo More Capacity for Category");
  return;
 }
 i = availableCategory;
 newnode[i].category_id=id;
 printf("\n\n Enter the Category Name :: ");
  scanf("%s",newnode[i].category_name);
 insertProduct(&newnode[i].product[newnode[i].number_of_product]);
 newnode[i].number_of_product++;
 availableCategory++;
  }


}

int find(struct Category *node,int id){
 int i;
 for(i=0;i<M;i++)
  if(node[i].category_id == id)
   return i;

return -1;
}

void swapProduct(struct Product *a, struct Product *b){
 struct Product *temp;
 memcpy(temp, a, sizeof(struct Product));
 memcpy(a, b, sizeof(struct Product));
 memcpy(b, temp, sizeof(struct Product));
}

void swapCategory(struct Category *a, struct Category *b){
 struct Category *temp;
 memcpy(temp, a, sizeof(struct Category));
 memcpy(a, b, sizeof(struct Category));
 memcpy(b, temp, sizeof(struct Category));
}

void sortProduct(struct Product node[N]){
 int i,j;
 for(j=0;j<N;j++)
    for(i=j;i<N;i++)
      if(node[i].product_id && node[j].product_id)
  if(node[j].product_price < node[i].product_price)
   swapProduct(&node[j],&node[i]);
}

void sortCategory(struct Category node[M]){
 int i,j;
 for(i=0;i<N;i++)
     sortProduct(node[i].product);
 for(j=0;j<M;j++)
    for(i=j;i<M;i++)
  if(strcmp(node[j].category_name, node[i].category_name) > 0)
   swapCategory(&node[j],&node[i]);

}



void displayAllProduct(struct Product node[N]){
int i;
 for(i=0;i<N;i++)
  if(node[i].product_id)
   displayProduct(node[i]);
}

void displayProduct(struct Product node){
printf("\n*********************************");
printf("\n\nProduct Name :: %s",node.product_name);
printf("\nProduct Price  :: %d",node.product_price);
printf("\nProduct ID     :: %d",node.product_id);
printf("\n\n*******************************");
getch();
}

void displayCategory(struct Category node){
printf("\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
printf("\n\nCategory Name :: %s",node.category_name);
printf("\nCategory ID     :: %d",node.category_id);
displayAllProduct(node.product);
printf("\n\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
getch();
}

void displayAllCategory(struct Category node[M]){
int i;
 for(i=0;i<M;i++)
  displayCategory(node[i]);
}



int main(){
int ch;
struct Category root[M];
clrscr();
do{
 printf("\n\n 1.Insert Product\n\n 2.Search Category ID\n\n 3.Display All Category\n\n 4.Exit (Enter -ve number)");
 printf("\n\n\n\t\tEnter your Choice :: ");
  scanf("%d",&ch);
 switch(ch){
  case 1:
   insertCategory(root);
   sortCategory(root);
   break;
  case 2:
   search(root);
   break;
  case 3:
   displayAllCategory(root);
   break;
  case 4:
   return 0;
  default:
   printf("Ooops ... Entered choice is wrong ...!");
   getch();
   return 0;

 }

}while(1);

getch();
return 0;
}



Comments

Popular posts from this blog

ORACLE 9i practice solutions

Created by BCL easyConverter SDK 3 (HTML Version)

Zoho Puzzle Questions With Answers

Measuring Time Logic Puzzle You are given with two ropes with variable width. However if we start burning both the ropes, they will burn at exactly same time i.e. an hour. The ropes are non-homogeneous in nature. You are asked to measure 45 minutes by using these two ropes.

How can you do it?

Please note that you can’t break the rope in half as it is being clearly stated that the ropes are non-homogeneous in nature.
Answer & Explanation Solution: 45 minutes

Explanation :
All you have to do is burn the first rope from both the ends and the second rope from one end only simultaneously. The first rope will burn in 30 minutes (half of an hour since we burned from both sides) while the other rope would have burnt half. At this moment, light the second rope from the other end as well. Where, the second rope would have taken half an hour more to burn completely, it will take just 15 minutes as we have lit it from the other end too.

Thus you have successfully calculated 30+15 = 45 minutes …

Hackerrank > SQL > Basic Select

Select
01-Select All
Given a City table, whose fields are described as +-------------+----------+ | Field       | Type     | +-------------+----------+ | ID          | int(11)  | | Name        | char(35) | | CountryCode | char(3)  | | District    | char(20) | | Population  | int(11)  | +-------------+----------+
write a query that will fetch all columns for every row in the table.

My Solution
SELECT*FROM city;
---------------------------------------------------------------------------------
02-Select by ID
Given a City table, whose fields are described as