Question

Could anyone help me solve this problem in C++? Thanks a lot. Develop an OOP program...

Could anyone help me solve this problem in C++? Thanks a lot.

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.

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

Screenshot

Program

assignment.h

/*
Create a class Assignment
with attributes of name and due date
*/
#include<iostream>
#include<string>
using namespace std;
class Assignment {
   //Attributes
private:
   string assignmentName;
   string dueDate;
   //Member functions
public:
   Assignment(string name = "",string date = "");
   friend ostream& operator<<(ostream& out, Assignment as);
   bool operator==(Assignment& as);
   string getName()const;
   string getDate()const;
};
//Constructor assign values
Assignment::Assignment(string name,string date) {
   assignmentName = name;
   dueDate = date;
}
//Output operator overload
//Display assignments details as coma separated values
ostream& operator<<(ostream& out, Assignment as) {
   out << as.assignmentName << ", " << as.dueDate;
   return out;
}
//Check 2 assignmnets are equal or not
bool Assignment::operator==(Assignment& as) {
   return this->assignmentName==as.assignmentName && this->dueDate==as.dueDate;
}
//Attributes getters
string Assignment::getName()const {
   return assignmentName;
}
string Assignment::getDate()const{
   return dueDate;
}

Tester.cpp

/*
Tester
*/
#include "assignment.h"
#include<list>
#include<iterator>
#include <ctime>

//Function prototypes
int getOption();
void addAssignment(list<Assignment>& assignments);
void removeAssignment(list<Assignment>& assignments);
void displayAssignments(list<Assignment>& assignments);
void earliestAssignments(list<Assignment>& assignments);

int main()
{
   //Create a list for assignmnets storage
   list<Assignment> assignments;
   //Get option
   int opt = getOption();
   //Loop until exit
   while (opt != 5) {
       //Add assignment
       if (opt == 1) {
           addAssignment(assignments);
       }
       //Remove assignment
       else if (opt == 2) {
           removeAssignment(assignments);
       }
       //Display all assignments
       else if (opt == 3) {
           displayAssignments(assignments);
       }
       //Display earliest assignments details
       else if (opt == 4) {
           earliestAssignments(assignments);
       }
       //Repetition of loop
       cout << endl;
       opt = getOption();
   }
   cout << "\nEnding.....\n";
}
/*
Function to get an option from user
Display user options
Ask for user choice
Do error check
And return option
*/
int getOption() {
   int opt;
   cout << "USER OPTIONS:-\n1. Add a new assignment\n2. Remove an assignment\n"
       << "3. Provide list of assignment\n4. Earliest due date assignment\n5. Exit\n";
   cin >> opt;
   while (opt < 1 || opt>5) {
       cout << "Error!!!Option must be 1-5\n";
       cout << "USER OPTIONS:-\n1. Add a new assignment\n2. Remove an assignment\n"
           << "3. Provide list of assignment\n4. Earliest due date assignment\n5. Exit\n";
       cin >> opt;
   }
   return opt;
}
/*
Function to add a new assignemnt in the list
*/
void addAssignment(list<Assignment>& assignments) {
   string name, date;
   cin.ignore();
   //Get assignment details from user
   cout << "Enter assignment name: ";
   getline(cin, name);
   cout << "Enter assignment date(d/m/yyyy): ";
   cin >> date;
   //Create an assignment object
   Assignment assignment(name, date);
   //Get current date as string
   time_t now = time(0);
   tm *ltm = localtime(&now);
   string current = to_string(ltm->tm_mday) + "/"+to_string(1+ltm->tm_mon)+"/"+to_string(1900 + ltm->tm_year);
   //Compare new assignment less than current date ,generate error msg
   if (assignment.getDate()<current){
       cout << "Date is less than current date,not added!!!" << endl;
   }
   //Otherwise
   else {
       //Check already present in list
       bool flag = false;
       list <Assignment> ::iterator it;
       for (it = assignments.begin(); it != assignments.end(); ++it) {
           Assignment as = *it;
           if (as==assignment) {
               cout << "Assignment already added!!!So not newly addd!!!" << endl;
               flag = true;
               break;
           }
       }
       //Otherwise add into list
       if (!flag) {
           assignments.push_back(assignment);
           cout << "Added successfully!!!\n";
       }
   }
}
/*
Function get an assignment details
if found in list remove
otherwise not found error message
*/
void removeAssignment(list<Assignment>& assignments) {
   string name, date;
   cin.ignore();
   //Get assignment details
   cout << "Enter assignment name: ";
   getline(cin, name);
   cout << "Enter assignment date(d/m/yyyy): ";
   cin >> date;
   //Create an assignment object
   Assignment assignment(name, date);
   //Check present or not
   bool flag = false;
   list <Assignment> ::iterator it;
   for (it = assignments.begin(); it != assignments.end(); ++it) {
       Assignment as = *it;
       if (as==assignment) {
           flag = true;
           assignments.erase(it);
           cout << "Assignment removed successfully!!!" << endl;
           break;
       }
   }
   if (!flag) {
       cout << "Not found in list!!!\n";
   }
}
/*
Function to display all assignments as added way
*/
void displayAssignments(list<Assignment>& assignments) {
   list <Assignment> ::iterator it;
   for (it = assignments.begin(); it != assignments.end(); ++it)
       cout << *it << endl;
}
/*
Display detail of an assignment as earliest submission due
*/
void earliestAssignments(list<Assignment>& assignments) {
   list <Assignment> ::iterator it;
   it = assignments.begin();
   Assignment assignment = *it;
   for (it = assignments.begin(); it != assignments.end(); ++it) {
       Assignment as = *it;
       if (as.getDate()<assignment.getDate()) {
           assignment = as;
       }
   }
   cout << "Earliest assignmnet = " << assignment << endl;
}

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

Output

USER OPTIONS:-
1. Add a new assignment
2. Remove an assignment
3. Provide list of assignment
4. Earliest due date assignment
5. Exit
1
Enter assignment name: A1
Enter assignment date(d/m/yyyy): 28/2/2020
Added successfully!!!

USER OPTIONS:-
1. Add a new assignment
2. Remove an assignment
3. Provide list of assignment
4. Earliest due date assignment
5. Exit
1
Enter assignment name: A2
Enter assignment date(d/m/yyyy): 11/1/2020
Date is less than current date,not added!!!

USER OPTIONS:-
1. Add a new assignment
2. Remove an assignment
3. Provide list of assignment
4. Earliest due date assignment
5. Exit
1
Enter assignment name: A1
Enter assignment date(d/m/yyyy): 28/2/2020
Assignment already added!!!So not newly addd!!!

USER OPTIONS:-
1. Add a new assignment
2. Remove an assignment
3. Provide list of assignment
4. Earliest due date assignment
5. Exit
1
Enter assignment name: A3
Enter assignment date(d/m/yyyy): 28/1/2020
Added successfully!!!

USER OPTIONS:-
1. Add a new assignment
2. Remove an assignment
3. Provide list of assignment
4. Earliest due date assignment
5. Exit
3
A1, 28/2/2020
A3, 28/1/2020

USER OPTIONS:-
1. Add a new assignment
2. Remove an assignment
3. Provide list of assignment
4. Earliest due date assignment
5. Exit
4
Earliest assignmnet = A3, 28/1/2020

USER OPTIONS:-
1. Add a new assignment
2. Remove an assignment
3. Provide list of assignment
4. Earliest due date assignment
5. Exit
2
Enter assignment name: A3
Enter assignment date(d/m/yyyy): 28/1/2020
Assignment removed successfully!!!

USER OPTIONS:-
1. Add a new assignment
2. Remove an assignment
3. Provide list of assignment
4. Earliest due date assignment
5. Exit
3
A1, 28/2/2020

USER OPTIONS:-
1. Add a new assignment
2. Remove an assignment
3. Provide list of assignment
4. Earliest due date assignment
5. Exit
5

Ending.....

