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

My current code, please use. start #include <stdio.h> #include <stdlib.h> #inclu

ID: 3815617 • Letter: M

Question

My current code, please use.

start

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

typedef struct MobileStore
{
char brand[50];
char model[50];
char color[50];
int memory;
float price;
float emi;
int stock;
struct MobileStore *next;
} mobile;
struct MobileStore *first=NULL,*last=NULL,*k;
void printSingleMobile();

void clearBuffer(char c)
{
while(c != ' ')
{
scanf("%c", &c);
}
}
char getMenuOption()
{
char o;

printf(" MENU ");
printf(" Enter C for creating database");
printf(" Enter A for Add new mobile info");
printf(" Enter S for searching a Single mobile info");
printf(" Enter V for view all mobiles in store");
printf(" Enter D for delete a mobile in store");
printf(" Enter X for exit!");
printf(" Enter the choice:");
scanf("%c",&o);
clearBuffer(o);
return o;
}

void createdatabase(unsigned int n)
{
int i = 1;
first=(struct MobileStore*)malloc(sizeof(struct MobileStore));
printf(" Enter the mobile 1 info: ");
printf("Brand : ");
scanf("%s", first->brand);
printf("Model : ");
scanf("%s", first->model);
printf("color : ");
scanf("%s", first->color);
printf("memory : ");
scanf("%d", &first->memory);
printf("price : ");
scanf("%f", &first->price);
printf("EMI : ");
scanf("%f", &first->emi);
printf("stock : ");
scanf("%d", &first->stock);
first->next=NULL;
last=first;
for(i=2; i <= n ; i++)
{
k=(struct MobileStore*)malloc(sizeof(struct MobileStore));
printf(" Enter the mobile info: ");
printf("Brand : ");
scanf("%s",k->brand);
printf("Model : ");
scanf("%s",k->model);
printf("color : ");
scanf("%s",k->color);
printf("memory : ");
scanf("%d", &k->memory);
printf("price : ");
scanf("%f", &k->price);
printf("EMI : ");
scanf("%f", &k->emi);
printf("stock : ");
scanf("%d", &k->stock);
k->next=NULL;
last->next=k;
last=k;
}
}
void printMobileInfo()
{
struct MobileStore *t;
t=first;
while(t!=NULL)
{
printf(" Brand :%s",t->brand);
printf(" Model :%s",t->model);
printf(" Color :%s",t->color);
printf(" Memory :%d", t->memory);
printf(" Price:%f",t->price);
printf(" EMI:%f",t->emi);
printf(" Stock:%d ",t->stock);
t=t->next;
}
printf(" Press enter to continue..");
}
void addNewMobile()
{
char r[10];
int flag=0;
printf(" Enter new mobile model:");
scanf("%s",r);
struct MobileStore *t;
t=first;
while(t!=NULL)
{
if(strcmp(r,t->model)==0)
{
k=(struct MobileStore*)malloc(sizeof(struct MobileStore));
printf("Brand : ");
scanf("%s",k->brand);
printf("Model : ");
scanf("%s",k->model);
printf("color : ");
scanf("%s",k->color);
printf("memory : ");
scanf("%d", &k->memory);
printf("price : ");
scanf("%f", &k->price);
printf("EMI : ");
scanf("%f", &k->emi);
printf("stock : ");
scanf("%d", &k->stock);
k->next=t->next;
t->next=k;
flag=1;
break;
}
t=t->next;
}
if(flag==0)
printf(" The element not found!!!");
}
void del()
{
struct MobileStore *back,*k;
char r[10];
int flag=0;
printf(" Enter the model name to delete:");
scanf("%s",r);
if(strcmp(r,first->model)==0)
{
first=first->next;
flag=1;
}
else
{
back=first;
k=first->next;
while(k!=NULL)
{
if(strcmp(r,k->model)==0)
{
back->next=k->next;
flag=1;
break;
}
}
}
if(flag==0)
printf(" The element not found!!!");
}
void printSingleMobile()
{
char r[10];
int flag=0;
printf(" Enter the model number to search:");
scanf("%s",r);
struct MobileStore *t;
t=first;
while(t!=NULL)
{
if(strcmp(r,t->model)==0)
{
printf(" The model number found in the list!!! brand name is %s",t->brand);
printf("model name is %s",t->model);
printf("color is %s",t->color);
printf("memory size is %d", t->memory);
printf("Price is %f",t->price);
printf("EMI is %f",t->emi);
printf("Stock available is %d",t->stock);
flag=1;
break;
}
t=t->next;
}
if(flag==0)
printf(" The model number not in database!!");
}
int main()
{
char ch;
while (1)
{
ch = getMenuOption();
unsigned int n = 0;
switch(ch)
{
case 'C':
printf(" Enter the number of mobiles you want to enter:");
scanf("%d",&n);
createdatabase(n);
clearBuffer(ch);
break;
case 'V':
printMobileInfo();
clearBuffer(ch);
break;
case 'A':
addNewMobile();
clearBuffer(ch);
break;
case 'D':
del();
clearBuffer(ch);
break;
case 'S':
printSingleMobile();
clearBuffer(ch);
break;
case 'X':
exit(0);
break;
default:
printf(" You have entered a wrong choice!!!");
}
}
getchar();
}

void print Mobilelnfo( mobile head); Print the contents of the created linked list to the screen. If you choose to print the mobile information without creating data, there should to be an error message saying "Database is empty mobile addNewMobilel mobile *head); In this function, the user is prompted for specifications of a new phone and data provided about the new phone should to be inserted in the linked list. void printSingleMobile(mobile *head); In this function, user should be prompted to enter a model of the phone. Then the details of the phone with that single model has to be printed to the screen. void free Database( mobile head), This function should free or empty all the dynamic memory allocated during this program This function also should exit the program Note: You may change the names of the function and its parameters. An example illustrating interaction with the program follows Mobile Database System C Create the database A Add new mobile info S Search Single mobile info V View all mobiles in store X Exit Enter choice: C Enter the number of mobiles data you want to enter: 2 Enter the mobile 1 info Brand: Apple Mode iphones Color: gold Memory: 32 Price: 450 EMI: 17.89 Stock: 5 Enter the mobile 2 info Brand: LG Model: G5 black Color Memory: 64 Price: 400 EMI: 12.65 Stock 4 Database is created.

Explanation / Answer

NOTE : Your logic for del() and addNewMobile method was wrong. So I corrected it. It works perfectly fine now

#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <string.h>

typedef struct MobileStore
{
    char brand[50];
    char model[50];
    char color[50];
    int memory;
    float price;
    float emi;
    int stock;
    struct MobileStore *next;
} mobile;
struct MobileStore *first=NULL,*last=NULL,*k;
void printSingleMobile();

void clearBuffer(char c)
{
    while(c != ' ')
    {
        scanf("%c", &c);
    }
}
char getMenuOption()
{
    char o;

    printf(" MENU ");
    printf(" Enter C for creating database");
    printf(" Enter A for Add new mobile info");
    printf(" Enter S for searching a Single mobile info");
    printf(" Enter V for view all mobiles in store");
    printf(" Enter D for delete a mobile in store");
    printf(" Enter X for exit!");
    printf(" Enter the choice:");
    scanf("%c",&o);
    clearBuffer(o);
    return o;
}

void createdatabase(unsigned int n)
{
    int i = 1;
    first=(struct MobileStore*)malloc(sizeof(struct MobileStore));
    printf(" Enter the mobile 1 info: ");
    printf("Brand : ");
    scanf("%s", first->brand);
    printf("Model : ");
    scanf("%s", first->model);
    printf("color : ");
    scanf("%s", first->color);
    printf("memory : ");
    scanf("%d", &first->memory);
    printf("price : ");
    scanf("%f", &first->price);
    printf("EMI : ");
    scanf("%f", &first->emi);
    printf("stock : ");
    scanf("%d", &first->stock);
    first->next=NULL;
    last=first;
    for(i=2; i <= n ; i++)
    {
        k=(struct MobileStore*)malloc(sizeof(struct MobileStore));
        printf(" Enter the mobile info: ");
        printf("Brand : ");
        scanf("%s",k->brand);
        printf("Model : ");
        scanf("%s",k->model);
        printf("color : ");
        scanf("%s",k->color);
        printf("memory : ");
        scanf("%d", &k->memory);
        printf("price : ");
        scanf("%f", &k->price);
        printf("EMI : ");
        scanf("%f", &k->emi);
        printf("stock : ");
        scanf("%d", &k->stock);
        k->next=NULL;
        last->next=k;
        last=k;
    }
}
void printMobileInfo()
{
    struct MobileStore *t;
    t=first;
    while(t!=NULL)
    {
        printf(" Brand :%s",t->brand);
        printf(" Model :%s",t->model);
        printf(" Color :%s",t->color);
        printf(" Memory :%d", t->memory);
        printf(" Price:%f",t->price);
        printf(" EMI:%f",t->emi);
        printf(" Stock:%d ",t->stock);
        t=t->next;
    }
    printf(" Press enter to continue..");
}
void addNewMobile()
{
    char r[10];
    printf(" Enter new mobile model:");
    scanf("%s",r);
    struct MobileStore *t;
    t=first;
    while(t!=NULL)
    {
        if(strcmp(r,t->model)==0)
        {
       printf(" Mobile Already Exists!!!");
       return;
        }
       if (t->next == NULL)
       break;  
        t=t->next;
    }
   k=(struct MobileStore*)malloc(sizeof(struct MobileStore));
   printf("Brand : ");
   scanf("%s",k->brand);
   printf("Model : ");
   scanf("%s",k->model);
   printf("color : ");
   scanf("%s",k->color);
   printf("memory : ");
   scanf("%d", &k->memory);
   printf("price : ");
   scanf("%f", &k->price);
   printf("EMI : ");
   scanf("%f", &k->emi);
   printf("stock : ");
   scanf("%d", &k->stock);
   t->next=k;
}
void del()
{
    struct MobileStore *back,*k;
    char r[10];
    int flag=0;
    printf(" Enter the model name to delete:");
    scanf("%s",r);
    if(strcmp(r,first->model)==0)
    {
        first=first->next;
        flag=1;
    }
    else
    {
        back=first;
        k=first->next;
        while(k!=NULL)
        {
       if(strcmp(r,k->model)==0)
       {
            back->next=k->next;
            flag=1;
            break;
       }
       back = k;
          k = k->next;
        }
    }
    if(flag==0)
        printf(" The element not found!!!");
}

void printSingleMobile()
{
    char r[10];
    int flag=0;
    printf(" Enter the model number to search:");
    scanf("%s",r);
    struct MobileStore *t;
    t=first;
    while(t!=NULL)
    {
        if(strcmp(r,t->model)==0)
        {
       printf(" The model number found in the list!!! brand name is %s ",t->brand);
       printf("model name is %s ",t->model);
       printf("color is %s ",t->color);
       printf("memory size is %d ", t->memory);
       printf("Price is %f ",t->price);
       printf("EMI is %f ",t->emi);
       printf("Stock available is %d ",t->stock);
       flag=1;
       break;
        }
        t=t->next;
    }
    if(flag==0)
        printf(" The model number not in database!!");
}
int main()
{
    char ch;
    while (1)
    {
        ch = getMenuOption();
        unsigned int n = 0;
        switch(ch)
        {
        case 'C':
       printf(" Enter the number of mobiles you want to enter:");
       scanf("%d",&n);
       createdatabase(n);
       clearBuffer(ch);
       break;
        case 'V':
       printMobileInfo();
       clearBuffer(ch);
       break;
        case 'A':
       addNewMobile();
       clearBuffer(ch);
       break;
        case 'D':
       del();
       clearBuffer(ch);
       break;
        case 'S':
       printSingleMobile();
       clearBuffer(ch);
       break;
        case 'X':
       exit(0);
       break;
        default:
       printf(" You have entered a wrong choice!!!");
        }
    }
    getchar();
}

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