Question

In: Computer Science

Here, we will create a structure that resembles a university’s profile. The structure must contain 5...

Here, we will create a structure that resembles a university’s profile. The structure must contain 5 members:

- One member for number of undergraduate students

- One member for number of graduate students

- One member for number of classrooms

- One member for the name of the university (an array)

- One member for the term (fall, summer or spring; also an array)

Once you define a structure with these members (don’t forget to give your arrays a default length), go ahead and declare one structure of this type in main. Then, also inside main, initialize the members that aren’t arrays. After this, you will ask the user for the estimated lengths of the other two members. For example, “How many letters do we expect for the name of the university? ”. When you receive these two values (one for each array), make sure to check that they do not surpass the default length you gave each array. If any of these two surpass the default length(s), print out a message and exit the program (all of this is done in main as well).

Next, if the program didn’t ended, the next step is to initialize the arrays with the help of a function. You will 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). 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. Indicate the user to end with a dot.

You will have to call this function twice, a first time for the University’s name, and a second time for the term. Once you call this function two times, your structure will be fully initialized. All is left, is to print out all the members. Go ahead and print the non-array members. Then, use a function to print out the array members (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 and it should accept an array.

Use C code to answer this question.

Solutions

Expert Solution

#include <stdio.h>      // for scanf() and prinf() functions
#include <stdlib.h>     // for exit() function

#define NAME_SIZE 40
#define TERM_SIZE 8


struct UniversityProfile {

    int noOfUndergraduate;
    int noOfGraduate;
    int noOfClassrooms;
    char nameOfUniversity[NAME_SIZE];
    char term[TERM_SIZE];

};


void arrayInitializer(char []);         // Function to initialize the array members.
void printArrayMembers(char []);        // Funtion to print the array members.

int main() {
    
    struct UniversityProfile profile1 = {.noOfUndergraduate = 2500, .noOfGraduate = 1200, .noOfClassrooms = 800};

    int nameSize;
    int termSize;
    
    // Asking the user for the estimated lengths of the two arrays.
    printf("How many letters do you expect for the name of the university?\n");
    scanf("%d", &nameSize);
    printf("How many letters do you expect for the term?\n");
    scanf("%d", &termSize);

    // Checking if the size provided by the user do not surpass the default length
    if ((nameSize >= 40) || (termSize >= 8)) // Taking equality in the condition so, to have space for the '\0' character.
    {
        printf("ERROR: Your provided sizes is more than the nameSize or termSize");
        exit(1);
    }

    // Calling the array initializer function to intialize the array members.
    arrayInitializer(profile1.nameOfUniversity);
    arrayInitializer(profile1.term);
    
    // Printing all structure members.
    printf("Number of Undergraduates: %d\n", profile1.noOfUndergraduate);
    printf("Number of Graduates: %d\n", profile1.noOfGraduate);
    printf("Number of Classrooms: %d\n", profile1.noOfClassrooms);
    printf("Name of University: ");
    printArrayMembers(profile1.nameOfUniversity);
    printf("Term: ");
    printArrayMembers(profile1.term);

    return 0;
}

void arrayInitializer(char arr[]) {
    printf("Enter the string you want to set(Press . to end): \n");
    
    // This will make sure that character newline and whitespaces are taken until '.' followed but newline is encountered
     scanf("%[^.]%*c", arr);

    // You can use getche() in a loop by including conio.h if you are using MS DOS compilers.
    // In GCC compilers conio.h is not defined.    
}

void printArrayMembers(char arr[]) {
    printf("%s\n", arr);
}

OUTPUT:


Related Solutions

MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a...
MUST BE DONE IN C (NOT C++)) Here, we will create a structure that resembles a university’s profile (you can pick any university name, just so long as the program runs properly). The structure must contain 5 members: - One member for number of undergraduate students - One member for number of graduate students - One member for number of classrooms - One member for the name of the university (an array) - One member for the term (fall, summer...
Create an ANOVA and regresion problem, must contain steps and answers.
Create an ANOVA and regresion problem, must contain steps and answers.
to create an effective and efficient terrorist group profile, you must be sure to include the...
to create an effective and efficient terrorist group profile, you must be sure to include the following information: Aliases Bases of Operation Date Formed Strength/Number of members Organizational Structure Classification (i.e. Religious, Nationalist, etc.) Is there a leader? Provide a photo of the group leader Group Leader Demographics (i.e. DOB, Place of Birth, Citizenship Height, Weight, Eyes, Languages, etc.) Is there a reward for the capture of the group leader? If so, how much is the reward? Financial Sources Founding...
(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with...
(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with arrays. You will have to create your own structure. However, make sure to meet these guidelines: - Give the structure whichever name you want. - It must have at least 3 members. - Two of the members must be arrays. - Your members should be of at least two different data-types. In other words, your members cannot be integers only (or floats, or doubles…)....
Al Qadea create an effective and efficient terrorist group profile, you must be sure to include...
Al Qadea create an effective and efficient terrorist group profile, you must be sure to include the following information: Aliases Bases of Operation Date Formed Strength/Number of members Organizational Structure Classification (i.e. Religious, Nationalist, etc.) Is there a leader? Provide a photo of the group leader Group Leader Demographics (i.e. DOB, Place of Birth, Citizenship Height, Weight, Eyes, Languages, etc.) Is there a reward for the capture of the group leader? If so, how much is the reward? Financial Sources...
A person has to create a code. The code must contain exactly 6 letters. The first...
A person has to create a code. The code must contain exactly 6 letters. The first letter must be a vowel that is not an E or I. The second letter must be either a J, K, or L. The third letter must be a consonant that is not a G or R. The fourth letter must be a vowel that is not an I. The fifth letter must be a consonant. If repetition of letters are not allowed, how...
A person has to create a code. The code must contain exactly 7 letters. The first...
A person has to create a code. The code must contain exactly 7 letters. The first letter must either a N, P, R, or T. The second letter must be a vowel that is not I, O, or U. The third letter must be a consonant that is not a D, F, H, or J. The fourth letter must be a vowel that is not an O or U. The fifth letter must be a consonant that is not a...
Objective: Create a webpage with a simple quiz. Instructions: The webpage must contain at least ten...
Objective: Create a webpage with a simple quiz. Instructions: The webpage must contain at least ten simple questions as a quiz. The user must be able to answer the questions in the input boxes and finally click on a Submit button to get a final score. The questions must be such a way that some answer formats must cover all the following types: A number A string An expression (e.g. 2+3) If the user does not answer a question and...
What three financial statements have we created? In what order must we create them? Why must...
What three financial statements have we created? In what order must we create them? Why must they be created in that order?
We need a Stock and Bond trading application. Here is what is required: Create Menu with...
We need a Stock and Bond trading application. Here is what is required: Create Menu with the options organized as below: ******************************************************************************** A. Buy Bonds B. Sell Bonds C. Buy Stocks D. Sell Stocks E. Short Stock Sale    X. Exit Here are the steps involved. Create a char variable named menuChoice. Display the menu as described above. Prompt for the menu choice (A-E,X) (Assume the input will be uppercased). Use an IF statement to validate that the choices are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT