Question

In: Computer Science

Please write a complete C coding program (NOT C++) that has the following: (including comments) -...

Please write a complete C coding program (NOT C++) that has the following: (including comments)

- declares two local integers x and y

- defines a global structure containing two pointers (xptr, yptr) and an integer (z)
- declares a variable (mst) by the type of previous structure
- requests the values of x and y from the user using only one scanf statement
- sets the first pointer in the struct to point to x
- sets the second pointer in the struct to point to y
- uses the structure to print out the values in x and y (do not print x and y values directly)

- Declare a variable (mstptr) that is a pointer to the structure and make it point to the structure you already declared (mst)

- Using the pointer to the structure set the integer z in the structure to the number 5.

- Using the pointer to the structure display the value of the integer and the values pointed to by the two pointers (must use -> operator)

Solutions

Expert Solution

#include<stdio.h>

struct Point // declare and define a structure named Point with elements as *xptr, *yptr and z

{
   int *xptr;
   int *yptr;
   int z;
};

int main()
{

   int x,y; // declare variables x and y

   struct Point mst; // declare structure element mst

   printf("Enter value of x and y : ");
   scanf("%d%d",&x,&y); // read x and y values
   mst.xptr = &x; // assign the first pointer in the struct to point to x
   mst.yptr = &y; // assign the second pointer in the struct to point to y

   printf("Printing the value using mst pointer\n"); // display x and y values using the pointer mst    
   printf(" x = %d\n",*mst.xptr);
   printf(" y = %d\n",*mst.yptr);
struct Point *mstptr=&mst; //Declare a variable mstptr that is a pointer to the structure

   mstptr->z=5;    //assign value 5 to z
   printf("\nPrinting the value using structure pointer\n");
   //display the values of x and y and z using structure point
   printf(" x = %d\n",*mstptr->xptr);
   printf(" y = %d\n",*mstptr->yptr);
   printf(" z = %d\n",mstptr->z);
   return 0;

}


Related Solutions

Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three integer values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a complete Java program, including comments in each method and in the main program, to...
Write a complete Java program, including comments in each method and in the main program, to do the following: Outline: The main program will read in a group of three int||eger values which represent a student's SAT scores. The main program will call a method to determine if these three scores are all valid--valid means in the range from 200 to 800, including both end points, and is a multiple of 10 (ends in a 0). If the scores are...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
Write a complete Java program, including comments in both the main program and in each method,...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...
Write a complete JAVA program, including comments (worth 2 pts -- include a good comment at...
Write a complete JAVA program, including comments (worth 2 pts -- include a good comment at the top and at least one more good comment later in the program), to process data for the registrar as follows: NOTE: Include prompts. Send all output to the screen. 1. Read in the id number of a student, the number of credits the student has, and the student’s grade point average (this is a number like 3.25). Print the original data right after...
PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as...
PLEASE PROVIDE COMMENTS ON STEPS Write a C++ program that modifies a string (null terminated) as follows: Consonants are positioned at the beginning of the string and vowels are moved to the end of the string. Example : Original string : washer New string : wshrae Note: The library string functions cannot be used. You must use pointers and the switch statement to execute this program. Assume that the vowels are a, e, i, o, and u. The modification has...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
Please answer the following by coding in R with comments ! Thank you!!! Evaluation of a...
Please answer the following by coding in R with comments ! Thank you!!! Evaluation of a square root is achieved using the sqrt() function, but a warning will be issued when the argument is negative. Consider the following code which is designed to test whether a given value is positive before checking whether the square root of the value is less than 5. testValue <-7 (testValue > 0) & (sqrt(testValue) < 5) ## [1] TRUE testValue <--7 (testValue > 0)...
Please answer the following by coding in R with comments ! Thank you!!! Evaluation of a...
Please answer the following by coding in R with comments ! Thank you!!! Evaluation of a square root is achieved using the sqrt() function, but a warning will be issued when the argument is negative. Consider the following code which is designed to test whether a given value is positive before checking whether the square root of the value is less than 5. testValue <-7 (testValue > 0) & (sqrt(testValue) < 5) ## [1] TRUE testValue <--7 (testValue > 0)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT