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

Tuples C Programming I need to complete the definition of the tupla tBook so it

ID: 3825339 • Letter: T

Question

Tuples C Programming

I need to complete the definition of the tupla tBook so it can store the following information:

-An identifier max. 13 charcaters lenght

-Year published (integer)

-Availability ( Boolean , Tor F)

-A tuple Classification with 2 fields. The indetifier from the main section the books belongs to (1 character) and the identifier from the subsection the book belongs to (1 character)

-The author code (string of three characters)

-Book tittle ( Max string of 100 characters)

Please note that we should use constants for the strings length.

it needs to be completed in tuple tBook in the following data.h file:

data.h

/* This code ensures that this file is included only once */
#ifndef __DATA_H
#define __DATA_H
/* If the constant DATA_H is not defined (ifndef), the code is added, otherwise, this code is excluded. When the code is added, the constant is defined, therefore next time this file will be included it will be defined and no inclusion will be done. */

#define MAX_PATHNAME 256
#define MAX_LINE 512
#define MAX_SECTIONS 10
#define MAX_SECTION_NAME 100
#define MAX_BOOKS 300
#define MAX_SUB 10
#define MAX_BOOK_AUTHOR_CODE 4

/* Definition of a boolean type */
typedef enum {FALSE, TRUE} tBoolean;

/* Definition of the error type. */
typedef enum {OK=1, ERROR=0, ERR_CANNOT_READ=-1, ERR_CANNOT_WRITE=-2, ERR_MEMORY=-3, ERR_DUPLICATED_ENTRY=-4, ERR_INVALID_DATA=-5, ERR_ENTRY_NOT_FOUND=-6} tError;

/* Definition of a location */
typedef struct {
    char row;
    char column;
    char shelf;
} tLocation;

/* Definition of a section */
typedef struct {
    char id;
    char name[MAX_SECTION_NAME];
    tLocation init;
} tSection;

/* Table of sections */
typedef struct {
    tSection table[MAX_SECTIONS];
    unsigned int size;
} tSectionTable;


/* Definition of the book */
typedef struct {
} tBook;

/* Table of books */
typedef struct {
    tBook table[MAX_BOOKS];
    unsigned int size;
} tBookTable;


/* Definition of the application data structure */
typedef struct {
    /* Path where data will be stored */
    char path[MAX_PATHNAME];
   
    /* sections table */
    tSectionTable sections;
   
    /* Books table */
    tBookTable books;
   
} tAppData;

#endif /*__DATA_H*/

Explanation / Answer

So here is the code including the section tBook.....

/* This code ensures that this file is included only once */
#ifndef __DATA_H
#define __DATA_H
/* If the constant DATA_H is not defined (ifndef), the code is added, otherwise, this code is excluded. When the code is added, the constant is defined, therefore next time this file will be included it will be defined and no inclusion will be done. */
#define MAX_PATHNAME 256
#define MAX_LINE 512
#define MAX_SECTIONS 10
#define MAX_SECTION_NAME 100
#define MAX_BOOKS 300
#define MAX_SUB 10
#define MAX_BOOK_AUTHOR_CODE 3
#define MAX_TITLE_LENGTH 100
#define MAX_ID_LENGTH 13
/* Definition of a boolean type */
typedef enum {FALSE, TRUE} tBoolean;
/* Definition of the error type. */
typedef enum {OK=1, ERROR=0, ERR_CANNOT_READ=-1, ERR_CANNOT_WRITE=-2, ERR_MEMORY=-3, ERR_DUPLICATED_ENTRY=-4, ERR_INVALID_DATA=-5, ERR_ENTRY_NOT_FOUND=-6} tError;
/* Definition of a location */
typedef struct {
char row;
char column;
char shelf;
} tLocation;
/* Definition of a section */
typedef struct {
char id;
char name[MAX_SECTION_NAME];
tLocation init;
} tSection;
/* Table of sections */
typedef struct {
tSection table[MAX_SECTIONS];
unsigned int size;
} tSectionTable;

/* Definition of the book */
typedef struct {

//IDENTIFIER
char identifier[MAX_ID_LENGTH];

//year published
  int yearPublished;
//availability as boolean
bool availability;
//classification : [0] means a character identifier from main section
//and [1] means a character identifier from subsection and both are the characters
char classification[2];
//author code
char authorCode[MAX_BOOK_AUTHOR_CODE];
//title
char title[MAX_TITLE_LENGTH];
} tBook;
/* Table of books */
typedef struct {
tBook table[MAX_BOOKS];
unsigned int size;
} tBookTable;

/* Definition of the application data structure */
typedef struct {
/* Path where data will be stored */
char path[MAX_PATHNAME];

/* sections table */
tSectionTable sections;

/* Books table */
tBookTable books;

} tAppData;
#endif /*__DATA_H*/

So, here you are asked to complete the definition of the structure tBook.

The first thing is an identifier. It is of length 13 characters max.

As in the last line of the question, it is written that you need to use constants for the strings length, I first defined a constant that represents this identifier length as: #define MAX_ID_LENGTH 13

and then I used this MAX_ID_LENGTH to declare the identifier of that much length.

The next is simple : int yearPublished and it can store the year value in which this book is published.

The next is availability : bool availability can save this value, true or false

The next information is : tuple classification.

Here, 2 classifications are needed and they are of same type, 1 character. Plus, they are inter related also. First you find the main section and from that you will find its subsection.

So, I created a character array for the same as : char classification[2];

In which you can understand and use it as : when you access the index 0, it means it is the main section and when you access the index 1, it means the sub section.

The next information is author code.
It is a string with 3 characters.
This length also we need to define as constant right!
If you see the code in data.h, there is 1 constant MAX_BOOK_AUTHOR_CODE with value 4, but it is not used anywhere in data.h code you uploaded.

So I used that constant itself, changed its value from 4 to 3.

And created the author code string as : char authorCode[MAX_BOOK_AUTHOR_CODE];

The last thing is title.
Its size (maximum) is 100 characters so let's define it as #define MAX_TITLE_LENGTH 100 first.

And then we will use this constant to declare the book title as: char title[MAX_TITLE_LENGTH];

So this how the structure tBook is completed with the given requirements.

Do comment if there is any query. Thank you. :)

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