### 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

}

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)");
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;
}
```

### C Questions

C Questions
C Questions

Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:

void main()
{
int const * p=5; printf("%d",++(*p));
}
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
main()
{
char s[ ]="man"; int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
aaaa nnnn
Explanation

### Zoho Interview | Set 1 (Advanced Programming Round)

Third Round: (Advanced Programming Round) Here they asked us to create a “Railway reservation system” and gave us 4 modules. The modules were:
1. Booking
2. Availability checking
3. Cancellation
4. Prepare chart
We were asked to create the modules for representing each data first and to continue with the implementation phase.

My Solution :