Tuesday, 15 March 2016

Write a code fragment that dynamically allocates a structure of the type described in Question 8 and then reads a value for the kind member of the structure.

Leave a Comment

Question:

Write a code fragment that dynamically allocates a structure of the type described in Question 8 and then reads a value for the kind member of the structure.

Answer:

struct fish
{
char kind[20];
int weight;
float length;
};

fish * pole = new fish;
cout << "Enter kind of fish: ";
cin >> pole->kind;

Source:

C++ Primer Plus Sixth Edition Chapter Review

If You Enjoyed This, Take 5 Seconds To Share It