Esempio n. 1
0
Data::Data(int T, int S, std::vector<int> c, int E, int P, int X, std::vector<std::vector<int>> a, std::vector<std::vector<int>> b) :
		T(T),
		S(S),
		c(c),
		E(E),
		P(P),
		X(X),
		a(a),
		b(b),
		v(countStudents(X,a))
{}
REPLY* runAddc(COMMAND cnode,STUDENT *shead,COURSES *chead){
  REPLY *rtemp;
  int k;
  STUDENT *studentp;
  STUDENT *current;
  STUDENT *temp;
  COURSES *coursep;
  int i;
  if((rtemp = malloc(sizeof(REPLY))) == NULL){
    fprintf(stderr,"Error occured with malloc");
    exit(1);
  }
  if((coursep =getCourse(chead,cnode.courseId)) !=NULL){
    if((studentp = getStudent(shead,cnode.string)) !=NULL){
      k = 0;
      while(studentp->courseIds[k] != -1){
	if(k >=MAX_CLASSES){
	  rtemp->status = 0;
	  return rtemp;
	}
	if(studentp->courseIds[k] == cnode.courseId){
	  rtemp->status = 0;
	  return rtemp;
	}
	k++;
      }
      studentp->courseIds[k] = cnode.courseId;
      studentp->numCourses++;
      rtemp->status = 1;
      return rtemp;
    }
    else if(studentp == NULL){
      if((countStudents(shead))+1 >100){
	rtemp->status = 0;
	return rtemp;
      }
      else{
	current = shead;
	while(current->next !=NULL){
	  current = current->next;
	}
	if((temp = malloc(sizeof(STUDENT))) == NULL){
	  fprintf(stderr,"Error occured with maloc\n");
	  exit(1);
	}
	strcpy(temp->name,cnode.string);
	temp->numCourses = 1;
	temp->next = NULL;
	current->next = temp;
	for(i = 1; i < MAX_CLASSES;i++){
	  temp->courseIds[i] = -1;
	}
	temp->courseIds[0] = cnode.courseId;
	rtemp->status = 1;
	return rtemp;
      }
    }
  }
  else if(coursep == NULL){
    rtemp->status = 0;
    return rtemp;
  }
  rtemp->status = 1;
  return rtemp;
 
}