In: Computer Science
Remember we're only using C to program this. That does not mean C++, just no!
This one's long so pay attention. You are going to create a structure that resembles a university’s profile (Any university name is ok, just pick one). This structure must contain 5 members. They are listed here:
1. One member for number of undergraduate students
2. One member for number of graduate students
3. One member for number of classrooms
4. One member for the name of the university (use an array)
5. One member for the term (fall, summer or spring; also an array)
Once you define a structure with these members (make sure your array's have a default length), you will declare one structure of this type in main. Then, also inside main, initialize the members that aren’t arrays. Next, you are going to ask the user for the estimated lengths of the other two members. In an example here, “How many letters do we expect for the name of the university?”. When you receive these two values (one for each array), be sure to check that they do not surpass the default length you gave to each array. If any of these two happen to surpass the default lengths, you will print out a message and exit the program (this will all be done in main).
Now, if the program didn’t end, the next step is to initialize the arrays with the help of a function. You must initialize one array at a time (keep in mind that these arrays are members of a structure, so you will have to manipulate them a little different than before, but it is do-able). This function will not return anything and it will accept an array. Inside the function, you will scan for a set of characters given by the user. Lastly, indicate the user to end with a "dot" (you must recall what a "dot" is in terms of programming).
Call this function twice, the first time for the University’s name, and the second time for the term (spring, summer, or fall). Once you have called this function two times, your structure will be fully initialized. Now all that is needed, is to print out all the members. You are going to print the non-array members. Then, use a function to print out the array members (like before you will also have to call this function twice; once for the University’s name and once for the term). This function should not return anything, but it should accept an array.
In the below we have define a structure and its given mambers.
Define functions to initialize the array and print the array
This is the whole code of the given problem.