Question
Please complete the following with C language. Thanks. 1. Use the following Guidelines Give identifiers semantic meaning and make them easy to read (examples num_students,
Please complete the following with C language. Thanks.
1. Use the following Guidelines
Give identifiers semantic meaning and make them easy to read (examples num_students, gross_pay, etc).
Use lower case word for all identifiers (variables, functions, objects). Separate words with underscore character
Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes structures, functions, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.
Use white space to make your program more readable.
For each file in your assignment, provide a heading (in comments) which includes:
The assignment number.
Its author (your name).
A description of what this program is doing.
2. Part 1. Primitive Types, Searching, Recursion.
a) Create a file homework_part_1.c
b) Create a function initialize_array that receives two parameters: an array of integers and the array size. Use a for loop and an if statement to put 0s in the odd positions of the array and 1s in the even positions. Hint: review pointers as parameters.
c) Create a function print_array that receives as parameters an array of integers and the array size. Use a for statements to print all the elements in the array. Hint: review pointers as parameters.
d) Create a function selection_sort that receives as parameters an array of integers and the array size, and order the array element in ascending order. Implement Selection Sort algorithm. It should be Selection Sort, not Bubble Sort, not Quick Sort, etc. If you do not remember selection sort, this link could be useful: https://goo.gl/hrAdMo
e) Create a recursive function that calculate and returns the factorial of a number. The function receives the number (integer number) as parameter
f) Copy the following main function in your class,
int main() { int a [10] = {3, 5, 6, 8, 12, 13, 16, 17, 18, 20}; int b [6]= {18, 16, 19, 3 ,14, 6}; int c [5]= {5, 2, 4, 3, 1};
// testing initialize_array print_array(a, 10); // print: 3, 5, 6, 8, 12, 13, 16, 17, 18, 20 initialize_array(a, 10); print_array(a, 10); // print: 1, 0, 1, 0, 1, 0, 1, 0, 1, 0
// testing initialize_array print_array(b, 6); // print: 18, 16, 19, 3 ,14, 6 selection_sort (b, 6); print_array(b, 6); // print: 3, 6, 14, 16, 18, 19
// testing factorial printf("Factorail of 5 - %d ", factorial (5)); //print: 120
c[0] = factorial (c[0]); c[1] = factorial (c[2]); print_array(c, 5); // print: 120, 24, 4, 3, 1
return 0; }
4. Part 2 Structs and Arrays.
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.
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:
After compiling the homework_part_2.c file, you need to execute it.
Sample Output: (the inputs entered by a user are shown in bold)
Make sure that your program works at least with this scenario.
CODE------
#include
struct student {
char last_name[30] ;
char first_name[30]; };
struct classroom_seating { struct student **seating;
}; void student_init_default (struct student *g ) {} void student_init (struct student *g, char *info) {} void student_to_string (struct student *g ) {} void classroom_seating_init (int rowNum, int columnNum, struct classroom_seating *a ) {} int assign_student_at (int row, int col, struct classroom_seating *a, struct student* g) {} int check_boundaries (int row, int col, struct classroom_seating *a) {} void classroom_seating_to_string (struct classroom_seating *a ) {}
void main() { struct classroom_seating classroom_seating; struct student temp_student;
int row, col, rowNum, columnNum; char student_info[30];
// Ask a user to enter a number of rows for an classroom seating printf ("Please enter a number of rows for an classroom seating."); scanf ("%d", &rowNum);
// Ask a user to enter a number of columns for an classroom seating printf ("Please enter a number of columns for an classroom seating."); scanf ("%d", &columnNum);
// classroom_seating classroom_seating_init(rowNum, columnNum, &classroom_seating);
printf("Please enter a student information or enter \"Q\" to quit.");
/*** reading a student's information ***/ scanf ("%s", student_info);
/* we will read line by line **/ while (1 /* change this condition*/ ){
printf (" A student information is read."); // printing information. printf ("%s", student_info); // student
student_init (&temp_student, student_info); // Ask a user to decide where to seat a student by asking // for row and column of a seat
printf ("Please enter a row number where the student wants to sit."); scanf("%d", &row);
printf("Please enter a column number where the student wants to sit."); scanf("%d", &col);
// Checking if the row number and column number are valid
// (exist in the theatre that we created.) if (check_boundaries(row, col, &classroom_seating) == 0) {
printf(" row or column number is not valid.");
printf("A student %s %s is not assigned a seat.", temp_student.first_name, temp_student.last_name);
} else { // Assigning a seat for a student if (assign_student_at(row, col, &classroom_seating, &temp_student) == 1){
printf(" The seat at row %d and column %d is assigned to the student",row, col); student_to_string(&temp_student); classroom_seating_to_string(&classroom_seating);
} else { printf(" The seat at row %d and column %d is taken.", row, col);
} }
// Read the next studentInfo printf ("Please enter a student information or enter \"Q\" to quit."); /*** reading a student's information ***/ scanf("%s", student_info);
} }
Function void student init default (struct student *s) Description 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.JStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started