Question

In: Computer Science

(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 of your second structure).

- Lastly, print out all six members with their respective message.

Notice the words “define”, “declare” and “initialize”. Using them properly with the guidelines in terms of programming is going to help a lot in understanding this problem.

Solutions

Expert Solution

Structure data type:

A structure is a user-defined data type that is a collection of different data types. The structure data member can be accessed by using the structure variable and dot operator or structure pointer variable and arrow operator.

The required program source code is given below:

#include <stdio.h>

//define structure
struct abc
{
//structure member
int a;
float b;
char c;
};

//define structure
struct def
{
//structure member
double d;
unsigned int e;
long int f;
};

int main()
{
//structure variable declaration
struct abc st;
struct def st1;
  
//initialize the structure member
st.a = 10;
st.b = 20.0f;
st.c = 'm';
  
st1.d = 2500;
st1.e = 32;
st1.f = 430;
  
//display the values of the structure member
printf("The structure members values are given below:\n");
printf("a = %d\n", st.a);
printf("b = %f\n", st.b);
printf("c = %c\n\n", st.c);
  
printf("d = %lf\n", st1.d);
printf("e = %u\n", st1.e);
printf("f = %ld\n", st1.f);
  
return 0;
}

OUTPUT:

The structure members values are given below:
a = 10
b = 20.000000
c = m

d = 2500.000000
e = 32
f = 430



Related Solutions

(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++) 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++) 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, 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 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++)) 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...
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++) 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++)) 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT