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

i need helping constructing an array of structs, this is my part of my header fi

ID: 3638146 • Letter: I

Question

i need helping constructing an array of structs, this is my part of my header file which contains the following struct

struct PCB
{
el_t id; // contains the priority of the process
string state; // current state of the process (e.g running)
PCB *next;// link to the next process
};

i need help creating an array of 50 structs PCB and initialize all state to READY, and initialize all el_t id from 1 to 50 for example
id[0] = 1;
id[1]=2;
.
.
id[49]=50;

i never created an array of structs, so any help is appreciated.

Explanation / Answer

THIS IS A STRUCTURE ARRAY:

using namespace std;

struct PCB
{
el_t id; // contains the priority of the process
string state; // current state of the process (e.g running)
};

int main()
{

PCB * arr = new PCB[5]; // would create a array of 5 PCB

{

cout << "Enter the DETAILS of, "<<i<<"element :";

cin>>arr[i]id;

getline(cin,arr[i].state);
}
return 0;
}

THIS IS A STRUCTURE LINKED LIST:


struct PCB
{
el_t id; // contains the priority of the process
string state; // current state of the process (e.g running)
PCB *next;// link to the next process
};


int main()
{

char option = 'Y';

PCB *head; // would create a array

PCB *c;

c = head;

while(option == 'Y')

{

PCB *arr = new PCB;

cout << "Enter the DETAILS of, "<<i<<"element :";

cin>>arr->id;

getline(cin, arr->state);

arr->next=NULL;

c->next = arr;

c=ar;

cout<<"Enter Y to enter more details, or N to terminate.";

cin>>option;

}

return 0;
}