Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Sample C codes.Need Solutions

+1 vote
asked Jan 11, 2019 by anonymous

Hi.I need the solution of this questions for my final exams,thanks for your help!

1-Construct a list of 20 items of an record(string and number).Sort records according to the string letter order.(A-Z)

2-In a restaurant the waiter takes notes for the ordered things,which consist of meal id and table.(Link List).Add sequential clients and remove them when they leave.

3-In the problem 2 if three guests are ordered meals and in the meantime the one and third are eating second is leaving.Correct the list with the new situation.

4-A computer sw that stores every new entry word but lists after the third entrance.

5-Write a code that makes 4 arithmetic operations.(with function pointers that takes +,-,*,/)

2 Answers

0 votes
answered Jan 11, 2019 by sefayildiz (140 points)

The first question´s answer:

#include <stdio.h>

#include <string.h>

int main (void) {

   char string[20]; // But that can given another format : string[]="msyildiz" and dont use scanf

   char temp;

   printf("Input text:");

   scanf("%s",string);

   int i, j;

   int n = strlen(string);

   printf("String before sorting - %s \n", string);

   for (i = 0; i < n-1; i++) {

      for (j = i+1; j < n; j++) {

         if (string[i] > string[j]) {

            temp = string[i];

            string[i] = string[j];

            string[j] = temp;

         }

      }

   }

   

   printf("String after sorting  - %s \n", string);

   return 0;

}

OUTPUT : 

Input text:msyildiz
String before sorting - msyildiz
String after sorting  - diilmsyz

If you can not do other questions contact me

commented Jan 12, 2019 by anonymous
I am beginner,i need your helps also in other ones thank you :)
0 votes
answered Jan 17, 2019 by Jyothi_Rk
Ans for 2nd Question.

#include <stdio.h>
#include <stdlib.h>
struct node
{
    int meal_Id;
    int Table_No;
    struct node *nxt;
};
typedef struct node Node;
Node *start=NULL;

void addfirst(int table)
{
  int mid;
  Node *client = (Node *)malloc(sizeof(Node));
  start=client;
  printf("enter mealid\n");
  scanf("%d",&mid);
  client ->meal_Id = mid;
  client ->Table_No = table;
  client ->nxt =NULL;
  
}
void add(int table)
{
  Node *client = (Node *)malloc(sizeof(Node));
  Node *ptr;
  int mid;
  for(ptr=start;ptr->nxt != NULL;ptr=ptr->nxt);
  ptr->nxt =client;
  printf("enter mealid\n");
  scanf("%d",&mid);
  client ->meal_Id = mid;
  client ->Table_No = table;
  client ->nxt =NULL;
}

void dlt(int table)
{
    Node *ptr;
    Node *temp;
    if(start->Table_No ==table)
    {
        ptr=start;
        start=start->nxt;
        free(ptr);
    }
    else
    {
        for(ptr=start;(ptr->nxt->Table_No != table)&&(ptr !=NULL);ptr=ptr->nxt);
        temp=ptr->nxt;
        ptr->nxt =temp->nxt;
        free(temp);
    }
}
int main()
{
  int op,tn,Customer=1;
  Node *disp;
  while(Customer)
  {
  printf("select the action of client in the below option\n");
  printf("1=Food is to be ordered\n");
  printf("2=Customer left the restaurant\n");
  scanf("%d",&op);
  printf("enter tablenum\n");
  scanf("%d",&tn);
  if(op==1)
  {
    if(start == NULL)
      addfirst(tn);  
    else
       add(tn);
  }
  else if(op==2)
  {
      dlt(tn);
  }
  else
    printf("Wrong option\n");
  printf("Do you wish to see all customers?,If yes press 0");
  scanf("%d",&Customer);
  }
  
  for(disp=start;disp != NULL;disp=disp->nxt)
  {
       printf("mealid=%d\ttable num=%d\n",disp->meal_Id,disp->Table_No);
  }
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...