Question: Part 2 Structs and Arrays (65 points). In this assignment, we will be making a program that reads in students information, and create a classroom
Part 2 Structs and Arrays (65 points).
In this assignment, we will be making a program that reads in students information, and create a
classroom seating arrangement with a number of rows and columns specified by a user. Then it
will attempt to assign each student to a seat in an classroom.
Use the file homework_part_2.c (attached at the end of this document). Complete the file and
include all the following requested code in the file homework_part_2.c
Step 1.
First, you need to create a structure student. It should contain two variables, last_name (char
[30]) and first_name (char [30]). In addition, the following functions should be defined.
Function Description
void student_init_default
(struct student *s)
Assign the default string " ??? " to both variables,
last_name and first_name.
void student_init
(struct student *s, char *info)
Use the strtok function to extract first name and
last name from the variable student, then assign
them to each instance variable of the student
structure. An example of the input string is:
David/Johnson
void student_to_string (struct student *s) It prints the initial character of the first name, a
period, the initial character of the last name, and a
period. An example of such string for the student
David Johnson is:
D.J.
Step 2.
You will be creating a structure called classroom_seating in the same code file. The
structure classroom_seating will contain a 2-dimensional array called "seating" of student type.
Define the following functions:
Function Description
void classroom_seating_init
(int rowNum, int columnNum,
struct classroom_seating *a )
It instantiates a two-dimensional array of the size
"rowNum" by "columnNum" specified by the
parameters inside the struct a. Then it initializes each
student element of this array using the
student_init_default function. So, each student will
have default values for its instance variables.
int assign_student_at
(int row, int col,
struct classroom_seating *a,
struct student* s)
The function attempts to assign the "s" to the seat at
"row" and "col" (specified by the parameters of this
function). If the seat has a default student, i.e., a student
with the last name "???" and the first name "???", then
we can assign the new student "s" to that seat and the
method returns true. Otherwise, this seat is considered to
be taken by someone else, the method does not assign
the student and return 0 (false).
int check_boundaries
(int row, int col,
struct classroom_seating *a)
The function checks if the parameters row and col are
valid. If at least one of the parameters "row" or "col" is
less than 0 or larger than the last index of the array (note
that the number of rows and columns can be different),
then it return 0 (false). Otherwise it returns 1 (true).
void classroom_seating_to_string
(struct classroom_seating *a )
It prints information of the "seating". It should show the
list of students assigned to the seating using the
student_to_string function (it shows initials of each
student) and the following format:
The current seating
--------------------
D.J. ?.?. E.T..
?.?. ?.?. S.W.
T.C. A.T. ?.?.
Please see the sample output listed below.
After compiling the homework_part_2.c file, you need to execute it.
#include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
