C  Assignment Help

This is the only location to come to for help with C home work. If you are looking for help on C then, I’m not aware of anywhere else where you can get better service.

C was a programming language invented by Kernigan and Ritchie and was used to program the PDP computers.It is a form of high level assembly language, and is the one of the most common languages used (especially since languages such as Java tend to be written in C). The operating system in your computer and games are normally programmed in C as well. Many other languages use C style syntax, so ; to end a line, [] to indicate array access. The programmer is responsible for allocating and freeing memory themselves as there is no garbage collection.

C is a general purpose middle level language, originally developed by Dennis M. Ritchie who had first developed UNIX operating system at Bell Labs. All UNIX application programs, the C compiler, the UNIX operating system are written in C. It is a structured language and is easy to learn. The programs written in C programming language can be compiled on a variety of computer platforms. They can handle low level activities that are efficient. C is widely used as a popular system programming language. Our experts who provide help with C programming homework, which is useful for students in implementing and writing the code efficiently. Programminghomeworkhelp offers assignment solutions to students seeking C programming homework help. C programming language is also used for professional coding.

C is an easy to learn structured language, if proper attention is paid to the subject under the guidance of specialized experts. The C programming homework answers are provided by us with the intention of creating masters of C programming language.  The C programming language homework solved by our experts meets all the guidelines stipulated by the universities, schools and colleges for successful execution of the homework assignment.

As an illustration of a project, here’s one that indicates the syle we have done with a C language assignment.

Producer-Consumer problem using PThreads library.

Your program will create 4 consumer threads and 4 producer threads. Each thread loops for 5 iterations.

Producers insert cookies to a buffer while consumers remove cookies from the buffer.

This project is very similar as the programming project 6.40 in the textbook. On pages 274 to 278 of the textbook, essential explanation and a code skeleton of producer-consumer problem using PThreads are already given. However, you need to note that there are a few differences:

  1. Instead of inserting and removing item from the buffer, in this assignment you will simply use an int cookieCount, which represents the total number of cookies. The insert_item(..) and remove_item(..) will just increment and decrement the cookieCount.
  2. The arguments of insert_item(..) and remove_iterm(..) will be the id of the thread, not the item. So the type will be int. e.g.: int insert_item(int threadid); The return value indicates if there is any error (-1 means error, 0 means no error).
  3. insert_item(int) and remove_item(int) will print out the thread id as well as the current cookie count. (See Example Output below.) The printing needs to be done in the critical section. I am recapping the essential requirements of the project, with the modifications, as below:

For this project, standard counting semaphores will be used for empty and full, and a mutex lock, rather than a binary semaphore, will be used to represent mutex. The producer and consumer – running as separate threads – will add cookies to and remove cookies from a buffer that is synchronized with these empty, full, and mutex structure.

The buffer will be manipulated with two functions, insert_item() and remove_item(), which are called by the producer and consumer threads, respectively. A skeleton outlining these functions (without synchronization logic) are:

int insert_item(int threadid)
{
    /* increment cookie count by 1.
    Print out a line indicating which thread is inserting a cookie and current cookie count.
    Return a value (0 or -1).
    */
}
int remove_item(int threadid)
{
    /* decrement cookie count by 1.
    Print out a line indicating which thread is removing a cookie and current cookie count.
    Return a value (0 or -1).
    */
}

The main() function will do the initialization to initialize the mutual-exclusive object mutex along with empty and full semaphore. It also creates the separate producer and consumer threads, 4 each. Once it has created the producer and consumer threads, the main() function will wait for the 8 threads to finish (using pthread_join()),

A skeleton for main() is:

int main(int argc, char *argv[])
{
    /* Initialization.
    Create producer threads.
    Create consumer threads.
    Wait for producer threads to finish.
    Wait for consumer threads to finish.
    Cleanup and exit.
    */
}

The producer thread will alternate between inserting an item and sleeping for 1second It will do so for 5 times. Call sleep(1) to sleep for 1 second between iterations. A skeleton for producer is:

void *producer(void *param)
{
    //some local variables
    for( int i=1;i<=5;i++)
    {
        //insert an item
        //sleep for 1 second
    }
}

Consumer can be coded similarly.

The above skeletons do NOT yet have any synchronization logic. You need to add mutex locks and semaphores at the correct places.

You will use one mutex for protecting the critical section in insert_item(..) and remove_iterm(..). The related code sample is as below (you need to check the return value in your program to know if the operation was successful):

#include <pthread.h>
pthread_mutext_t mutex;
/* create the mutex lock */
pthread_mutex_init(&mutex, NULL);
/*acquire the mutex lock */
pthread_mutex_lock(&mutex);
/*** critical section ****/
/* release the mutex lock */
pthread_mutex_unlock(&mutex);

You will need two semaphores for thread synchronization between producers and consumers:

sem_t full;
sem_t empty;

Semaphore empty is initialized to BUFFER_SIZE, which is set to 10. Semaphore full is initialized to 0.
You can do so using:

sem_init(&empty, 0, BUFFER_SIZE);
sem_init(&full, 0, 0);

The following example shows the semaphore API using a binary semaphore as example:

#include <semaphore.h>
sem_t mutex;
sem_init(&mutex, 0, 1);
/* acquire the semaphore */
sem_wait(&mutex);
/*** critical section ***/
/* release the semaphore */
sem_post(&mutex);

Cleanup the resources in main() by destroying the semaphore and mutex which can be done by calling pthread_mutex_destroy() and sem_destroy().

You need to define the NUM_THREADS and BUFFER_SIZE as constants. You will set
NUM_THREADS to 4 in this assignment. By setting them as constants, you can change them easily.

If you will use printf to print out information, use fflush(stdout) after it to flush the output buffer

#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>

#define NUM_THREADS 4
#define BUFFER_SIZE 10

pthread_mutex_t mutex;
sem_t full;
sem_t empty;
int cookieCount;

// producer calls this function to produce a cookie
void insert_item(int pid) {
  cookieCount ++;
  printf("producer #%d inserted a cookie. Total: %d\n", pid, cookieCount);
  fflush(stdout);
}

// consumer calls this function to remove a cookie
void remove_item(int pid) {
  cookieCount --;
  printf("consumer #%d removed a cookie. Total: %d\n", pid, cookieCount);
  fflush(stdout);
}

void *producer_procedure(void *p) {
  int pid = (int)(unsigned long)p;
  int times = 5; 
  int i = 0;
  for (i = 0; i < times; i++) {
    if (sem_wait(&empty) != 0) { // wait until there is free space
      fprintf(stderr, "Could not wait on the semaphore.\n");
      break;
    }

    if (pthread_mutex_lock(&mutex) != 0) {
      fprintf(stderr, "Could not lock the mutex.\n"); // should not happen
      break;
    }

    insert_item(pid); // insert item

    pthread_mutex_unlock(&mutex);

    if (sem_post(&full) != 0) { // increase the full slot by 1
      fprintf(stderr, "Could not post on the semaphore.\n");
    }

    sleep(1);
  }
  return NULL;
}

void *consumer_procedure(void *p) {
  int pid = (int)(unsigned long)p;
  int times = 5; 
  int i = 0;
  for (i = 0; i < times; i++) {
    if (sem_wait(&full) != 0) { // wait until there is at least one cookie
      fprintf(stderr, "Could not wait on the semaphore.\n");
      break;
    }

    if (pthread_mutex_lock(&mutex) != 0) {
      fprintf(stderr, "Could not lock the mutex.\n"); // should not happen
      break;
    }

    remove_item(pid); // remove item

    pthread_mutex_unlock(&mutex);

    if (sem_post(&empty) != 0) { // increase the empty slot by 1
      fprintf(stderr, "Could not post on the semaphore.\n");
    }

    sleep(1);
  }

  return NULL;
}

int main(int argc, char *argv[]) {
  pthread_t producers[NUM_THREADS];
  pthread_t consumers[NUM_THREADS];
  int i;

  // initilize the mutex
  if (pthread_mutex_init(&mutex, NULL) != 0) {
    fprintf(stderr, "Could not initialize the mutex.\n");
    return 0;
  }

  // initialize the semphore
  if (sem_init(&empty, 0, BUFFER_SIZE) != 0) {
    fprintf(stderr, "Could not initialize the semaphore.\n");
    return 0;
  }
  if (sem_init(&full, 0, 0) != 0) {
    fprintf(stderr, "Could not initialize the semaphore.\n");
    return 0;
  }

  // create the consumers and producers
  for (i = 0; i < NUM_THREADS; i++) {
    producers[i] = 0;
    consumers[i] = 0;
  }

  for (i = 0; i < NUM_THREADS; i++) {
    // parse the thread id (i) as the parameter to the procedure
    if (pthread_create(&producers[i], NULL, producer_procedure, (void *)(unsigned long)i) != 0) {
      fprintf(stderr, "Could not create producer thread\n");
      break;
    }
  if (pthread_create(&consumers[i], NULL, consumer_procedure, (void *)(unsigned long)i) != 0) {
      fprintf(stderr, "Could not create consumer thread\n");
      break;
    }
  }

  // wait until all the producers and consumers terminate
  for (i = 0; i < NUM_THREADS; i++) {
    if (producers[i] > 0) {
      pthread_join(producers[i], NULL);
    }
    if (consumers[i] > 0) {
      pthread_join(consumers[i], NULL);
    }
  }

  // destroy the semaphores and mutex before the system terminates
  sem_destroy(&empty);
  sem_destroy(&full);
  pthread_mutex_destroy(&mutex);

  return 0;
}

Here is a sample of a C home work, compare our results to anyone else. Check out our C programming homework help.

With our C programming assignment help, students can understand the basic functionalities of C which was used for system development work initially because the code produced were running as fast as the code written in assembly language. The practical implementation of C programming showcases the areas like the operating systems, Language compilers Assemblers, Print spoolers, Network drivers, Language interpreters, and many others. C programming language also defines the parts, which are the preprocessor commands, variables, statements, functions, expressions and comments. Experts who provide help with C programming homework have years of expertise in coding.

Our programming homework service is excellent and best in class. The C language assignment questions that we give to our students satisfies the need of even the most intellectual of the minds.  The assignment problem in C language that are given in top colleges and schools are more often difficult to crack, but those problems are made simpler by our experts. The solution to C programming language homework is provided by our experts that have a masters or PhD degree under their belt. The C programming homework answers provided by our experts is in easily comprehendible language and the codes are nicely commented that the students need not go anywhere else for their homework help. The C language produces efficient programmes and can handle all the low level activities. The computer programming homework help in C language teaches the students how to write efficient codes that are free from bugs.

C program for gross pay

Problem 1:

Write a C program that will calculate the gross pay of a set of employees.
The program should prompt the user to enter the number of hours each employee worked. When prompted, key in the hours shown below.

The program determines the overtime hours (anything over 40 hours), the gross pay and then outputs a table in the following format.

Column alignment, leading zeros in Clock#, and zero suppression in float fields is important.

Use 1.5 as the overtime pay factor.

---------------------------------------------------------
Name            Clock#   Wage   Hours     OT     Gross
---------------------------------------------------------
Connie Cobol    098401   10.60   51.0    11.0    598.90
Mary Apl        526488    9.75   42.5     2.5    426.56
Frank Fortran   765349   10.50   37.0     0.0    388.50
Jeff Ada        034645   12.25   45.0     5.0    581.88
Anton Pascal    127615   10.00   40.0     0.0    400.00
---------------------------------------------------------

Total:                          215.5    18.5    2395.84
Average:                         43.1     3.7    479.168
Minimum                          37.0     0.0    388.50
Maximum                          51.0    11.0    598.90

Additionally, here are a few more things I would like you to calculate and print out.

1) These are mandatory and need to be done:

a) Add a Total row at the end to sum up the hours, ot, and gross columns
b) Add an Average row to print out the average of the hours, ot, and gross columns

2) These two optional challenges if you have time

a) Calculate and print the minimum hours, ot, and gross values
b) Calculate and print the maximum hours, ot, and gross values

You should implement this program using a structure similar to the suggested one below to store the information for each employee. Feel free to tweak it if you wish. For example, its OK to have a first and last name member instead of just a name member, and if you want to use different types, that is OK as well.

struct employee
{
  char  name [20];
  long  id_number;
  float wage;
  float hours;
  float overtime;
  float gross;
};

Use the following information to initialize your data.

Connie Cobol     98401   10.60   
Mary Apl        526488    9.75
Frank Fortran   765349   10.50
Jeff Ada         34645   12.25
Anton Pascal    127615   10.00

With our C programming assignment help, students can understand the basic functionalities of C which was used for system development work initially because the code produced were running as fast as the code written in assembly language. The practical implementation of C programming showcases the areas like the operating systems, Language compilers Assemblers, Print spoolers, Network drivers, Language interpreters, and many others. C programming language also defines the parts, which are the preprocessor commands, variables, statements, functions, expressions and comments. Experts who provide help with C programming homework have years of expertise in coding.

The C programming assignment questions that are compiled, is the finest collection of questions that are asked in the top ranked schools and colleges throughout the world. The computer programming assignment help that we provide suffices the need of even the research scholars and the working professionals. The students pay for the programming homework but they get full worth of the money that they pay to us by getting higher grades in their internal  and  semester  examination.

Create an array of structures with 5 elements, each being of type struct employee.

Initialize the array with the data provided and reference the elements of the array with the appropriate subscripts.

Solution:

#include<stdio.h>

/* Define Constants */
#define NUM_EMPL 5
#define OVERTIME_RATE 1.5f
#define STD_WORK_WEEK 40.0f

struct employee
{
  char first_name[20];
  char last_name[20];
  long clock_number;
  float wage_rate;
  float hours;
  float OT;
  float gross;
};

// struct to store the total/averate/minimum/maximum
struct statistic {
  float hours;
  float OT;
  float gross;
};

/* define prototypes here for each function except main */
void Get_Input (struct employee e[]);
void Gross_pay_calc (struct employee e[]);

void Output_results_screen (struct employee e[], 
    struct statistic *total, struct statistic *average, struct statistic *minumum, struct statistic *maximum);

void Total_and_Avg (struct employee e[], struct statistic *total, struct statistic *average);
void Minimum_and_Maximum(struct employee e[], struct statistic *total, struct statistic *average);

/*************************************************************************/
/* Function: Output_results_screen */
/* */
/* Purpose: Outputs to screen in a table format the following */
/* information about an employee: Clock, Wage, */
/* Hours, Overtime, and Gross Pay. */
/* */
/* Parameters: employeeData - an array of structures containing */
/* employee information */
/* */
/* Returns: Nothing (void) */
/* */
/************************************************************************/

void Output_results_screen (struct employee employeeData[], 
    struct statistic *total, struct statistic *average, struct statistic *minimum, struct statistic *maximum)
{
int idx; /* loop index */

        printf ("\n\tGeorge Smith, C Programming, Fifth Homework Assignment\n\n");
        printf ("\t----------------------------------------------------------\n");
        printf ("\tName            Clock#  Wage    Hours    OT      Gross\n");
        printf ("\t----------------------------------------------------------\n");

/* printf information about each employee */
for (idx = 0; idx < NUM_EMPL ; ++idx)
{
        printf("\t%s %s \t%06li \t%5.2f \t%4.1f \t%4.1f \t%6.2f \n",employeeData[idx].first_name, 
            employeeData[idx].last_name, employeeData[idx].clock_number, employeeData[idx].wage_rate, 
            employeeData[idx].hours,employeeData[idx].OT, employeeData[idx].gross);
} /* for */
        printf ("\t----------------------------------------------------------\n");
        printf ("\tTotal: \t\t\t\t%5.1f \t%5.1f \t%5.2f\n",total->hours, total->OT, total->gross);
        printf ("\tAverage: \t\t\t%5.1f \t%5.1f \t%5.3f\n", average->hours, average->OT, average->gross);
        printf ("\tMinimum: \t\t\t%5.1f \t%5.1f \t%5.2f\n",minimum->hours, minimum->OT, minimum->gross);
        printf ("\tMaximum: \t\t\t%5.1f \t%5.1f \t%5.2f\n",maximum->hours, maximum->OT, maximum->gross);
} /* Output_results_screen */

/*function for user input*/
void Get_Input (struct employee employeeData[NUM_EMPL])
{
     int idx; /* loop index */

     /* printf information about each employee */
     for (idx = 0; idx < NUM_EMPL ; ++idx)
     {
         printf("\nEnter hours worked for employee %06li : ",employeeData[idx].clock_number);
         scanf("%f",&employeeData[idx].hours);
     }
}
/*function to calculate overtime and gross pay*/
void Gross_pay_calc (struct employee employeeData[NUM_EMPL])
{
     int idx; /* loop index */

     /* printf information about each employee */
     for (idx = 0; idx < NUM_EMPL ; ++idx)
     {
         if (employeeData[idx].hours <= STD_WORK_WEEK)
         {
            employeeData[idx].OT = 0.0;
            employeeData[idx].gross = employeeData[idx].wage_rate * employeeData[idx].hours;
         }

          else if (employeeData[idx].hours > STD_WORK_WEEK)
          {
            employeeData[idx].OT = employeeData[idx].hours - STD_WORK_WEEK;
            employeeData[idx].gross = (STD_WORK_WEEK * employeeData[idx].wage_rate) + (employeeData[idx].OT * (OVERTIME_RATE * employeeData[idx].wage_rate));
          }

     }
}

/*function to calculate total and average hours, overtime and gross pay*/
void Total_and_Avg (struct employee employeeData [NUM_EMPL], struct statistic *total, struct statistic *average)
{
int idx; /* loop index */
float total_hours=0;
float total_OT=0;
float total_gross=0;
/* printf information about each employee */
     for (idx = 0; idx < NUM_EMPL ; ++idx)
{
    total_hours+= employeeData[idx].hours;
    total_OT+= employeeData[idx].OT;
    total_gross+= employeeData[idx].gross;
}

total->hours = total_hours;
total->OT = total_OT;
total->gross = total_gross;

average->hours = total_hours / NUM_EMPL;
average->OT = total_OT / NUM_EMPL;
average->gross = total_gross / NUM_EMPL;
}

/*function to calcuate minimum and maximum hours, OT and gross pay*/
void Minimum_and_Maximum(struct employee employeeData[], struct statistic *minimum, struct statistic *maximum)
{

  int idx;

  // initialize the data
  minimum->hours = -1;
  minimum->OT = -1;
  minimum->gross = -1;
  maximum->hours = 0;
  maximum->OT = 0;
  maximum->gross = 0;

  for (idx = 0; idx < NUM_EMPL ; ++idx) 
  {
    if (minimum->hours == -1) {
      minimum->hours = employeeData[idx].hours;
      minimum->OT = employeeData[idx].OT;
      minimum->gross = employeeData[idx].gross;
    }

    // save the new smaller one
    if (minimum->hours > employeeData[idx].hours) {
      minimum->hours = employeeData[idx].hours;
    }
    if (minimum->OT > employeeData[idx].OT) {
      minimum->OT = employeeData[idx].OT;
    }
    if (minimum->gross > employeeData[idx].gross) {
      minimum->gross = employeeData[idx].gross;
    }

    // save the new larger one
    if (maximum->hours < employeeData[idx].hours) {
      maximum->hours = employeeData[idx].hours;
    }
    if (maximum->OT < employeeData[idx].OT) {
      maximum->OT = employeeData[idx].OT;
    }
    if (maximum->gross < employeeData[idx].gross) {
      maximum->gross = employeeData[idx].gross;
    }
  }
}

int main()
{
    /* Variable Declaration and initialization */
    struct employee employeeData[NUM_EMPL] = {
    {"Connie", "Cobol", 98401, 10.60},
    {"Mary", "Apl", 526488, 9.75},
    {"Frank", "Fortran", 765349, 10.50},
    {"Jeff", "Ada", 34645, 12.25},
    {"Anton", "Pascal", 127615, 10.00}
};

struct statistic total, average, minimum, maximum;

/* Call various functions needed to reading, calculating, and printing as needed */
Get_Input(employeeData);
Gross_pay_calc(employeeData);
/* Function call to output results to the screen in table format. */
Total_and_Avg (employeeData, &total, &average);
Minimum_and_Maximum(employeeData, &minimum, &maximum);
Output_results_screen (employeeData, &total, &average, &minimum, &maximum);
return(0); /* success */

}; /* main */

 

Problem 2:

SIMPLE POINTERS

Write a C program that will calculate the gross pay of a set of employees. Declare an array of structures to hold your employees as well as a pointer to it. Do not use any array references with indexes.

    emp[i].wage     /* this is bad, it uses an array reference with an index, in this case, i */

    emp_ptr->wage;  /* this is good, it uses a pointer to reference the wage value */

The program determines the overtime hours (anything over 40 hours), the gross pay and then outputs a table in the following format.

Column alignment, leading zeros in Clock#, and zero suppression in float fields is important.

Use 1.5 as the overtime pay factor.

---------------------------------------------------------
Name            Clock#   Wage   Hours     OT     Gross
---------------------------------------------------------
Connie Cobol    098401   10.60   51.0    11.0    598.90
Mary Apl        526488    9.75   42.5     2.5    426.56
Frank Fortran   765349   10.50   37.0     0.0    388.50
Jeff Ada        034645   12.25   45.0     5.0    581.88
Anton Pascal    127615   10.00   40.0     0.0    400.00
---------------------------------------------------------

You should implement this program using a structure similar to the suggested one below to store the information for each employee. Feel free to tweak it if you wish. For example, its OK to have a first and last name member instead of just a name member, and if you want to use different types (such as long or double), that is OK as well.

struct employee
{
      char  name [20];
      int  id;
      float wage;
      float hours;
      float overtime;
      float gross;
};

Use the following information to initialize your data.

Connie Cobol     98401   10.60   
Mary Apl        526488    9.75
Frank Fortran   765349   10.50
Jeff Ada         34645   12.25
Anton Pascal    127615   10.00

With our C programming assignment help, students can understand the basic functionalities of C which was used for system development work initially because the code produced were running as fast as the code written in assembly language. The practical implementation of C programming showcases the areas like the operating systems, Language compilers Assemblers, Print spoolers, Network drivers, Language interpreters, and many others. C programming language also defines the parts, which are the preprocessor commands, variables, statements, functions, expressions and comments. Experts who provide help with C programming homework have years of expertise in coding.

Create an array of structures with 5 elements, each being of type struct employee

Initialize the array with the data provided.

Set a pointer to it and then use that pointer going forward to access elements (and their associated members) in your array of structures. Again, do not use array references with indexes.

Challenge: If you wish, optionally add code needed to generate a total and average of the hour, overtime, and gross pay values, just like you did in the previous homework.

Solution:

#include<stdio.h>

/* Define Constants */
#define NUM_EMPL 5
#define OVERTIME_RATE 1.5f
#define STD_WORK_WEEK 40.0f

struct employee
{
    char first_name[20];
    char last_name[20];
    long clock_number;
    float wage_rate;
    float hours;
    float OT;
    float gross;
};

// struct to store the total/averate/minimum/maximum
struct statistic {
    float hours;
    float OT;
    float gross;
};

/* define prototypes here for each function except main */
void Get_Input (struct employee *e, int size);
void Gross_pay_calc (struct employee *e, int size);

void Output_results_screen (struct employee *e, int size, 
    struct statistic *total, struct statistic *average, struct statistic *minumum, struct statistic *maximum);

void Total_and_Avg (struct employee *e, int size, struct statistic *total, struct statistic *average);
void Minimum_and_Maximum(struct employee *e, int size, struct statistic *total, struct statistic *average);

/*************************************************************************/
/* Function: Output_results_screen                                       */
/*                                                                       */
/* Purpose: Outputs to screen in a table format the following            */
/* information about an employee: Clock, Wage,                           */
/* Hours, Overtime, and Gross Pay.                                       */
/*                                                                       */
/* Parameters: employeeData - an array of structures containing          */
/* employee information                                                  */
/*                                                                       */
/* Returns: Nothing (void)                                               */
/*                                                                       */
/************************************************************************/

void Output_results_screen (struct employee *employeeData, int size, 
    struct statistic *total, struct statistic *average, struct statistic *minimum, struct statistic *maximum)
{
    int idx; /* loop index */

    printf ("\n\tGeorge Smith, C Programming, Fifth Homework Assignment\n\n");
    printf ("\t----------------------------------------------------------\n");
    printf ("\tName            Clock#  Wage    Hours    OT      Gross\n");
    printf ("\t----------------------------------------------------------\n");

/* printf information about each employee */
    for (idx = 0; idx < size ; ++idx, ++employeeData)
    {
        printf("\t%s %s \t%06li \t%5.2f \t%4.1f \t%4.1f \t%6.2f \n",employeeData->first_name, 
            employeeData->last_name, employeeData->clock_number, employeeData->wage_rate, 
            employeeData->hours,employeeData->OT, employeeData->gross);
    } /* for */

    printf ("\t----------------------------------------------------------\n");
    printf ("\tTotal: \t\t\t\t%5.1f \t%5.1f \t%5.2f\n",total->hours, total->OT, total->gross);
    printf ("\tAverage: \t\t\t%5.1f \t%5.1f \t%5.3f\n", average->hours, average->OT, average->gross);
    printf ("\tMinimum: \t\t\t%5.1f \t%5.1f \t%5.2f\n",minimum->hours, minimum->OT, minimum->gross);
    printf ("\tMaximum: \t\t\t%5.1f \t%5.1f \t%5.2f\n",maximum->hours, maximum->OT, maximum->gross);
} /* Output_results_screen */

/*function for user input*/
void Get_Input (struct employee *employeeData, int size)
{
     int idx; /* loop index */

     /* printf information about each employee */
     for (idx = 0; idx < size ; ++idx, ++employeeData)
     {
         printf("\nEnter hours worked for employee %06li : ",employeeData->clock_number);
         scanf("%f",&employeeData->hours);
     }
}
/*function to calculate overtime and gross pay*/
void Gross_pay_calc (struct employee *employeeData, int size)
{
     int idx; /* loop index */

     /* printf information about each employee */
     for (idx = 0; idx < size ; ++idx, ++employeeData)
     {
         if (employeeData->hours <= STD_WORK_WEEK)
         {
            employeeData->OT = 0.0;
            employeeData->gross = employeeData->wage_rate * employeeData->hours;
         }

         else if (employeeData->hours > STD_WORK_WEEK)
         {
              employeeData->OT = employeeData->hours - STD_WORK_WEEK;
              employeeData->gross = (STD_WORK_WEEK * employeeData->wage_rate) + (employeeData->OT * (OVERTIME_RATE * employeeData->wage_rate));
         }

     }
}

/*function to calculate total and average hours, overtime and gross pay*/
void Total_and_Avg (struct employee *employeeData, int size, struct statistic *total, struct statistic *average)
{
    int idx; /* loop index */
    float total_hours=0;
    float total_OT=0;
    float total_gross=0;
/* printf information about each employee */
     for (idx = 0; idx < size ; ++idx, ++employeeData)
    {
        total_hours+= employeeData->hours;
        total_OT+= employeeData->OT;
        total_gross+= employeeData->gross;
    }

    total->hours = total_hours;
    total->OT = total_OT;
    total->gross = total_gross;

    average->hours = total_hours / size;
    average->OT = total_OT / size;
    average->gross = total_gross / size;
}

/*function to calcuate minimum and maximum hours, OT and gross pay*/
void Minimum_and_Maximum(struct employee *employeeData, int size, struct statistic *minimum, struct statistic *maximum)
{

  int idx;

  // initialize the data
  minimum->hours = -1;
  minimum->OT = -1;
  minimum->gross = -1;
  maximum->hours = 0;
  maximum->OT = 0;
  maximum->gross = 0;

  for (idx = 0; idx < size ; ++idx, ++employeeData) 
  {
    if (minimum->hours == -1) {
      minimum->hours = employeeData->hours;
      minimum->OT = employeeData->OT;
      minimum->gross = employeeData->gross;
    }

    // save the new smaller one
    if (minimum->hours > employeeData->hours) {
      minimum->hours = employeeData->hours;
    }
    if (minimum->OT > employeeData->OT) {
      minimum->OT = employeeData->OT;
    }
    if (minimum->gross > employeeData->gross) {
      minimum->gross = employeeData->gross;
    }

    // save the new larger one
    if (maximum->hours < employeeData->hours) {
      maximum->hours = employeeData->hours;
    }
    if (maximum->OT < employeeData->OT) {
      maximum->OT = employeeData->OT;
    }
    if (maximum->gross < employeeData->gross) {
      maximum->gross = employeeData->gross;
    }
  }
}

int main()
{
    /* Variable Declaration and initialization */
    struct employee employeeData[NUM_EMPL] = {
    {"Connie", "Cobol", 98401, 10.60},
    {"Mary", "Apl", 526488, 9.75},
    {"Frank", "Fortran", 765349, 10.50},
    {"Jeff", "Ada", 34645, 12.25},
    {"Anton", "Pascal", 127615, 10.00}
};

struct statistic total, average, minimum, maximum;

/* Call various functions needed to reading, calculating, and printing as needed */
Get_Input(employeeData, NUM_EMPL);
Gross_pay_calc(employeeData, NUM_EMPL);
/* Function call to output results to the screen in table format. */
Total_and_Avg (employeeData, NUM_EMPL, &total, &average);
Minimum_and_Maximum(employeeData, NUM_EMPL, &minimum, &maximum);
Output_results_screen (employeeData, NUM_EMPL, &total, &average, &minimum, &maximum);
return(0); /* success */

}; /* main */

 

Problem 3:

you need to prompt the user for all of the above information, … and you still need to prompt for the hours worked for each employee.

Hint: Use one or two scanf statements to read in the first and last names with the %s format.

Get the data above from the terminal, and for each one:

  • get dynamic memory, using malloc, for an employee node
  • put the employee data in the dynamic memory node
  • link the nodes with pointers in the above order

After the list pointers are in place you must get at the second and later instances of the structure by going from the first structure down the chain of list pointers.

Then, for each employee, read in the hours worked from the terminal. Do all appropriate computations, and write out the table.

You do not need an array of structures like you used in homework 6 and 7.

Use the template and dynamically allocate linked list nodes as needed.

Your code should work for any number of employees, and that is how the template is designed.

Tip: Use left justification to line up character array name values … for example: %-10.10s or %-10s

Remember: Use the Template!

Solution:

#include<stdio.h>
#include <stdlib.h>   /* for malloc */
#include <ctype.h>


/* Define Constants */
#define NUM_EMPL 5
#define OVERTIME_RATE 1.5f
#define STD_WORK_WEEK 40.0f

struct employee
{
  char first_name[20];
  char last_name[20];
  long clock_number;
  float wage_rate;
  float hours;
  float OT;
  float gross;

  struct employee *next;
};

/*-----------------------------------------------------------------------------*/
/*                                                                             */
/* FUNCTION:  print_list                                                       */
/*                                                                             */
/* DESCRIPTION:  This function will print the contents of a linked             */
/*               list.  It will traverse the list from beginning to the        */
/*               end, printing the contents at each node.                      */
/*                                                                             */
/* PARAMETERS:   emp1 - pointer to a linked list                               */
/*                                                                             */
/* OUTPUTS:      None                                                          */
/*                                                                             */
/* CALLS:        None                                                          */
/*                                                                             */
/*-----------------------------------------------------------------------------*/
void print_list(struct employee *emp1)
{
        struct employee *tmp;   /* tmp pointer value to current node */
        int i = 0;              /* counts the nodes printed          */

        printf ("\n\tGeorge Smith, C Programming, Fifth Homework Assignment\n\n");
        printf ("\t----------------------------------------------------------\n");
        printf ("\tName            Clock#  Wage    Hours    OT      Gross\n");
        printf ("\t----------------------------------------------------------\n");

        /* Start a beginning of list and print out each value               */
        /* loop until tmp points to null (remember null is 0 or false)      */
        for(tmp = emp1; tmp ; tmp = tmp->next)
        {
            i++;
            printf("\t%s %s \t%06li \t%5.2f \t%4.1f \t%4.1f \t%6.2f \n", tmp->first_name, 
            tmp->last_name, tmp->clock_number, tmp->wage_rate, 
            tmp->hours, tmp->OT, tmp->gross);
        }

        printf("\n\nTotal Number of Employees = %d\n", i);

}

void Gross_pay_calc (struct employee *e);

/*----------------------------------------------------------------------------*/
/*                                                                            */
/* FUNCTION:  main                                                            */
/*                                                                            */
/* DESCRIPTION:  This function will prompt the user for an employee           */
/*               id and wage until the user indicates they are finished.      */
/*               At that point, a list of id and wages will be                */
/*               generated.                                                   */
/*                                                                            */
/* PARAMETERS:   None                                                         */
/*                                                                            */
/* OUTPUTS:      None                                                         */
/*                                                                            */
/* CALLS:        print_list                                                   */
/*                                                                            */
/*----------------------------------------------------------------------------*/
int main ()
{

    char   answer[80];       /* to see if the user wants to add more employees */
    int    more_data = 1;    /* flag to check if another employee is to be processed */
    char   value;             /* gets the first character of answer */

    struct employee *current_ptr,   /* pointer to current node */
                    *head_ptr;       /* always points to first node */

   /* Set up storage for first node */
    head_ptr = (struct employee *) malloc (sizeof(struct employee));
    current_ptr = head_ptr;

    while (more_data)
    {
        /*  - Prompt for Employee Name and Hours as well here */
        printf("\nEnter employee first name: ");
        scanf("%s", current_ptr->first_name);

        printf("\nEnter employee last name: ");
        scanf("%s", current_ptr->last_name);


        /* Read in Employee ID and Hourly Wage */
        printf("\nEnter employee ID: ");
        scanf("%li", & current_ptr -> clock_number);

        printf("\nEnter employee weekly wage: ");
        scanf("%f", & current_ptr -> wage_rate);

        printf("\nEnter employee hours: ");
        scanf("%f", & current_ptr -> hours);


        printf("Would you like to add another employee? (y/n): ");
        scanf("%s", answer);

        /* Ask user if they want to add another employee */
        if ((value = toupper(answer[0])) != 'Y')
           {
           current_ptr->next = (struct employee *) NULL;
           more_data = 0; 
           }
        else
           {
           /* set the next pointer of the current node to point to the new node */
           current_ptr->next = (struct employee *) malloc (sizeof(struct employee));
          /* move the current node pointer to the new node */
           current_ptr = current_ptr->next;
           }
    } /* while */

    Gross_pay_calc (head_ptr);
    printf("\n");
    /* print out listing of all employee id's and wages that were entered */
    print_list(head_ptr);

   printf("\n\nEnd of program\n");
   return 0;
}

/*function to calculate overtime and gross pay*/
void Gross_pay_calc (struct employee *employeeData)
{

     /* printf information about each employee */
     while (employeeData != NULL)
     {
         if (employeeData->hours <= STD_WORK_WEEK)
         {
            employeeData->OT = 0.0;
            employeeData->gross = employeeData->wage_rate * employeeData->hours;
         }

          else if (employeeData->hours > STD_WORK_WEEK)
          {
            employeeData->OT = employeeData->hours - STD_WORK_WEEK;
            employeeData->gross = (STD_WORK_WEEK * employeeData->wage_rate) + (employeeData->OT * (OVERTIME_RATE * employeeData->wage_rate));
          }
          // pointer to the next one in the list
          employeeData = employeeData->next;
     }
}

The following is an example C assignment, so if you need C assignment help check out this program.

The various tokens that are discussed in C programming is either a keyword, an identifier, a constant, a string literal or a symbol. C programming similarly define the term identifier that is a name used to detect a variable, function or any other item defined by user. Our online C programming assignment experts also give examples while offering C programming homework help. You are at the right place if you are looking for help with C programming assignment at our site.

Implementing a concordance using bucketed Link List

Question 1. The bucketed list

A problem with linked lists is that traversing nodes can be an expensive operation. One way to reduce the number of nodes in a list is to use bucketing: instead of containing a single value, each node contains a fixed-sized array of values. This can reduce the overall number of nodes in the list, but requires a little extra work to manage its contents.

Download the file ordered_list.c which contains a ordinary (not bucketed) linked-list implementation of a list of strings in alphabetical order. For this question, you will do the following four things:

  1. Rearrange the file to use separate compilation. Keep as much detail as possible private to the header (implementation) file (like the contents of structures).
  2. Convert the list to a bucketed list. Start this by uncommenting the alternative Node structure and using it instead. Then modify the code as described below.
  3. Apply the principles of Programming by Contract to the code. Include all pre- and post-conditions that must be met, and also a function that tests invariants.
  4. Write a main program that thoroughly tests your bucketed list implementation.

You should probably start out with step 1 on the provided code. After you are done, your test code (and Question 2) should work similarly whether you use the original list or your new bucketed list. The header file should be the same for both. The remaining three steps should probably be done together, a bit of each at a time.

Each node in the bucketed list contains a partially-filled array with up to BUCKET_SIZE values. As you add values to the list, they can be inserted into an existing bucket if there is room, using a regular ordered array insertion (shuffling items down). If the desired node is full, then you can split it into two buckets, each containing half the items of the original list. Then insert the value in the correct bucket.

You could instead check the next node to see if the value belongs there and if there’s room for it before splitting, but that’s not required. You should implement the array insertion in a separate function.

The other functions need to be modified as well: find() has to search within the buckets, size() prints the actual number of items (not nodes!), and print() should print the list with blank lines in between the buckets (for verification purposes). The node_count() function should still return the number of nodes in the list. If you want to make other modifications to the details of the implementation, you can.

Hint: you can add more information to the List structure.

Implement the bucketed list code in a file named bucketed_list.c.

In addition to implementing the contract using assertions, you need to include adequate coding to ensure that a program using this list will not crash if the assertions are turned off. Note that to turn off assertions you should compile with -DNDEBUG.

The main program should run a suite of unit tests to ensure that the List correctly handles insertions, searches, and checking the size, and creating and destroying more than one list. Use a white-box strategy that exercises all possibilities (such as buckets being split, and insertions at different positions in an array). It must print results that indicate whether or not each test was successful. Use total_nodes to help verify expected results. Name this program main.c.

Finally, include a Makefile for compiling your complete program.

ordered_list.c

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

// #define BUCKET_SIZE 8

typedef enum BOOL { false, true } boolean;

// Linked list node definition
typedef struct NODE Node;

struct NODE
{
   char *string;
   Node *next;
};

/*
struct NODE
{
   char *bucket[BUCKET_SIZE]; // an array of strings
   int count;                 // number of items in the array
   Node *next;
};
*/

typedef struct LIST List;

struct LIST {
   Node *top; 
};

// construct a linked list
List *construct() {
   List *list;

   list = malloc( sizeof( List ) );
   list->top = NULL;

   return list;
}

// perform an ordered insertion of an item into a list
boolean insert( List *list, char *new_string )
{
   boolean rc = true;
   Node *newNode = NULL;
   Node *curr;
   Node *prev;

   newNode = (Node *)malloc( sizeof( Node ) );
   newNode->string = new_string;

   curr = list->top;
   prev = NULL;
   while ( NULL != curr && strcmp( curr->string, new_string ) < 0 ) {
      prev = curr;
      curr = curr->next;
   }

   if ( prev == NULL ) {
      newNode->next = list->top;
      list->top = newNode;
   } else {
      newNode->next = curr;
      prev->next = newNode;
   }

  // note that we need to have space for the string as well!
   newNode->string = (char *)malloc( strlen( new_string ) + 1 );
   strcpy( newNode->string, new_string );

   return rc;
}

// tells us whether or not the given string is in the list
boolean find( List *list, char *target )
{
   boolean found = false;
   Node *curr = list->top;

   while ( NULL != curr && !found ) {
      if ( strcmp( target, curr->string ) == 0 ) {
         found = true;
      } else {
         curr = curr->next;
      }
   }

   return found;
}

// calculates the number of nodes in a list
int node_count( List *list )
{
   int count;
   Node *curr = list->top;

   count = 0;
   while ( NULL != curr ) {
      count++;
      curr = curr->next;
   }

   return count;
}

// calculates the size of a list
int size( List *list )
{
   return node_count( list );
}

// print the contents of a list, one item per line
void print( List *list )
{
   Node *curr = list->top;

   while ( NULL != curr ) {
      printf( "%s\n", curr->string );
      curr = curr->next;
   }
}

// destroy the nodes in a list
void destroy( List *list )
{
   Node *curr = list->top;
   Node *next;

   while ( NULL != curr ) {
      next = curr->next;
      free( curr->string );
      free( curr );
      curr = next;
   }

   free( list );
}

Some of rules regarding identifiers are explained in C programming, that the punctuation characters are not allowed like @, $ and % within identifiers. C is also a case sensitive language. The concepts of reserved words in C programming may not be used as constants or variables or any other identifier names. C compiler ignores the lines consisting whitespace with a statement known as blank line. Whitespace in C programming separates one part of a statement from another. It allows the compiler to identify where one element in a statement ends and the next element begins. We offer C programming project help to working professionals and C programming homework help to students.

Question 2. Concordance

Using your bucketed list from Question 1, implement a concordance. A concordance stores every word found in a document (without duplicates). Do this by writing a new main program that will read and tokenize any file (from standard input), store the words in an ordered list, print the concordance and its size once the file has been completely processed and conclude by freeing the list.

Your program should compile using a Makefile. When executed, your program reads its input from standard input and writes output to standard output. The output will include blank lines (between buckets, as described in the previous question). Don’t worry about punctuation when processing the file: tokenizing based on whitespace is fine.

Submit your solution tar file thru the associated D2L dropbox. Note: You can submit as many times as you want until the due date and time, but the dropbox will only keep your last copy. Also, you can only submit one file and it must be the tar file containing your README.txt file and two directories (Q1 and Q2 ) containing your solutions to the above questions, respectively.

1. bucketed_list.h   <Header FILE>

#ifndef BUCKETED_LIST_H
#define BUCKETED_LIST_H

typedef enum BOOL { false, true } boolean;

// Linked list node definition
typedef struct NODE Node;
typedef struct LIST List;

List *construct();
boolean insert( List *list, char *new_string );
boolean find( List *list, char *target );
int node_count( List *list );
int size( List *list );
void print( List *list );
void destroy( List *list );

#endif //BUCKETED_LIST_H


2.bucketed_list.c

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

#include "bucketed_list.h"

#define BUCKET_SIZE 8

struct NODE
{
    char *bucket[BUCKET_SIZE]; // an array of strings
    int count;                 // number of items in the array
    Node *next;
};

struct LIST
{
    Node *top; 
};

// construct a linked list
List *construct() {
    List *list;

    list = malloc( sizeof( List ) );
    list->top = NULL;

    return list;
}

void debugNode(Node *curr)
{
    int i;
    boolean comma = false;
    for (i = 0; i < BUCKET_SIZE; i++)
    {
        if (curr->bucket[i])
        {
            if (comma) printf(", ");
            comma = true;
            printf("%s", curr->bucket[i]);
        }
    }
    printf("\n");
}

char* getLast(Node *curr)
{
    int i;
    for (i = BUCKET_SIZE - 1; i > 0; i--)
    {
        if (curr->bucket[i]) return curr->bucket[i];
    }
    return NULL;
}

void splitBucket(Node *from, Node *to)
{
    int i;
    assert(from != NULL);       //Nodes must exist
    assert(to != NULL);
    assert(from != to);         //And nodes must be different
    for (i = (BUCKET_SIZE / 2) - 1; i >= 0; i--)
    {
        to->bucket[i] = from->bucket[(BUCKET_SIZE / 2) + i];
        from->bucket[(BUCKET_SIZE / 2) + i] = NULL;
    }
    //printf("Split %s-%s before %s-%s\n", from->bucket[0], from->bucket[3], to->bucket[0], to->bucket[3]);
}

void insertString(Node *curr, char *new_string)
{
    int i = 0;                  //Insert at 0, if there are no entries
    int j;
    assert(curr != NULL);       //Nodes must exist
    assert(new_string != NULL); //String must exist
    assert(curr->bucket[BUCKET_SIZE - 1] == NULL);  //Bucket must not be full
    if (curr->bucket[0])
    {
        for (i = 0;; i++)
        {
            if (!curr->bucket[i]) break;
            if (strcmp(new_string, curr->bucket[i]) <= 0)
            {
                //printf("Inserting %s before %s\n", new_string, curr->bucket[i]);
                break;
            }
        }
        for (j = BUCKET_SIZE - 1; j > i; j--)
        {
            curr->bucket[j] = curr->bucket[j-1];
        }
    }
    // note that we need to have space for the string as well!
    curr->bucket[i] = (char *)malloc( strlen( new_string ) + 1 );
    strcpy( curr->bucket[i], new_string );
}

// perform an ordered insertion of an item into a list
boolean insert( List *list, char *new_string )
{
    boolean rc = true;
    Node *newNode = NULL;
    Node *curr;
    Node *prev;
    char *lastword;
    assert(list != NULL);       //List must have been created
    assert(new_string != NULL); //String must exist

/*
    if (list->top)
    {
        int i = 0;
        newNode = list->top;
        while (i < 5 && newNode)
        {
            printf("[%d] ", i);
            debugNode(newNode);
            i++;
            newNode = newNode->next;
        }
    }
*/
    curr = list->top;
    prev = NULL;
    while ( NULL != curr && strcmp( curr->bucket[0], new_string ) < 0 )
    {
        prev = curr;
        curr = curr->next;
    }

    if (prev)
    {
        lastword = getLast(prev);
        if (lastword)
        {
            if (strcmp(lastword, new_string) > 0)
            {
                if (prev->bucket[BUCKET_SIZE - 1])
                {
                    newNode = (Node *)calloc( 1, sizeof( Node ) );

                    newNode->next = prev->next;
                    prev->next = newNode;
                    splitBucket(prev, newNode); //Need to split the bucket, to avoid searching
                    return insert(list, new_string);    //Recursive call, so we don't need to check which side to include it on
                }
                //printf("Should insert %s between %s and %s\n", new_string, prev->bucket[0], lastword);
                insertString(prev, new_string);
                return rc;
            }
        }
    }

    if (!curr || curr->bucket[BUCKET_SIZE - 1])     //If bucket is full we need to split, or reached end of list
    {
        newNode = (Node *)calloc( 1, sizeof( Node ) );

        if ( prev == NULL )
        {
            newNode->next = list->top;
            list->top = newNode;
        }
        else
        {
            //newNode->next = curr;
            //prev->next = newNode;
            if (curr)
            {
                newNode->next = curr->next;
                curr->next = newNode;
                splitBucket(curr, newNode);         //Need to split the bucket since it was full
                return insert(list, new_string);    //Recursive call, so we don't need to check which side to include it on
            }
            else
            {
                prev->next = newNode;
            }
        }
        curr = newNode;
    }

    insertString(curr, new_string);

    return rc;
}

// tells us whether or not the given string is in the list
boolean find( List *list, char *target )
{
    Node *curr = list->top;
    Node *prev = curr;
    int cmp;
    assert(list != NULL);       //List must have been created
    assert(target != NULL);     //We must provide a non null search string

    while ( NULL != curr)
    {
        cmp = strcmp( target, curr->bucket[0] );

        if ( cmp == 0 )
        {
            return true;
        }
        else if (cmp > 0)
        {
            prev = curr;
            curr = curr->next;
        }
        if (cmp < 0 || !curr)
        {
            //It might be on the previous "page"
            for (cmp = BUCKET_SIZE - 1; cmp > 0; cmp--)
            {
                if (prev->bucket[cmp] && !strcmp(target, prev->bucket[cmp]))
                {
                    return true;
                }
            }
            break;
        }
    }

    return false;
}

// calculates the number of nodes in a list
int node_count( List *list )
{
    int count = 0;
    Node *curr = list->top;
    assert(list != NULL);       //List must have been created

    while ( NULL != curr )
    {
        count++;
        curr = curr->next;
    }

    return count;
}

// calculates the size of a list
int size( List *list )
{
    int count = 0;
    Node *curr = list->top;
    int i;
    assert(list != NULL);       //List must have been created

    while ( NULL != curr )
    {
        for (i = BUCKET_SIZE - 1; i >= 0; i--)
            if (curr->bucket[i]) count++;
        curr = curr->next;
    }

    return count;
}

// print the contents of a list, one item per line
void print( List *list )
{
    Node *curr = list->top;
    int i;
    assert(list != NULL);       //List must have been created

    while ( NULL != curr )
    {
        for (i = 0; i < BUCKET_SIZE; i++)
        {
            if (curr->bucket[i]) printf( "%s\n", curr->bucket[i] );
        }
        printf("\n");   //blank to check buckets
        curr = curr->next;
    }
}

// destroy the nodes in a list
void destroy( List *list )
{
    Node *curr = list->top;
    Node *next;
    int i;
    assert(list != NULL);       //List must have been created


    while ( NULL != curr )
    {
        next = curr->next;
        for (i = BUCKET_SIZE - 1; i >= 0; i--)
            free( curr->bucket[i] );
        free( curr );
        curr = next;
    }

    free( list );
}


concordance.c

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

#include "bucketed_list.h"

int main()
{
    List *words = construct();
    char word[32];
    int count = 0;

    //FILE *file = fopen("mikado.txt", "r");
    while (true)
    {
        int read = scanf("%s30", word);
        //int read = fscanf(file, "%s30", word);
        if (read < 0) break;
        count++;
        if (!find(words, word))
        {
            insert(words, word);
        }
        //if (size(words) > 30) break;
    };
    //fclose(file);
    print(words);
    printf("There are %d words in the text, and %d unique words (in %d nodes).\n", count, size(words), node_count(words));
    destroy(words);
    //getchar();
}



Main
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "bucketed_list.h"

void check(int value, int expected, char *message, char *testing)
{
    if (value == expected)
    {
        printf("%s = %d. %s. Test Passed\n", message, value, testing);
    }
    else
    {
        printf("%s = %d, expected value %d. %s. Test Failed\n", message, value, expected, testing);
    }
}

#define CHECK(value, expected, explain) check(value, expected, #value, explain)

void test()
{
    List *words = construct();
    List *second = construct();
    char search[2];
    char ch;
    int found = 1;

    CHECK(size(words), 0, "Empty list");
    CHECK(node_count(words), 0, "Empty list");
    insert(words, "9");
    CHECK(size(words), 1, "Single item");
    CHECK(node_count(words), 1, "Single item");
    insert(words, "8");
    CHECK(size(words), 2, "Two items");
    CHECK(node_count(words), 2, "Two items");
    insert(words, "7");
    insert(words, "6");
    insert(words, "5");
    insert(words, "4");
    insert(words, "3");
    insert(words, "2");
    CHECK(size(words), 8, "Full bucket");
    CHECK(node_count(words), 1, "Full bucket");
    insert(words, "1");
    CHECK(node_count(words), 2, "Split bucket");
    search[1] = 0;
    for (ch = 'z'; ch >= 'a'; ch--)
    {
        search[0] = ch;
        insert(words, search);
    }
    CHECK(size(words), 35, "1-9, a-z");
    CHECK(node_count(words), 8, "1-9, a-z");
    for (ch = 'z'; ch >= 'a'; ch--)
    {
        search[0] = ch;
        found &= find(words, search);
        assert(find(words, search) == true);    //All the letters should be present
        insert(words, search);
        insert(second, search);
    }
    printf("Search %s\n", found ? "passed" : "failed");
    print(words);
    CHECK(size(second), 26, "Seperate list of a-z");
    destroy(words);
    destroy(second);
    getchar();
}

int main() { test(); }

Data types in C programming is used for declaring variables or functions of different types refers to an extensive system. The type of a variable determines the amount of storage space required and how to interpret the bit pattern stored. The various data types in C programming are arithmetic types which further classified as integer types and floating-point types, and the Enumerated types. Our tutors work hard and provide 100% plagiarism free codes to students who need C programming homework help. Also, C programming assignment help is provided well within the deadline.

Our experts available 24*7to provide C programming assignment solutions, and are highly skilled in their relevant subjects. Students seeking assignment solutions in C programming project help can upload their assignment on our website or can send it via email.

. The computer programming homework help in C language teaches the students how to write efficient codes that are free from bugs.  The C programming assignments given by the schools and colleges require adept mentoring and our expert consultants are there to provide the requisite help. The C programming assignments questions given by our experts are the real gems that has been meticulously gathered by our experts. The programme written in C language can be compiled on various computer platforms. C language was invented at the Bell Labs to write an operating system called UNIX. C programming assignments for beginners includes all the fundamental basic concepts that are necessary to provide strong foundations to students in C language programming. The help with C programming assignment that we provide is all inclusive and complete in all respects. Our experts also take the responsibility of writing C programming project report. Today C is the most popularly used system programming language and numerous softwares has been implemented using the C programming language.