Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please write the code in language C using the following instructions, make sure the code runs and compiles on brightspace A review of BIT 1400

please write the code in language C using the following instructions, make sure the code runs and compiles on brightspace

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

A review of BIT 1400 Assignment deliverable: You will create structs for students and a course using dynamic arrays, structs, conditionals, loops and pointers (yes, all of those things) and then printf the information about these structs to the screen. Your program will: 1. create three new data structures: student, course, and registrar. 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 the change. 5. Free the dynamic memory. The TAs should be able to run your program with a different dataset and your code should still work and output the expected information. Important Policy: If you can't get a function or task to work in the assignment, there is no need to panic. Your code still needs to compile but you can get lots of partial credit for an attempt and still do the rest of the assignment. 1. Figure out a way to work around the issue (eg for findCourse you would just set the a1_student pointers manually based on where you know the courses are in the array). 2. Comment out the function or code you wanted to write. Leave comments in the code so we know what you were trying to do. You will get pointers for your plans and your attempt. Commenting out the code also means things still compile. Your submitted code should always compile (or you won't get the code running/testing points) but you certainly won't get 0 . You can also get points for reasonable attempts. You should still submit your work well before the deadline and submit again when finished. Learning Objectives: By completing the assignment, you will: - Refresh your knowledge of dynamic and static arrays, pointers, structs, and basic data types. - Gain improved efficiency and competency at reading provided C code. - Gain experience reading online documentation so you can call functions you did not write (I'm sure you don't remember everything from 1400) - Test your code to ensure it works as expected. - ......become more re-acquainted with general format of my assignments. Related Lecture Material: Lectures 1 and 2 particularly c-strings, structs, pointers, and linked lists. Introduction This assignment reviews what you learned in BIT 1400. Your job (with some hints along the way) is to create a "university registrar" that has all information about students and courses being offered. Obviously, this is a toy example and this could be any pairing of things like Netflix users and recommended movies or games and game systems. Registrar Our "registrar" is a struct that has 4 elements in it: a dynamic array of student structs, the number of those students, a static or dynamic array of course structs, and the number of courses. Student The student struct contains 3 elements: the student's name (this can be a constant char pointer like const char* name = "Mehdi"), an int student ID, and a pointer to the course the student is taking.....notice you normally take multiple classes but that just makes the problem more difficult. Here would be one possible definition of a student struct in case this helps you: Here is a dataset to use (feel free to modify to use with your struct definitions): I had to do something sneaky here. I made yet ANOTHER struct (of type a1_studentIn) and named the array of a1_studentIn structs students. Here is the definition of a1_studentIn: struct a1_studentln \{ const char* name; unsigned int id; const char* courseName; \}; You will then make an a1_student struct with a pointer to the appropriate course matching that name (the instructions are in part 1). Course A course struct has 3 elements: a const char string name, a float class average, and a positive int maximum enrollment. Here is a set of courses you can try: \[ \begin{array}{c} \text { a1_course courses[4] }=\{\{" B I T 2400 ", 71.0,90\}, \\ \{\text { 'BIT1400", 52.7, 140\}, } \\ \{\text { 'ITEC2100", 85.3,15\}, } \\ \text { \{"BIT2000", 85.3,15\}\}; } \end{array} \] This is an array of 4 a1_course structs and the array is named courses (very original names I know). This assignment consists of two parts: 1. The midway submission of part 1 is not graded but given to encourage you to work ahead of the deadline (if you claim the assignment took too long, I will check if you submitted this). 2. The final submission .cpp file including part 2. Part 1: Setup 1. Create a new empty project in Visual Studio (NOT a Hello World console example). 2. Make a new .cpp file named A1CReview_S22.cpp - The 4> should be the last 4 numbers of your Carleton ID....this should keep your ID safe yet makes cheating harder. - Create a new main method. Make sure your code compiles even if it does nothing. Coding 3. Define three structs outside the main function: a1_student, a1_studentIn, and a1_course based on the instructions above....you can change the struct names but I am calling them that. 4. Add the above datasets (or something similar) to your main function. 5. Your a1_student array (the one with pointers) should be a dynamic array and based on the a1_studentIn dataset. You must use malloc or calloc to do this. You can't use new and it can't be a static array without losing some points. 6. Make sure your a1_student array is freed at the end of the main function. - You will also need a bit if statement to put most of the code in, just in case the call to malloc/calloc returns NULL. 7. Write a function findCourse that takes an a1_course array, the size of that array and the c-string course name as parameters. The function returns a pointer to the course matching the name or NULL if that string doesn't match a course in the array. 8. Use findCourse to make sure your a1_student array has the correct pointers set up. 9. You may want to write a function printStudents that takes an a1_student array and the size of the array as parameters and returns nothing (void). The function itself calls printf statements to output the useful information about the students. 10. Write your name at the top of the file. 11. Make sure you write your code a little bit at a time and test it before moving on.....you can use printStudents to help you test your code for example. Part 2: Registrar 12. Create the registrar struct as described above. 13. I created a function named printCourselnfo which took an a1_course and two cstrings (two const char* named pretext and postText) as parameters. The function then prints out all relevant information about a course in an easy-to-read format. - I did this because I kept having to output course information both for students and for the courses themselves. It was much easier this way. 14. Write a function named numRegisteredStudents that takes an array of a1_students, the number of students and a pointer to a particular a1_course as parameters. The function will return an unsigned int representing the number of students taking that class. For example - unsigned int num1400Students = numRegisteredStudents(students, 6, \&courses[1]) results in num1400Students being 2 (there are 2 students taking course 1: \{"BIT1400", 52.7,140} 15. Write a function named printRegistrar that takes a registrar struct and prints information about all students and all courses. - Requirement: Your printRegistrar function must output all information about each student and each course. In addition, the COMPLETE course information associated with each student must be printed out. See the sample output below for an example. 16. OK. Now to prove your student struct has a pointer in it. In your main method do the following: - Make sure your stucts are set up correctly. - Call printRegistrar to confirm your data looks correct. - Modify one of your courses to increase the enrollment maximum. - Call printRegistrar again. See that the numbers have changed for the student WITHOUT changing any of the student structs. Notes: - If you are confused, please ask clarification questions on the forum (don't give your code or give away answers). This requires you to start working early. - Questions and instructions can seem obvious to me but make no sense to students and everyone is confused until someone asks. Please ask

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions