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

Consider the following declaration: struct name_type{ string first; char middle;

ID: 3552002 • Letter: C

Question

Consider the following declaration:


struct name_type{

string first;

char middle;

string last;

};



a)Declare two interger pointers, one called p, the other called s.


b)declare a pointer to the struct name_type.


c)Create a dynamic variable using p and a dynamic array of 100 intergers using s.


d)Read a value into your dynamic variable and then assign the value of the dynamic variable to all the 100 elements of the array - declare any additonal varible you need.


e) Create a dynamic structure variable using some_name.


f) Assign " Joe " to the member first of your dynamic variable, "C" to the member middle, and "Dibb" to the member last.


g) Delete the dynamic variable, the dynamic array and the dynamic structure variable.








Explanation / Answer

a> int *p, *s;


b>name_type *ptr;


c>p=new int();

s=new int[100];


d>cin>>*p;

for(int i=0;i<100;i++)s[i]=*p;


e>ptr = new name_type();


f>ptr->first="Joe";

ptr->middle='C'

ptr->last="Dibb"


g>delete p;

delete[] s;

delete ptr;