a. Create an array of 15 student records that should not be sorted. b. Create a
ID: 3890880 • Letter: A
Question
a. Create an array of 15 student records that should not be sorted.
b. Create a liked list of 15 student records. Each node is a node
of one student record from the above unsorted array.
(Append Function)
c. Each student record consists of student ID, student name, Student address, and GPA.
d. The student records must be defined as student object class with member functions. (No class definition will be no credit for the project.)
e. Execution and output:
1. Display the student records in the unsorted array
2. Display the student records from the unsorted linked list
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
class StudentRecords
{
private:
int student_ID;
string student_name;
string Student_address;
float GPA;
StudentRecords *next;
public:
void setStudentRecords(int std_ID,string std_name, string std_address, float std_GPA){
student_ID=std_ID;
student_name=std_name;
Student_address=std_address;
GPA=std_GPA;
}
void getStudentRecords(){
cout<<student_ID<<" "<<student_name<<" "<<Student_address<<" "<<GPA<<endl;
}
void append(StudentRecords *link){
next=link;
}
//Helps to travell from root to end of the linked list: at the last element next value presents as null
StudentRecords& travel(StudentRecords *link){
return link.next;
}
};
int main()
{
int i,std_ID;
string std_name,std_address;
float std_GPA;
//Student record array to store individual student record
StudentRecords studentArray[3];
for(i=0; i<3; i++){
cout << "Please enter student_ID,student_name,Student_address and GPA" << endl << endl;
cin>>std_ID;
cin>>std_name;
cin>>std_address;
cin>>std_GPA;
studentArray[i].setStudentRecords(std_ID,std_name,std_address,std_GPA);
cout << "Student record inserted successfully" << endl << endl;
}
//1. Display the student records in the unsorted array
cout << "Below are the Student record inserted in the student array"<< endl;
for(i=0; i<3; i++){
studentArray[i].getStudentRecords();
}
//Linked list for student record. root will point the current position of the linked list always.
StudentRecords *root,*link;
//Assign linked list in the existing student record array
for(i=0; i<3; i++){
root=&studentArray[i];
studentArray[i].append(link);
link=&studentArray[i];
}
//2. Display the student records using linked list
link=root;
while(link!=NULL)
{
link->getStudentRecords();
link= link->travel(link);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.