Write a C++ program that includes the following:
Define the class Student in the header file Student.h.
#ifndef STUDENT_H
#define STUDENT_H
#include
#include
using namespace std;
class Student
{
public:
// Default constructor
Student()
{
}
// Creates a student with the specified id and name.
Student(int id, const string& name)
{
}
// Returns the student name.
string get_name() const
{
}
// Returns the student id.
int get_id () const
{
}
// Sets the student name.
void set_name(const string& name)
{
}
// Sets the student id.
void set_id(int id)
{
}
// Prints the student id and name.
void print_student() const
{
}
private:
// student name
string name;
// student id
int id;
};
struct NodeType
{
Student student;
NodeType* next;
NodeType(): student(), next(nullptr)
{}
NodeType(const Student& s): student(s), next(nullptr)
{}
};
#endif
Impletment the class Student in the file Student.h.
The main() function is contained in the file lab02.cpp. The main() function,
Declares a pointer students which points to NodeType.
Prompts the user to enter a student information (id and name) and adds this student in the linked structure, stops adding the students when the user enters 0 as a student id.
Prompts the user to enter the student id to be removed, and remove the student from the linked structure.
Displays all students added in the linked structure.
The expected result:
Enter the student id: 1101
Enter the student name: Taylor
The student is added
Enter the student id: 1102
Enter the student name: Smith
The student is added
Enter the student id: 1103
Enter the student name: Alice
The student is added
Enter the student id: 1104
Enter the student name: Tom
The student is added
Enter the student id: 0
The student id to be removed: 1102
The student is removed
The students are:
1104 Tom
1103 Alice
1101 Taylor
Compile
This lab exercise should be put under cse330/lab02 subdirectory.
$g++ -c Student.h
$g++ -c lab02.cpp
$g++ lab02.o -o lab02
$./lab02
Hand In
Student.h: the header file.
lab02.cpp: the client test file containing main() funcion.
lab02result: the script file which captures the result.