create structs for students and a course using dynamic arrays,structs, conditionals, loops andpointers (yes, all of those things) and then printf the informationabout these structs to the screen. Yourprogram will:1. create three new data structures: student, course, andregistrar.2. create dynamic arrays of students and courses.3. print the contents of the registrar data structure.4. Modify a course and print the registrar data again to see thechange.5. Free the dynamic memory.
1)Figure out a way to work around the issue (eg for findCourseyou would just set the a1_studentpointers manually based on where you know the courses are in thearray).2) Comment out the function or code you wanted to write. Leavecomments in the code so we know what you were trying to do.
Introduction:
Your job (with some hints along the way) is to create a“university registrar” that has all information about students andcourses being offered.
Registrar:Our “registrar” is a struct that has 4 elements in it: a dynamicarray of student structs, the number ofthose students, a static or dynamic array of course structs, andthe number of courses.StudentThe student struct contains 3 elements: the student’s name (thiscan be a constant char pointer likeconst char* name = “Mehdi”), an int student ID, and a pointer tothe course the student istaking.....notice you normally take multiple classes but that justmakes the problem more difficult.
Here would be one possible definition of a student struct incase this helps you:
struct a1_student{const char* p_name;int studentID;a1_course* p_course;}
Here is a dataset to use (feel free to modify to use with yourstruct definitions):a1_studentIn students[6] ={ {"Mehdi Niknam", 12345, "BIT2400"},{"Joe Smith", 54321, "BIT2400"},{"Brian Brown", 11111, "BIT1400"},{"Raymond Rose", 55555, "BIT1400"},{"Gene Eric Student", 99999, "ITEC2100"},{"Amanda Spring", 88888, "BIT2000"} };
I made yet ANOTHER struct (of type a1_studentIn) and namedthearray of a1_studentIn structs students. Here is the definition ofa1_studentIn:struct a1_studentIn{const char* name;unsigned int id;const char* courseName;};
You will then make an a1_student struct with a pointer to theappropriate course matching that name(the instructions are in part 1).
Course:A course struct has 3 elements: a const char string name, a floatclass average, and a positive intmaximum enrollment.
Here is a set of courses you can try:a1_course courses[4] = { {"BIT2400", 71.0, 90},{"BIT1400", 52.7, 140},{"ITEC2100", 85.3, 15},{"BIT2000", 85.3, 15} };This is an array of 4 a1_course structs and the array is namedcourses.
Coding:1. Define three structs outside the main function: a1_student,a1_studentIn, and a1_course basedon the instructions above....you can change the struct names but Iam calling them that.2. Add the above datasets (or something similar) to your mainfunction.3. Your a1_student array (the one with pointers) should be adynamic array and based on thea1_studentIn dataset. You must use malloc or calloc to do this. Youcan’t use new and it can’tbe a static array without losing some points.4. Make sure your a1_student array is freed at the end of the mainfunction.• You will also need a bit if statement to put most of the code in,just in case the call tomalloc/calloc returns NULL.5. Write a function findCourse that takes an a1_course array, thesize of that array and the c-stringcourse name as parameters. The function returns a pointer to thecourse matching the name orNULL if that string doesn’t match a course in the array.6. Use findCourse to make sure your a1_student array has thecorrect pointers set up.7. <Optional> You may want to write a function printStudentsthat takes an a1_student array andthe size of the array as parameters and returns nothing (void). Thefunction itself calls printfstatements to output the useful information about thestudents.8. Write your name at the top of the file.9. Make sure you write your code a little bit at a time and test itbefore moving on.....you can useprintStudents to help you test your code for example.
Part 2: Registrar10. Create the registrar struct as described above.11. <Optional> I created a function named printCourseInfowhich took an a1_course and two c-strings (two const char* named pretext and postText) as parameters.The function then printsout all relevant information about a course in an easy-to-readformat.• I did this because I kept having to output course informationboth for students and forthe courses themselves. It was much easier this way.12. Write a function named numRegisteredStudents that takes anarray of a1_students, thenumber of students and a pointer to a particular a1_course asparameters. The function willreturn an unsigned int representing the number of students takingthat class. For example• unsigned int num1400Students = numRegisteredStudents(students, 6,&courses[1])results in num1400Students being 2 (there are 2 students takingcourse 1: {"BIT1400",52.7, 140}13. Write a function named printRegistrar that takes a registrarstruct and prints informationabout all students and all courses.• Requirement: Your printRegistrar function must output allinformation about eachstudent and each course. In addition, the COMPLETE courseinformation associatedwith each student must be printed out. See the sample output belowfor an example.14. OK. Now to prove your student struct has a pointer in it. Inyour main method do thefollowing:• Make sure your stucts are set up correctly.• Call printRegistrar to confirm your data looks correct.• Modify one of your courses to increase the enrollmentmaximum.• Call printRegistrar again. See that the numbers have changed forthe studentWITHOUT changing any of the student structs.
Microsoft Visua Sudic Debug Console The number of students registered in 81124e0 is 2 ere are the students: [(Hendi. Nikram 12345 taking | Course DIT2400 Max Enrollment: 90, Average: 71.000000 (Joe Smith 54321 taking (Orig Brown 11111 taking course BIT1400 Max Enrollment: 140, Average: 52.7000eel (Raymond Rose 55555 taking (oine Eric stucent 99999 taking Courts ITFC2100 Naz Enrollment: 16, avarage: 55.30000] (Amanda Springting ] Here are the 4 courses: 0 Course BIT2400 Max Enrollment: se. Average: 71.000000 Course BIT1439 Max Enrollment: 140, Course ITEC2100 Max Enrollmen L: 15. Course BIT2000 Max Enrollment: 15. Average: 85.300000 Average: 52.700000 Average: 85.300000 Here are the 6 students: [(Hehdi. Nikram 12345 taking | Course BIT2100 Max Enrollment: 150, Average: 71.000000) (Joe Smith 54321 taking (Bri an Brown 11111 taking | Course BIT1400 Max Cerullmani: 140, Average: 52.700900) (Raymund Rose 55555 Laking (damni triu Sausant 99999 Laking Course ITEC2:00 Max Enrollment: 15. Average: 85.360000) (Amanda Spring 88188 taking ] here are the 4 courses: Course BIT2430 Max Enrollment: 150, Average: 71.000000 Cource BIT1430 Max Enrollment: 140, 52.700008 Avarage Course ITEC2100 Max Enrollment: 15 Average: 85.300000 Course BIT2009 Max Enrollment: 15, Average: 85.300000 C:\Users\a{knasourcereposTutorial1Debug'Tutorial1.exe (process 2106) exited with code 8. To automatically close the console when debugging stops, enable Teals->Options-Debugging-Automatically close the conscle when debugging st PS. Press any key to close this window...
create structs for students and a course using dynamic arrays, structs, conditionals, loops and pointers (yes, all of th
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am