Question

In: Computer Science

Write a complete program (possible to compile) that: 1) declares two local integers x and y...

Write a complete program (possible to compile) that:
1) declares two local integers x and y
2) defines a global structure containing two pointers (xptr,yptr) and an integer (z)
3) Declares a variable (mst) by the type of previous structure
4) requests the values of x and y from the user using only one scanf statement
5) sets the first pointer in the struct to point to x
6) sets the second pointer in the struct to point to y
7) uses the structure to print out the values in x and y (do not print x and y values directly)

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

9) Using the pointer to the structure set the integer z in thestructure to the number 5.

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

C++ Coding Please and if you could put comments down that would be amazing!

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

#include<iostream>
using namespace std;

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

int main()
{
   //declare x and y
   int x,y;

   //object of structure
   struct Point mst;

   //ask for the input
   printf("Enter value of x and y : ");
   scanf("%d%d",&x,&y);

   //set x and y to pointer
   mst.xptr = &x;
   mst.yptr = &y;

   //print x and y using mst pointer
   printf("Printing the value using mst pointer\n");
   printf(" x = %d\n",*mst.xptr);
   printf(" y = %d\n",*mst.yptr);

   //define pointer to structure
   struct Point *mstptr=&mst;

   //set value to z
   mstptr->z=5;
   printf("\nPrinting the value using structure pointer\n");
   //print 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

Find two integers x,y (if possible) such that 32x + 47y = 1. Is there more...
Find two integers x,y (if possible) such that 32x + 47y = 1. Is there more than one solution?
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements....
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array. Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
You are required to write an interactive program that prompts the user for two integers X...
You are required to write an interactive program that prompts the user for two integers X and Y and performs the following tasks: Adds two numbers Subtracts Y from X Multiplies X and Y Divides X by Y Finds which numbers is larger X oy Y) Prints all the results (a , b, c, d, and e) Program requirements: -     The program should run as many times as the users wish -     The program should be fully documented. -   ...
y'=y-x^2 ; y(1)= -4 Write a MATLAB program that makes two plots of the solution to...
y'=y-x^2 ; y(1)= -4 Write a MATLAB program that makes two plots of the solution to the equation using the following values. Suggest you use nested loops instead of two different loops. Be sure to label your plots. a. x0 = 1.0, step size h = .2, number of steps n = 20. b. x0 = 1.0, step size h = .05, number of steps n = 80.
Write a complete Java program to solve the following problem. Read two positive integers from the...
Write a complete Java program to solve the following problem. Read two positive integers from the user and print all the multiple of five in between them. You can assume the second number is bigger than the first. For example if the first number is 1 and the second number is 10, then your program should output 5 10 Java must be grade 11 work easy to understand and not complicated code
Question Write a C program that asks the user to enter two integers x and n....
Question Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. and give me an output please use printf and scanf #include int main(void) {     //Declare required variables             //read two integers x , n from the keyboard                 //compute xn using for loop                     printf("< Your name >\n");...
C++ Program: Write another program (in C++) that will allocate a local static array of integers...
C++ Program: Write another program (in C++) that will allocate a local static array of integers and then a dynamic array of integers. Are they stored next to each other? You can examine this by examining the memory addresses where they are located. As described in class, on some systems the size of a dynamic array is actually stored in the bytes previous to a dynamically allocated array. Through some experiments on your own, try to see if this is...
Complete the following C# code that declares an array of 7 integers. The application allows the...
Complete the following C# code that declares an array of 7 integers. The application allows the user three options: l. to view the elements of array in reverse order, from the last to first position, 2. to choose a specific position to view, 3. quit the program
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the...
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the receipt of each new input value, displays the largest and smallest integers thus far. An input of 0 indicates the end of input values and is not an input value itself. Note that you do not need to keep all integers in memory.
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant...
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant float variable NJSALES_TAX; declares and initializes to 1000 an integer variable total; declares and initializes to zero a float variable grand_total; prompt and input on new line total; calculate grand_total to equal total plus (total*NJSALES_TAX); if grand_total <= 1000 print on new line “Grand total is less than or equal to 1000 it is $” and the grand_total to two decimal places; else if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT