Answer to Question #238687 in C++ for Audrey

Question #238687

Develop an OOP program to maintain a list of homework


assignments. When an assignment is assigned, add it to the list, and when it is


completed, remove it. You should keep track of the due date. Your program should


provide the following services:


• Add a new assignment.


• Remove an assignment.


• Provide a list of the assignments in the order they were assigned.


• Find the assignment(s) with the earliest due date.


create a class called assignments to complete the task and use STL to implement the


linked list. compile and run your project and test all the methods.



1
Expert's answer
2021-09-18T02:57:18-0400
#include <iostream>
using namespace std;
//class Assignment
struct Node {
   int Assignment;
   struct Node* next;
   };


void addAssignment(struct Node** head, int new_Assignment)
{
   struct Node* newNode = new Node;
   newNode->Assignment = new_Assignment;
   newNode->next = (*head);
   (*head) = newNode;
}
 
Node* removeAssignment(struct Node* head)
{
   if (head == NULL)
   return NULL;
 
   if (head->next == NULL) {
      delete head;
      return NULL;
   }


// keeping track of due date
Node* Due_date = head;
while (Due_date->next->next != NULL)
Due_date = Due_date->next;


 
Due_date->next = NULL;
 
return head;
}


int main()
{
   
   Node* add = NULL;


   addAssignment(&add, 1);
   addAssignment(&add, 2);
   addAssignment(&add, 3);
   addAssignment(&add, 4);
   addAssignment(&add, 5);
 
         Node* temp;
 
   cout<<"List of assignments in the order they were assigned "<<endl; for (temp = add; temp != NULL; temp = temp->next)
   cout << temp->Assignment << "-->";
   if(temp == NULL)
   cout<<"NULL"<<endl;
   cout<<"Assignment with the earliest due date is: ";
    cout<<1;
 //deleting completed assignment
   add = removeAssignment(add);
   
   cout<<"\nLinked list after removing completed assingment"<<endl; for (temp = add; temp != NULL; temp = temp->next)
   cout << temp->Assignment << "-->";
   if(temp == NULL)
   cout<<"NULL";
 
   return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS