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

C LANGUAGE IMPLEMENTATION - BIGINNER LEVEL implement several functions, declared

ID: 3782305 • Letter: C

Question

C LANGUAGE IMPLEMENTATION - BIGINNER LEVEL

implement several functions, declared in student.h, transcript.h and internal.h (with support from common.h).

There are 3 rules:

1. There are three types of students: undergraduate, MEng and PhD.

2. Undergraduates must complete 40 courses, MEng students 5 and PhD students 2.

3. Undergraduate students require a mark of 50 to pass; graduate students need a 65.

----------------Common.h--------------------------------------------------------------------------------------------------------------------------------------------------------------

#ifndef COMMON_H

#define COMMON_H

/*Portable macros for declaring C functions visible to C++.*/

#ifdef __cplusplus

#define BEGIN_DECLS extern "C" {

#define END_DECLS }

#else

#define BEGIN_DECLS

#define END_DECLS

#endif

#endif /* COMMON_H */

------------------------------------Internal.h--------------------------------------------------------------------------------------------------------------------------------

#ifndef STUDENT_INTERNAL_H

#define STUDENT_INTERNAL_H

#include "student.h"

/** Allocate memory for a new @ref student object. */

struct student* student_alloc(void);

/**Initialize an already-allocated @ref student object.

* @returns NULL on failure but does not free the memory*/

struct student* student_init(struct student *, const char *name, size_t namelen,

struct student_id, student_complete);

#endif /* STUDENT_INTERNAL_H */

---------------------------------------------student.h------------------------------------------------------------------------------------------------------------------------

#ifndef STUDENT_H

#define STUDENT_H

#include <sys/types.h>

#include "common.h"

#include "transcript.h"

BEGIN_DECLS

/** A student ID is composed from a registration year and a serial number. */

struct student_id {

   unsigned short   sid_year;

   unsigned int   sid_serial;

};

/* Forward declaration. */

struct student;

/**

* Function pointer: a function that examines a @ref student to determine

* whether or not they've finished their program.

*/

typedef int (*student_complete)(struct student *);

/**

* Representation of a registered student.

*/

struct student {

   /** The student's full name. Memory is owned by this structure. */

   char           *s_name;

   struct student_id   s_id;

   /** Number of references to this student. */

   unsigned int       s_ref;

   /** Transcript (singly-linked list, NULL terminator). */

   struct transcript_entry   *s_transcript;

   /** Whether or not this student has completed his/her program. */

   student_complete   s_complete;

   enum Student_Type stundent_type;

};

enum student_Type{

   UnderGradStudent,

   MEngStudent,

   PhdStudent,

}

/**Allocate and initialize a new grad student (MEng or PhD).

*

* The returned structure will have a refcount of 1.*/

struct student*   student_grad_create(const char *name, size_t namelen,

   struct student_id, int phd);

/** Allocate and initialize a new undergraduate student.

*

* The returned structure will have a refcount of 1.*/

struct student*   student_undergrad_create(const char *name, size_t namelen,

   struct student_id);

/** A student has completed a course: add to their transcript.

*

* @returns 1 on success, 0 on failure

*/

int   student_add_entry(struct student *, struct transcript_entry *);

/**Deallocate a @ref student with a refcount of 1.

*/

void   student_free(struct student *);

/** Increment a @ref student's refcount. */

void   shold(struct student *);

/** Decrement a @ref student's refcout and free if 0. */

void   srelease(struct student *);

END_DECLS

#endif /* STUDENT_H */

----------------------------------------------------------transcript.h--------------------------------------------------------------------------------------------------------

#ifndef TRANSCRIPT_H

#define TRANSCRIPT_H

#include <sys/types.h>

#include "common.h"

BEGIN_DECLS

enum faculty {

ARTS,

BUSINESS,

ENGINEERING,

MEDICINE,

MUSIC,

NURSING,

PHARMACY,

};

/**

* A result in a course (

*/

struct transcript_entry {

/** Identifier: Engineering 1020, etc. */

enum faculty te_faculty;

enum Student_Type student_type;

unsigned int te_number;

/** Grade attained in the course. */

unsigned int te_grade;

/** Number of references to this entry. */

unsigned int te_ref;

/** Next entry in the singly-linked list (or NULL terminator). */

struct transcript_entry *te_next;

};

/**

* Create a new transcript entry.

* @returns a @ref transcript_entry with refcount 1

*/

struct transcript_entry* transcript_entry(

enum faculty, unsigned int course_number, unsigned int grade);

/** Deallocate a @ref transcript_entry. */

void transcript_entry_free(struct transcript_entry *);

/** Increment a @ref transcript_entry's refcount.*/

void tehold(struct transcript_entry *);

/** Decrement a @ref transcript_entry's refcout and free if 0. */

void terelease(struct transcript_entry *);

END_DECLS

#endif /* TRANSCRIPT_H */

Explanation / Answer

#include struct student { char name[50]; int roll; float marks; } s[10]; int main() { int i; printf("Enter information of students: "); // storing information for(i=0; i