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: 3776175 • 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 <stack>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
stack<int> st;
int choice, item;
while (1)
{
cout<<" ---------------------"<<endl;
cout<<"Stack Implementation in Stl"<<endl;
cout<<" ---------------------"<<endl;
cout<<"1.Insert Element into the Stack"<<endl;
cout<<"2.Delete Element from the Stack"<<endl;
   cout<<"3.Size of the Stack"<<endl;
cout<<"4.Top Element of the Stack"<<endl;
cout<<"5.Exit"<<endl;
cout<<"Enter your Choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter value to be inserted: ";
cin>>item;
st.push(item);
break;
case 2:
item = st.top();
st.pop();
   cout<<"Element "<<item<<" Deleted"<<endl;
break;
case 3:
   cout<<"Size of the Queue: ";
   cout<<st.size()<<endl;
break;
case 4:
   cout<<"Top Element of the Stack: ";
   cout<<st.top()<<endl;
break;
case 5:
exit(1);
   break;
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
}

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