
Xiana Z.
asked 11/02/20Suppose you have to create a data structure to represent a "Student” where student is represented by "studid" whose data type is integer and "studname" whose data type is character array of size 40.
Suppose you have to create a data structure to represent a "Student” where student is represented by "studid" whose data type is integer and "studname" whose data type is character array of size 40. You have decided to create a "Student" link
list to store student information. Using the data type "Student" you, you need to create two students having their information as follows:
1st- ID 1001 Name: ALEX
2nd - ID=1002 Name: NICOLAS
Define the data node "Student and allocate memory and create and show the link list of two students.
1 Expert Answer

Patrick B. answered 11/03/20
Math and computer tutor/teacher
using namespace std;
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define STUDENT_NAME_LENGTH (40)
typedef struct _TStudent
{
int studID;
char studName[STUDENT_NAME_LENGTH];
} *TStudent;
#define STUDENT_SIZE (sizeof(struct _TStudent))
void Student_Init( TStudent student, int iStudentIdNum, char * studentName )
{
memset(student,0,STUDENT_SIZE);
student->studID = iStudentIdNum;
strncpy(student->studName,studentName,STUDENT_NAME_LENGTH);
}
void Student_Copy(TStudent studentDest, TStudent studentSource)
{
studentDest->studID = studentSource->studID;
strncpy(studentDest->studName,studentSource->studName,STUDENT_NAME_LENGTH);
}
void Student_Display(TStudent student, char * strMsg)
{
if (strMsg!=NULL)
{
cout << "*****************************************************" << endl;
cout << strMsg << endl;
}
cout << "**************************************************************" << endl;
cout << " student id # " << student->studID << endl;
cout << " student name >" << student->studName << "<" << endl;
}
void Student_SerializeToCSV(TStudent student, char * csvBuff)
{
sprintf(csvBuff,"%d,%s\n",student->studID,student->studName);
}
void Student_ParseCSV(TStudent student, char * csvBuff)
{
student->studID = atoi( strtok(csvBuff,","));
strncpy(student->studName,strtok(NULL,","),STUDENT_NAME_LENGTH);
}
int main()
{
char studentNames[][STUDENT_NAME_LENGTH]={"Alex",
"Nicholas",
"Amy Shannon",
"Darlene",
"Jennifer",
"Katie",
"Rachael",
"Sam",
"Teddy",
"Victoria",
"Dennis",
"Eddie",
"Craig",
"Francis",
"Gary",
"Patrick"
};
struct _TStudent students[16];
for (int iLoop=1001; iLoop<=1016; iLoop++)
{
char strMsg[25];
sprintf(strMsg,"Student Rec # %d of 16",iLoop-1000);
Student_Init(&students[iLoop-1001],iLoop,studentNames[iLoop-1001]);
Student_Display(&students[iLoop-1001],strMsg);
}
cout << endl;
char csvBuff1[STUDENT_SIZE*2];
char csvBuff2[STUDENT_SIZE*2];
Student_SerializeToCSV(&students[0],csvBuff1);
cout << csvBuff1 << endl;
Student_SerializeToCSV(&students[1],csvBuff2);
cout << csvBuff2 << endl;
struct _TStudent student;
Student_ParseCSV(&student,csvBuff1);
Student_Display(&student,(char*)"Parse student Rec #1");
Student_ParseCSV(&student,csvBuff2);
Student_Display(&student,(char*)"Parse student Rec #2");
}
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 RESROUCES section under this link11/03/20