Add a comment
Know the answer?
Add Answer to:
Could anyone help me solve this problem in C++? Thanks a lot. Develop an OOP program...
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
  • Could anyone help me solve this C++ problem? Thanks a lot create a class called minHeap...

    Could anyone help me solve this C++ problem? Thanks a lot create a class called minHeap to demonstrate the min Heap data structure of type integer. use a vector to implement the concept. in this class, have the following: private: vector of the type integer integer to store the index of the last element in the min heap "vector" integer to store the size (number of items in the vector "min heap") public: default constructor to set the size to...

  • Create a Student Planner app that will allow students to keep track of homework due dates...

    Create a Student Planner app that will allow students to keep track of homework due dates for the classes they are currently taking. The first app activity (screen) will display the list of classes the student has entered. There should also be a way for students to add, edit, and remove classes from the list. When students select a class they should be taken to a second activity (screen) which will display the assignment name and due date (at minimum,...

  • Program this in C There is a lot of sorting algorithms. So far, we have covered...

    Program this in C There is a lot of sorting algorithms. So far, we have covered selection and insertion sort. However, we only covered how selection sort is implemented using an array. Every sorting algorithm implemented using an array can also be implemented using a linked list. In this assignment, you will implement the selection sort algorithm using a linked list instead of an array. You will first create an interface for handling string items. Basically, you will need to...

  • I need this code in C programming. Can anyone pls help me in this? Project 8,...

    I need this code in C programming. Can anyone pls help me in this? Project 8, Program Design A hotel owner would like to maintain a list of laundry service requests by the guests. Each request was stored with the room number, the guest's first name, last name, and number of items. The program laundry_list.ccontains the struct request declaration, function prototypes, and the main function. Complete the function definitions so it uses a dynamically allocated linked list to store the...

  • please make sure rubics Program Specifications: Write a C++ program to manage a list of students...

    please make sure rubics Program Specifications: Write a C++ program to manage a list of students waiting to register for a course using a linked list. Operations should include adding a new student at the end of the list, adding a new student at the beginning of the list, removing a student from the beginning of the list, removing a student from the end of the list, and removing a student by name. Allow the user an option to exit....

  • This is a C++ program about link list, please help me complete the codes, thanks!(the .h...

    This is a C++ program about link list, please help me complete the codes, thanks!(the .h file has been provided) /* * List.h * * Class Description: List data collection ADT. * Class Invariant: Data collection with the following characteristics: * - Each element is unique (no duplicates). * - (What other characteristic does our List have?) * * * */ #pragma once // You can add #include statements if you wish. #include <string> #include "Patient.h" using namespace std; class...

  • Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic me...

    Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic memory allocation, pointers, recursion, and debugging Mandatory Instructions Develop a C++ object oriented solution to the Towers of Hanoi puzzle. Your solution will involve designing two classes one to represent individual Disk and another to represent the TowersOfHanoi game. TowersOfHanoi class will implement the game with three linked lists representing disks on each...

  • in c++ please RFIDs and lot Internet of things lloT) is one of the hottest technologies...

    in c++ please RFIDs and lot Internet of things lloT) is one of the hottest technologies at the moment. The concept of loT is to provide objects with unique identifiers (UIDs) and the ability to transfer their date over a network without requiring human interaction. Radio frequency identification system (RFID) is a technology that aids computers to identify objects and record their metadata By connecting RFID readers to the Internet, it will be able to send objects' date over the...

  • This is a C++ Program, I need the program broken up into Student.h, Student.cpp, GradeBook.h, GradeBook.cpp,...

    This is a C++ Program, I need the program broken up into Student.h, Student.cpp, GradeBook.h, GradeBook.cpp, and Main.cpp 1. The system must be able to manage multiple students (max of 5) and their grades for assignments from three different assignment groups: homework (total of 5), quizzes (total (total of 2) of 4), and exams 2. For each student record, the user should be able to change the grade for any assignment These grades should be accessible to the gradebook for...

  • Hello, please solve this problem for object oriented programming in C++ program language. I have final...

    Hello, please solve this problem for object oriented programming in C++ program language. I have final tomorrow so it will be very helpful. thank you. PROBLEM 1: application that simulates the highway Create an In order to solve above mentioned requirements, it is necessary to implement several classes: 1. Class Vehicle contains information about the vehicles that drive on the highway. Each vehicle has information about its a Type (can be one of these: Motorcycle, Car, Truck) b. License number...

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
ADVERTISEMENT