studentlist.~cp

来自「一次作业练习」· ~CP 代码 · 共 86 行

~CP
86
字号
#include "StudentList.h"



//post: has constructed an empty StudentList-object
StudentList::StudentList()
{
       set_count(0);
}

//pre: student is a pointer to a Student-object
//post: student is added to the end of the array
void StudentList::add(Student* student)
{
 if(get_count()<CAPACITY)
 {
  data[get_count()]=student;
  set_count(get_count()+1);
 }
 //else
 //cout<<"The number of students are larger than capacity."<<endl;
}

//pre: the first line of fin contains the number of 
//     Students, the other lines contains each the data 
//     of one Student
//post: the Student-data have been read and stored in the 
//      list
void StudentList::read(istream& fin)
{
  int number;
  fin>>number;


  char major;
  Student* temp=NULL;

  for(int i=0; i<number; i++)   //according to the major read, creating CS student object and EE student object
  {
   fin>>major;
   if(major=='c')
    {
    temp= new StudentCS();
    temp->read(fin);
    add(temp);
    }
    else
   if(major=='e')
    {
    temp= new StudentEE();
    temp->read(fin);
    add(temp);
    }
    else
    {
      cout<<"ERROR: The information of No."<<i+1<<" student is wrong. Please check."<<endl;
      system("PAUSE");
      exit(0);
    }

  }
}

//post: the data of the students have been written to fout
void StudentList::write(ostream& fout)
{
 fout<<"Faculty  Student  Student-ID  Course  Course"<<endl;
 for(int i=0;i<get_count();i++)
 {
  data[i]->write(fout);
  fout<<endl;
 }
}

//get 'count' value
int StudentList::get_count()
{
 return count;
}

//set c as the 'count' value
void StudentList::set_count(int c)
{
 count=c;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?