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

Edit: The max number of activities is arbitrary. As written in question; program

ID: 3776180 • Letter: E

Question

Edit: The max number of activities is arbitrary. As written in question; program should ask us to input the id of activities unless a negative number is entered. It is needed to select activities from these activities. Max number is up to us.

323as1) Could you please help me to solve this problem? (ONLY USING C++)

Problem:

You are requested to create a class called “Activity”.

You will use ordered link list to hold Activity’s class information.

In order to do that you will use Standard Template Library (STL) to make your codes more generic.

In the main method, you will create an ordered linked list object and add the information, which are entered by the user (id, start time, finish time), to the linked list object.

Id should be greater than or equal 0. Unless the user enters a negative number, the program will continue to ask activity information, else the program will terminate and if the first id number is a negative number, program will give an error message like EMPTY

Sort the linked list according to the finish time.

According to the entered a set of activities, select the activities up to maximum number of activities and print the total duration of selected activities.

Sample runs are below.

Edit: The max number of activities is arbitrary. As written in question; program should ask us to input the id of activities unless a negative number is entered. It is needed to select activities from these activities. Max number is up to us.

Reminder:

-      It is needed to include STL for Linked list.

Enter the id Enter the start time 1 Enter the finish time 2 Enter the id 1 Enter the start time: 3 Enter the finish time 4 Enter the id: 2 Enter the start time 0 Enter the finish time: 6 Enter the id: 3 Enter the start time 5 Enter the finish time Enter the id: 4 Enter the start time 8 Enter the finish time 9 Enter the id 5 Enter the start time 5 Enter the finish time 9 Enter the id -1 Selected activities: 0 1 3 4 Duration of activities 5 Enter the id: 1 Enter the start time 3 Enter the finish time 5 Enter the id: 2 Enter the start time 6 Enter the finish time 8 Enter the id: 3 Enter the start time 1 Enter the finish time: 4 Enter the id: 4 Enter the start time: 4 Enter the finish time Enter the id: 5 Enter the start time Enter the finish time: 10 Enter the id -1 Selected activities 3 4 5 Duration of activities 9

Explanation / Answer

#include <iostream>
#include<list>
using namespace std;
//class activity
class Activity {
friend ostream &operator<<(ostream &, const Activity &);
public:
int id;
int start_time;
int finish_time;
//default constructor
Activity() {
id = 0;
start_time = 0;
finish_time = 0;
}
//parameterised constructor
Activity(int x, int y, int z) {
id = x;
start_time = y;
finish_time = z;
}
//< operator overloading for sort
int operator<(const Activity &ac) const {
if (this->finish_time == ac.finish_time) return 1;
return 0;
}
};
//< operator overloading for printing

ostream &operator<<(ostream &output, const Activity &a) {

output << "ID: " << a.id << endl << "Start Time: " << a.start_time << endl << "Finish Time: " << a.finish_time << endl;
return output;
}

int main(int argc, char** argv) {

list<Activity> Activities;//activity list
Activity A;//activity object
cout << " Enter the id: ";
cin >> A.id;
if (A.id < 0) {
cout << "error";//for first value
return 1;
}
cout << " Enter the start time: ";
cin >> A.start_time;
cout << " Enter the finish time: ";
cin >> A.finish_time;
Activities.push_back(A);
while (1) {
cout << " Enter the id: ";
cin >> A.id;
if (A.id < 0)
break;//while -1
cout << " Enter the start time: ";
cin >> A.start_time;
cout << " Enter the finish time: ";
cin >> A.finish_time;
Activities.push_back(A);
}
list<Activity>::iterator i;//for list iteration
//unsorted list
for (i = Activities.begin(); i != Activities.end(); ++i) {
cout << *i << " "; // prints using overloaded operator
cout << endl;
}
//sorts list
Activities.sort();
//sorted list
for (i = Activities.begin(); i != Activities.end(); ++i) {
cout << *i << " "; // prints using overloaded operator
cout << endl;
}

return 0;
}


Enter the id:
Enter the start time:
Enter the finish time:
Enter the id:
Enter the start time:
Enter the finish time:
Enter the id:
Enter the start time:
Enter the finish time:
Enter the id:
Enter the start time:
Enter the finish time:
Enter the id:
Enter the start time:
Enter the finish time:
Enter the id:

ID: 0
Start Time: 1
Finish Time: 2

ID: 1
Start Time: 2
Finish Time: 4

ID: 2
Start Time: 5
Finish Time: 7

ID: 3
Start Time: 5
Finish Time: 8

ID: 4
Start Time: 9
Finish Time: 0

ID: 0
Start Time: 1
Finish Time: 2

ID: 1
Start Time: 2
Finish Time: 4

ID: 2
Start Time: 5
Finish Time: 7

ID: 3
Start Time: 5
Finish Time: 8

ID: 4
Start Time: 9
Finish Time: 0

RUN SUCCESSFUL (total time: 30s)

could not understand what this means:

According to the entered a set of activities, select the activities up to maximum number of activities and print the total duration of selected activities.

please explain in comments

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