Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that illustrates your knowledge of pointers and objects. Create

ID: 3533247 • Letter: W

Question

Write a program that illustrates your knowledge of pointers and objects. Create a program that creates an array of objects. Create an array of pointers to these objects. Use a for loop to create the objects and load the values. The numbers should be generated using the rand() function. Use a while loop to list out the values using the pointer array.

The data attributes should be:

int value; char 'E' or 'O' for even and odd.
Have a function that determines whether the number is even or odd.
Write a program that illustrates your knowledge of pointers and objects. Create a program that creates an array of objects. Create an array of pointers to these objects. Use a for loop to create the objects and load the values. The numbers should be generated using the rand() function. Use a while loop to list out the values using the pointer array.

The data attributes should be:

int value; char 'E' or 'O' for even and odd.
Have a function that determines whether the number is even or odd.

Explanation / Answer

#include <iostream>

#include <cstdlib>

#include <cstdio>


typedef struct{

int value;

char ch;

}obj;


void EVENODD(obj* O)

{

if(O->value % 2 == 0)

O->ch = 'E';

else

O->ch = 'O';

}


int main()

{

obj O[10];

int i;

obj* point[10];

for(i=0;i<10;i++)

point[i] = &O[i];

for(i=0;i<10;i++)

{

point[i]->value = rand() 0;

EVENODD(point[i]);

}

for(i=0;i<10;i++)

printf("Number is %d and character is %c ",point[i]->value,point[i]->ch);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote