我是 C++ 的初学者,作业要求我们记录我们的代码(序言,以及函数的前置条件)。我想知道它们如何适用于我的学生课程?
特别是,序言到底是什么意思?对于我的 get 方法,前置条件和后置条件是什么?我有一种感觉他们真的是为了更高级的功能(这些谁改变了数据的价值)?
class Student:
{
public:
// Constructor for the student class, require 4 parameters
// In the order of string (first name), string (last name),
// integer (student ID), string (major)
Student(string myFirstName, string myLastName, int myID, string myMajor)
{
firstName = myFirstName;
lastName = myLastName;
uid = myID;
major = myMajor;
}
// Get function for the student's first name
// Return the student's first name
string getFirstName()
{
return firstName;
}
.....
private:
string firstName; // Student's first name
string lastName; // Student's last name
int uid; // Student's ID number in a number format
string major; // Student's major
};