Question

In c++ show both .cpp and .hpp file for the class: class Task { private: //...

In c++ show both .cpp and .hpp file for the class:

class Task {

private:
// These three member variables store the basic information about a task
string title;
string location;

// This pointer will point to a dynamically-allocated array
// of THREE strings. Each element contains the name of a supply required for this task.
// This should start out set to NULL.
string * tags;
// This integer stores the number of elements in the tags array.
int numTags;

// This pointer specifies a "prereq" task, which is a task that
// must be completed BEFORE this one.
// It should start out set to NULL.
Task * prereqTask;

public:
// Constructor: Initializes all instance variables.
// A newly-created task has no tags and no prereq task.
Task(string title, string location);

// Copy constructor: Initializes the current task as a copy of an existing task.
// - If the existing task has an array of tags, the current
// task should end up with its own tags pointer pointing to
// a complete copy (newly allocated) of the same array.
Task(const Task& otherTask);

// AddTags: Add a set of tags to the task.
// - You may assume the tagsToAdd array is already filled with string elements,
// and the number of elements is given by the size parameter.
// - This method needs to:
// 1) PRINT AN ERROR (and do nothing else) if the task already has tags specified
// 2) Otherwise, allocate a new dynamically allocated array and set its
// elements to be copies of the elements in tagsToAdd.
void AddTags(string tagsToAdd[], int size);

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

#include <iostream>

#include <cstring>

#include <string>

using namespace std;

class Task {

private:

string title;
string location;

string *tags=NULL;

tags=new String[2];

int numTags=sizeof(*tags)/sizeof(string);// stores the size of the tag array

public:

Task(string title, string location) //constructor

{

this->title=title;

this->location=location

}

Task(const Task& otherTask) // copy constructor

{

  title = otherTask.title;

location = otherTask.location;

}

void AddTags(string tagsToAdd[], int size) //method

{

for(int i=0; i <size; i++)

{

if(tags[i]==tagsToAdd[i])

{

Cout<<" Sorry!! this tag is already present in the array"<<endl;

}

else

{

tags[i++] = "tagToAdd[i]"; // i used here already created array that is tag

numTags++;

  

}

}//for

}// method

delete []tags;

};//class

int main()
{
        

Task * prereqTask=NULL;

prereqTask=new Task[];

        delete []  prereqTask; // Delete array
        return 0;
}
Add a comment
Know the answer?
Add Answer to:
In c++ show both .cpp and .hpp file for the class: class Task { private: //...
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
  • In C++ Write a program that contains a class called VideoGame. The class should contain the...

    In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....

  • I only need the "functions" NOT the header file nor the main implementation file JUST the impleme...

    I only need the "functions" NOT the header file nor the main implementation file JUST the implementations for the functions Please help, if its difficult to do the complete program I would appreciate if you could do as much functions as you can especially for the derived class. I am a beginer so I am only using classes and pointers while implementing everything using simple c++ commands thank you in advanced Design and implement two C++ classes to provide matrix...

  • Assuming the following class declaration: class   Course {        private:               string grade_;        &n

    Assuming the following class declaration: class   Course {        private:               string grade_;               int       units_;         public:              Course ( );              Course ( string grade, int units);               ~Course ( );               string get_grade ( ) const ;               int       get_units ( ) const; }; NOTE: Class definitions are not provided but you may assume they're properly defined. Variable names used in your answers must follow our stated naming convention especially for pointer names. Write a fragment of...

  • In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following...

    In C++ and comment so I UNDERSTAND Implement a class named DynamicArray that has the following members: A pointer to hold a dynamically allocated array, of type int. A member variable to hold the size of the array. A default constructor, which will allocate an array of size 10 A parameterized constructor, which takes a size and use the size to allocate array. A copy constructor, which performs deep copy. A copy assignment operator, which performs deep copy and supports...

  • In this assignment, you are given several classes in the cpp file “DList.cpp”. Your task is...

    In this assignment, you are given several classes in the cpp file “DList.cpp”. Your task is to complete the implementation of the classes specified as below. Y 1 Your Task You are given a class “Item” that contains one integer value, and two pointers. You are going to build a doubly linked list class DLinkedList. I describe the tasks below. Task 1: Implement the constructors (default and copy) of DLinkedList. You need to make sure that the copy constructor makes...

  • c++ only Design a class representing an Employee. The employee would have at least these private...

    c++ only Design a class representing an Employee. The employee would have at least these private fields (Variables): name: string (char array) ID: string (char array) salary: float Type: string (char array) All the variables except for the salary should have their respective setters and getters, and the class should have two constructors, one is the default constructor and the other constructor initializes the name,ID and type of employee with valid user input. The class should have the following additional...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task an...

    its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...

  • Need this in C++ Goals: Your task is to implement a binary search tree of linked...

    Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...

  • 2. (50 marks) A string in C++ is simply an array of characters with the null...

    2. (50 marks) A string in C++ is simply an array of characters with the null character(\0) used to mark the end of the string. C++ provides a set of string handling function in <string.h> as well as I/O functions in <iostream>. With the addition of the STL (Standard Template Library), C++ now provides a string class. But for this assignment, you are to develop your own string class. This will give you a chance to develop and work with...

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