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.

Enter the id Enter the start time 1 Enter the fini

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <list>
using namespace std;

int main( )
{
list<int> intlist;
list<int>::iterator ptr;
int i;

//checking whether the list is empty
if (intlist.empty( )= =true)
{
cout<<endl<<"The list is empty";
}

//add 5 values to the list (0 1 2 3 4)
for( i = 0; i<5; i++)
{
intlist.push_back( i );
}

//add another element (4) to the list
intlist.push_back(4);

//initializ the iterator to first node
//display the value held in first node

ptr=intlist.begin( );
cout<<endl<<"First element has value: "<<*ptr;

//traversing through the list by incrementing the iterator
cout<<endl<<"Initial list contents are : ";
for (i = 0; ptr != intlist.end( ); i++)
{
cout<<" "<<*ptr; //displaying the value at that node
ptr++;
}

//removing duplicate elements from the list
intlist.unique( );

cout<<endl<<"Modified list contents are: ";
ptr = intlist.begin( );
for (i=0; ptr!=intlist.end( ); i++)
{
cout<<" "<<*ptr;
ptr++;
}

return 0;
}

Add a comment
Know the answer?
Add Answer to:
Edit: The max number of activities is arbitrary. As written in question; program should ask us...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program is to be written In C++, The output should look like the screen shot. It...

    Program is to be written In C++, The output should look like the screen shot. It should allow the user to continue to ask the user to enter all employee ID's until done and then prompt the user to enter the hours and pay rate for each employee ID. Please help:( Can you please run the program to make sure the output is just like the screenshot please? It needs to have the output that is in the screenshot provided,...

  • Consider a project having the following six activities:                                  

    Consider a project having the following six activities:                                                      Immediate                                                  Max        Crash cost             Activity                           Predecessors           Time (weeks)             Crash*    per week                   A                                none                                    6                          6                N/A                   B                                none                                    5                          2               $500                   C                                A                                       3                          2             $1000                   D                                A, B                                    4                          2             $2000                   E                                 C, D                                    5                          2             $1250                   F                                D                                       6                          2             $1000                                                                                                 *Shortest possible time for the task 1. Draw the project network and list...

  • Consider a project having the following six activities:                                  

    Consider a project having the following six activities:                                                      Immediate                                                  Max            Crash cost             Activity                           Predecessors          Time (weeks)             Crash*    per week                   A                                none                                    7                          7         N/A                   B                                none                                    3                          2        $500                   C                                A                                       5                          3      $1000                   D                                A, B                                    6                          4      $2000                   E                                 C, D                                    4                          3      $1250                   F                                D                                       3                          2      $1000                                                                                                 *Shortest possible time for the task 1. Draw the project network and list...

  • Activity Selection Last-to-Start | C++ Implementation Develop a program with a greedy algorithm that instead of always...

    Activity Selection Last-to-Start | C++ Implementation Develop a program with a greedy algorithm that instead of always selecting the first activity to finish, instead selects the last activity to start that is compatible with all previously selected activities. The program should read input from a file named “act.txt”. The file contains lists of activity sets with number of activities in the set in the first line followed by lines containing the activity number, start time & finish time. Example act.txt:...

  • In Java Write a program that reads an arbitrary number of 25 integers that are positive...

    In Java Write a program that reads an arbitrary number of 25 integers that are positive and even. The program will ask the user to re-enter an integer if the user inputs a number that is odd or negative or zero. The inputted integers must then be stored in a two dimensional array of size 5 x 5. Please create 3 methods: 1. Write a method public static int sum2DArray( int [1] inputArray ) The method sums up all elements...

  • This program is to ask the user N number of math (using only +, -, *,...

    This program is to ask the user N number of math (using only +, -, *, and /) questions. Once the program start it asks the user to enter how many questions will be asked (N, which is between 3-10). Then, the program asks N questions to the user. Each question will be one of four math operations (+, -, *, and /). The operation and operands will be selected randomly in your program.Operand are “unsigned short” between 0 and...

  • This is a Java text only program. This program will ask if the user wants to...

    This is a Java text only program. This program will ask if the user wants to create a music playlist. If user says he or she would like to create this playlist, then the program should first ask for a name for the playlist and how many songs will be in the playlist. The user should be informed that playlist should have a minimum of 3 songs and a maximum of 10 songs. Next, the program will begin a loop...

  • This program will ask the user to enter a number of players, then ask the user...

    This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...

  • Question 13 The following table provides a list of activities in a project, along with their...

    Question 13 The following table provides a list of activities in a project, along with their respective durations and precedence requirements: Immediate Duration Activity Predecessor(s) (weeks) A 2 B 3 с 2 D A,B 5 E CD F D 4 G E 2 1 Determine the duration of the project. a. 13 weeks b. 12 weeks OC. 11 weeks d. 10 weeks e. 9 weeks Question 14 Assume that activity F has the following times: Early start time (ES) =...

  • Problem 1 Write a Python program to do the following: (A) Ask the user to enter...

    Problem 1 Write a Python program to do the following: (A) Ask the user to enter as many integers from 1 to 10 as he/she wants. Store the integers entered by the user in a list. Every time after the user has entered an integer, use a yes/no type question to ask whether he/she wants to enter another one. (B) Display the list. (C) Calculate and display the average of the integers in the list. (D) If the average is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT