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

Please implement the pseudocode of the following. Please use C++. Your program w

ID: 3935518 • Letter: P

Question

Please implement the pseudocode of the following. Please use C++. Your program will first ask the user to input the number of activities, next it will ask the user to input a group of starting times, then a group of finishing times. The output will be a subset of maximum number of compatible activities. Deliverable: A complete program that can be compiled and run. Please, attach the screen shot of the running program. GREEDY-ACTIVITY-SELECTOR (s, f) n leftarrow length [s] A leftarrow {a_1} i leftarrow 1 for m leftarrow 2 to n do if s_m greaterthanorequalto f_i then A leftarrow A {a_m} i leftarrow m return A

Explanation / Answer

#include <iostream>

using namespace std;

/* Activities function definition */
void Activities(int s[], int f[], int n)
{
int i, k;

cout<<"Activities are selected : ";

/* first activity always will be selected */
i = 1;

/* so here print first activity */
cout<< i <<" ";

/* for loop for remaining activities*/
for (k = 1; k < n; k++)
{

if (s[k] >= f[i])
{
cout<< k +1 <<" ";
i = k;
}
}
}


int main()
{
int num;
cout<<" Enter Number of activities :";
cin>>num;

/* s array contains start time of all activities*/
int s[num];

/* f array contains finish time of all activities*/
int f[num];

cout<<" Enter start time of activities: ";
for(int i=0;i<num;i++)
{
cin>>s[i];
}

/*enter activities finishing time in order(time increasing)*/
cout<<" Enter finish time of activities :";
for(int j=0;j<num;j++)
{
cin>>f[j];
}

/* print start time of all activities */
cout<<"start time of activities : ";
for(int i=0;i<num;i++)
{
cout<<s[i] <<" ";
}
cout<<endl;
/* print finish time of all activities */
cout<<"finish time of activities : ";
for(int j=0;j<num;j++)
{
cout<<f[j] <<" ";
}
cout<<endl;
int n = sizeof(s)/sizeof(s[0]);
Activities(s, f, n);
cout<<endl;

return 0;
}

--------------------------------------------------------------------------------------

ouput sample 1:-

Enter Number of activities :4
Enter start time of activities: 1
4
0
5
Enter finish time of activities :2
4
6
8
start time of activities : 1 4 0 5
finish time of activities : 2 4 6 8
Activities are selected :
1 2 4

-------------

output sample 2:-

Enter Number of activities :5
Enter start time of activities: 1
4
0
7
9
Enter finish time of activities :3
5
7
9
10
start time of activities : 1 4 0 7 9
finish time of activities : 3 5 7 9 10
Activities are selected :
1 4 5

---------------------------------------------------------------------------------------------

If you have any query, please feel free to ask

Thanks a lot