Question

In: Computer Science

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 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" (be sure you understand what a dot is in programming).

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.

Solutions

Expert Solution

#include<stdio.h>
#include<stdlib.h>//for exit()

struct Edu
{
   int ug;
   int g;
   int class;
   char uni[100];
   char term[100];
};//declaration of structure

void initialize(char arr[], n)//method to initialize arrays
{
   arr= new int [n];
   printf("Enter the name followed by a dot to mark the end: ");
   scanf("%s", arr);
}

void display(int ug, int g, int class, char uni[], char term[])//method to display the structure values
{
   printf("No. of Undergraduates: %d", ug);
   printf("No. of Graduates: %d", g);
   printf("No. of Classes: %d", class);
   printf("Name of university: %s", uni);
   printf("Name of term: %s", term);
}

  
int main()
{
   int n;
   Edu A;
   A.ug=0;
   A.g=0;
   A.class=0;

   printf("Enter the no.of undergraduates");
   scanf("%d", &A.ug);
   printf("Enter the no.of graduates");
   scanf("%d", &A.g);
   printf("Enter the no.of classes");
   scanf("%d", &A.class);
   printf("How many letters do we expect for the name of the university?");
   scanf("%d", &n);
   if(n<=100)//if the given the size is leserthan or equal to the default size i.e. 100
       initialize(A.uni, n);
   else
       exit(0);

   printf("How many letters do we expect for the name of the term?");
   scanf("%d", &n);
   if(n<=100)
       initialize(A.term, n);
   else
       exit(0);

   display(A.ug, A.g, A.class, A.uni, A.term);

   return 0;

}//end of main()


Related Solutions

(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…)....
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of x students’ grades (grades will be stored in an array). To do so, please follow these guidelines: - Your program should ask the user for the number of students that are in the class. This number should help you declare your array. - Use the function seen in class to scan the grades of the array. In other words, we will populate the array...
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add...
MUST BE DONE IN C (NOT C++) In this task, using a function, we will add a range of values of an array. The range will be determined by the user. For example, if I have the following array … 1.5 -5.6 8.9 4.6 7.8 995.1 45.1 -5964.2 … and the user tells me to add from the 3rd element to the 6th element, my program would add the values 8.9, 4.6, 7.8 and 995.1. To do so, please follow...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases in which the initial unit is Fahrenheit or something not recognizable. Your program should incorporate Fahrenheit to Celsius, Fahrenheit to Kelvin and unknown initial units (display an error message for this last one). You must use functions to calculate Fahrenheit degrees.
(MUST BE DONE IN C (NOT C++)) Instead of using two different variables, define a structure...
(MUST BE DONE IN C (NOT C++)) Instead of using two different variables, define a structure with two members; one representing the feet and the other one representing the inches. You will also use three functions; one to initialize a structure, another one to check the validity of its values and one last one to print them out. First, go ahead and define your structure. Next, declare a structure of this type inside main. Then, call your first function (this...
(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure...
(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure you understood the concept of “the dot” in programming. Go ahead and declare an array of characters with a default length (whichever length you want, it's fine). Next, you want to ask the user for a phrase and store the characters in your array, but before you do that, ask the user for an estimated length of the array. If the length given is...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches....
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches. First, ask the user for the name of students they have in their class. Then, using a loop, you will ask for each student’s height. However, you will have to use two separate variables, one for feet and one for inches. Then, you will have to call two functions. The first function will check if the values entered are valid (check if number of...
MUST BE DONE IN C (NOT C++) This program should utilize the basics of strings. First,...
MUST BE DONE IN C (NOT C++) This program should utilize the basics of strings. First, declare and initialize a string. You can name the variable whichever way you want and you can initialize it to whichever value you want. Then, use a for loop to print its characters; one at a time, until you reach the null character. After this, go ahead and declare a second string (since you are not initializing it right away, you will have to...
(MUST BE DONE IN C (NOT C++)) Define two different structures at the top of your...
(MUST BE DONE IN C (NOT C++)) Define two different structures at the top of your program. Define each structure with exactly three members (each member has to be a different datatype). You may set them up whichever way you want. Don’t forget your semicolons. - Inside main, declare two structures. One for each of the two structures you defined. - Then, initialize each one of the members manually (the three members of your first structure and the three elements...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT