
Clark N.
asked 03/07/21create a simple linked list c++ program
The linked list
should hold students biodata records. Name the linked list
‘Student_record’ and implement the following:
1. Define and Create a node called ‘Student_biodata’ that can store the
following data fields:
Given, Last, Family Name, Age, and Student ID (i.e. student’s
registration number).
2. The ‘Student_record’ linked list should have the following functions:
a. Function to add Student biodata at the end of the of the list
b. Function to add Student in the beginning of the list.
c. Function to display all the records in the list at any given time.
3. In the main function, do the following:
a. Create an object of the linked list
b. Add a student’s biodata to the list object
c. Display the contents of the list object
d. Add another student’s biodata at the beginning of the list object
e. Once again display the contents of the list object
f. Add a third student’s biodata at the end of the list object
g. Finally, display the contents of the list object once again.
1 Expert Answer

Patrick B. answered 03/07/21
Math and computer tutor/teacher
using namespace std;
#include <iostream>
#include <string.h>
#include <string.h>
#include <stdlib.h>
#define STUDENT_NAME_SIZE (128)
#define STUDENT_ID_SIZE (25)
typedef struct _TStudent_Biodata_Node
{
char studentName[STUDENT_NAME_SIZE];
char studentID[STUDENT_ID_SIZE];
int age;
struct _TStudent_Biodata_Node * next;
} * TStudent_Biodata_Node;
#define STUDENT_BIODATA_NODE_SIZE (sizeof(struct _TStudent_Biodata_Node))
typedef struct _TStudentList
{
TStudent_Biodata_Node first;
TStudent_Biodata_Node last;
int count;
}*TStudentList;
StudentList_Init(TStudentList studentList)
{
studentList->first=studentList->last=NULL;
studentList->count=0;
}
void StudentList_PushFirst(TStudentList studentList, char * name, char *id, int Age)
{
TStudent_Biodata_Node newNode = (TStudent_Biodata_Node) malloc(STUDENT_BIODATA_NODE_SIZE);
strncpy(newNode->studentName,name,STUDENT_NAME_SIZE);
strncpy(newNode->studentID,id,STUDENT_ID_SIZE);
newNode->age = Age;
//cout << "Inserting ..." << newNode->studentName << " : " << newNode->studentID << " : " << newNode->age << endl;
if (studentList->count ==0)
{
newNode->next = NULL;
studentList->first = studentList->last = newNode;
studentList->count=1;
}
else
{
newNode->next = studentList->first;
studentList->first = newNode;
studentList->count++;
}
}
void StudentList_PushLast(TStudentList studentList, char* name, char* id, int Age)
{
TStudent_Biodata_Node newNode = (TStudent_Biodata_Node) malloc(STUDENT_BIODATA_NODE_SIZE);
strncpy(newNode->studentName,name,STUDENT_NAME_SIZE);
strncpy(newNode->studentID,id,STUDENT_ID_SIZE);
newNode->age = Age;
// cout << "Inserting ..." << newNode->studentName << " : " << newNode->studentID << " : " << newNode->age << endl;
if (studentList->count ==0)
{
newNode->next = NULL;
studentList->first=studentList->last = newNode;
studentList->count=1;
}
else
{
newNode->next = NULL;
studentList->last->next = newNode;
studentList->last = newNode;
studentList->count++;
}
}
StudentList_Display( TStudentList studentList, char * msgStr=NULL)
{
cout << endl << endl;
if (msgStr!=NULL)
{
cout << "******************************************************************" << endl;
cout << msgStr << endl;
}
cout << "******************************************************************" << endl;
TStudent_Biodata_Node curPtr = studentList->first;
for (int iLoop=0; iLoop<studentList->count; iLoop++)
{
cout << curPtr->studentName << " " << curPtr->studentID << " " << curPtr->age << endl;
curPtr = curPtr->next;
}
}
void StudentList_Destroy(TStudentList studentList)
{
TStudent_Biodata_Node curPtr = studentList -> first;
for (int iLoop=0; iLoop<studentList->count; iLoop++)
{
studentList->first = studentList->first->next;
free(curPtr);
curPtr = studentList->first;
}
studentList->first=studentList->last=NULL;
studentList->count=0;
}
int main()
{
struct _TStudentList student_records;
StudentList_Init(&student_records);
char studentName[STUDENT_NAME_SIZE];
char studentID[STUDENT_ID_SIZE];
strcpy(studentName,"Patrick Baldwin");
int age=51;
strcpy(studentID,"52769-PNC");
StudentList_PushFirst(&student_records,studentName,studentID,age);
StudentList_Display(&student_records,(char*)"1st record");
strcpy(studentName ,"Clark N");
strcpy(studentID,"32809-OSC");
age=25;
StudentList_PushFirst(&student_records,studentName,studentID,age);
StudentList_Display(&student_records,(char*)"2nd record"); // Clark , Patrick
strcpy(studentName,"Amy Shannon Merrick");
age=36;
strcpy(studentID,"70524-DTN");
StudentList_PushLast(&student_records,studentName,studentID,age);
StudentList_Display(&student_records,(char*)"3rd record"); //Clark,Patrick,Amy Shannon
StudentList_Destroy(&student_records);
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
source code uploaded to RESOURCES section03/07/21