You are not allowed to use any build in libraries - you have to build them from
ID: 3663005 • Letter: Y
Question
You are not allowed to use any build in libraries - you have to build them from scratch and they have to be allocaed on the heap. PLEASE do not leave out the student class that is needed for this assignment. I posted this question earlier and it was answered assuming I already had a student class and a student.h file made.
Create a SSL (singly linked list) datastructure that will store Student objects with two private slots: String::StudentName and String::StudentUserName.
SSL operations:
-> void print() the list content by calling the Student ->print() function
-> void add(Student*) add an instance of a student object
-> ssl* split() will split the list in two halves. If the number of objects saved in the list are odd, then the original list pointer will have the floor(list size / 2) objects and the function returns a pointer to the second half of the list with the student objects. The split function will retan the pointer to the first unchanged - the first half, and the split function will return a pointer to the second half of the list as a new singly linked list.
Student operations:
-> print() will print the content of the student object.
1. Separate the business logic from the payload.
2. Provide a driver that illustrated how you tested your linked list and its functionality.
3. For C++ implementation, make sure you allocate the ssl and student object on the heap and when you terminate the driver's main routine, you correctly deallocate all memory.
Implement the following functionality of this challenge:
-Implementation in both Java and C++
-You cannot use built-in libraries (such as a linked list, vector etc.)
-Read-in unlimited number of students
-Implement all necessary setter, getter, and manipulation methods
-Allocate all data-structures on the heap (not the stack) (C++)
-Graceful program termination: deallocate all allocated memory before exiting application (C++)
Explanation / Answer
/*driver.java */
package student;
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
System.out.println("Enter the number of students: ");
int n=scan.nextInt();
SLL sll=new SLL(n);
for(int i=0;i<n;i++)
{
System.out.println("Enter the name: ");
String name=scan.nextLine();
System.out.println("Enter the user name: ");
String uname=scan.nextLine();
sll.add(name,uname);
}
sll.print();
}
}
/*Student.java*/
package student;
public class Student {
String StudentName;
String StudentUserName;
Student next;
public Student(String Name, String Uname)
{
StudentName=Name;
StudentUserName=Uname;
next=null;
}
public Student()
{
StudentName=null;
StudentUserName=null;
next=null;
}
public void print()
{
System.out.println("Name: "+StudentName);
System.out.println("Name: "+StudentUserName);
}
}
/*SLL.java*/
package student;
public class SLL {
Student start;
public int N;
public SLL(int n)
{
N=n;
start=null;
}
public void add(String name, String uname)
{
Student s=new Student(name,uname);
if(start==null)
{
start=s;
}
}
public void print()
{
for(int i=0;i<N;i++)
{
}
}
/*-> ssl* split() will split the list in two halves. If the number of objects
saved in the list are odd, then the original list pointer will have the
floor(list size / 2) objects and the function returns a pointer to the
second half of the list with the student objects. The split function
will retan the pointer to the first unchanged - the first half,
and the split function will return a pointer to the second half of the list
as a new singly linked list*/
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.