Vous êtes sur la page 1sur 2

MACHINE

 EXERCISE  4  –  CLASSROOM  SEATING  ARRANGEMENT  

You  are  to  create  a  program  modeling/simulating  classroom  seating  arrangement.  The  idea  
is  that  a  classroom  is  composed  of  a  number  of  seats,  of  which  a  student  can  occupy  one  of  
those  seats.  A  student,  once  occupying  a  seat,  can  then  either  have  a  left  seatmate,  a  right  
seatmate,  or  both.    

Here  are  the  specifications  of  the  program  for  this  exercise:  

1)  Assume  that  the  classroom  has  23  seats  (and  consequently,  23  students),  positioned  as  
follows:  

1   2   3   4   5  
6   7   8   9   10  
11   12   13   14   15  
16   17   18   19   20  
21   22   23  
     
2)  Create  a  (object)  data  type  named  Classroom,  which  has  only  one  attribute:  seats.  

3)  Create  a  (object)  data  type  named  Student,  which  has  the  following  attributes:  student  
name,  seat  number,  left  seatmate,  right  seatmate.  Limit  the  student  name  to  100  characters.  

4)  Create  a  function  named  create_student  for  assigning  student  name,  and  additionally,  for  
designating  that  the  student  has  no  left  and  right  seatmates  (yet).  It  has  no  input  
parameters,  but  it  returns  a  Student  object  with  a  name.  The  function  should  prompt  the  
user  to  input  the  student’s  name.  

5)  Create  a  function  named  assign_seat  for  assigning  a  student  to  a  seat  inside  the  classroom.  
It  has  3  input  parameters:  classroom,  student,  and  seat  number.  It  should  not  return  
anything.  The  function  should  assign  a  student  to  the  seat  number  assuming  it  is  not  
occupied.  If  the  student  was  assigned  to  the  seat  successfully,  print  out  a  message  that  the  
student  (referred  to  by  its  name)  was  assigned  to  the  seat  number.  Otherwise,  print  a  
message  that  the  seat  number  is  occupied.  

6)  Create  a  function  named  count_free_seats,  which  returns  the  number  of  unoccupied  seats  
left  in  the  classroom.  It  takes  in  1  input  parameter:  classroom,  and  returns  an  integer  
representing  the  number  of  free  seats  left  in  the  classroom.  

7)  Create  a  function  named  get_student_info  that  prints  out  the  information  regarding  the  
student.  It  takes  in  1  input  parameter:  student.  It  does  not  return  any  value.  The  function  
should  then  print  out  the  name  of  the  student,  the  seat  number  the  student  is  occupying,  
and  the  names  of  the  student’s  left  and  right  seatmates.  If  the  student  has  not  yet  been  
assigned  as  seat,  print  out  a  message  that  the  student  has  not  yet  been  assigned  a  seat.  
Additionally,  if  the  student  has  no  left  and/or  right  seatmates,  specify  that  the  student  has  
no  left  and/or  no  right  seatmates.  

8)  Create  a  function  named  get_classroom_info  that  prints  out  the  information  of  the  seating  
arrangement  in  the  classroom.  It  takes  in  1  input  parameter:  classroom.  It  does  not  return  
any  value.  The  function  should  list  each  seat  number  and  the  name  of  the  student  occupying  
the  respective  seat.  If  there  is  no  student  occupying  the  seat,  print  out  that  the  seat  is  
unoccupied.  
9)  Use  the  following  as  the  template  main  function:  
main() {
Student students[23];
Classroom classroom;
int i;

for (i = 0; i < 23; i++) {


students[i] = create_student();
get_student_info(students[i]);
assign_seat(&classroom, &students[i], (23 – i));
printf(“The classroom has %d free seats left.\n”, count_free_seats(classroom));
}

get_classroom_info(classroom);

for (i = 0; i < 23; i++) {


get_student_info(students[i]);
}
}

Vous aimerez peut-être aussi