Question

In: Computer Science

URGENT: USING C++: You are given a main.cpp and a Schedule.h file. You are to write...

URGENT:

USING C++:

You are given a main.cpp and a Schedule.h file.  You are to write a Schedule.cpp file that implements the missing pieces from Schedule.h.
 
// ************************************
// *************  main.cpp ************
// ************************************
#include "Schedule.h"
void main()
{
      Schedule s1(10);
      s1.addEntry(1,20,"Feed Cat");
      s1.addEntry(2,40,"Feed Dog");
      s1.addEntry(2,50,"Walk Dog");
      s1.addEntry(4,0, "Fix Dinner");
      s1.addEntry(5,15,"Eat Dinner");
      s1.printSchedule();
      Schedule s2(s1); // Note this uses the copy constructor
      cout << endl << "Output from s2 " << endl;
      s2.printSchedule();
}
 
 
// **********************************************
// *************   Schedule.h  ******************
// **********************************************
#include <iostream>
#include <string>
using namespace std;
 
class Entry{
private:
    int m_hour;
    int m_minute;
    string m_todo;
 
public:
    Entry()
    {
        m_hour = -1;
        m_minute = -1;
        m_todo = "N/A";
    }
 
    void setData(int hour, int minute, const char *td);
    void setData(Entry & e);  
 
    //This routine prints a line that would look something like:
    // 12:30 Take a Walk
    void printEntry();
};
 
class Schedule
{
private:
    // Array of Entry
    Entry * m_entryArr;
 
    // Max size of the Array
    int m_maxEntries;
 
    // Number of entries filled in with setData (starts out = 0)
    int m_actualEntryCount;
 
public:
// This Constructor will initialize 2 ints and define the m_entryArr
    Schedule(int maxEntries);
 
// Copy Constructor – it is done for you

     Schedule::Schedule(Schedule & s) {

            m_actualEntryCount = s.m_actualEntryCount;

            m_maxEntries = s.m_maxEntries;

            m_entryArr = new Entry[m_maxEntries];

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

            {

                 m_entryArr[i].setData(s.m_entryArr[i]);

            }

 }
  ~Schedule();
// addEntry returns true if it succeeds, false if we are out of space
// Note that addEntry will merely call setData to fill in the next entry
// in the array and increment the m_actualEntryCount
      bool addEntry(int hour, int minute, const char *todo);
 
// This routine prints out all entries (i.e. as specified by m_actualEntryCount) 
      void printSchedule();
};

Solutions

Expert Solution

First Complete the getter(that is setData Method) for Entry class because we cannot access private data members of class variables in another class as Schedule use that.


void setData(int hour, int minute, const char *td)
{
this->m_hour=hour;
this->m_minute=minute;
this->m_todo=td;
}
void setData(Entry & e)
{
this->m_hour=e.m_hour;
this->m_minute=e.m_minute;
this->m_todo=e.m_todo;
}

print the entry data memebers as show hr:min "todo"

// 12:30 Take a Walk
void printEntry()
{
cout<<this->m_hour<<":"<<this->m_minute<<" "<<this->m_todo<<"\n";
}

Whole Code:

class Entry
{
private:
int m_hour;
int m_minute;
string m_todo;
public:
Entry()
{
m_hour = -1;
m_minute = -1;
m_todo = "";
}

void setData(int hour, int minute, const char *td)
{
this->m_hour=hour;
this->m_minute=minute;
this->m_todo=td;
   


}
void setData(Entry & e)
{
this->m_hour=e.m_hour;
this->m_minute=e.m_minute;
this->m_todo=e.m_todo;

}
//This routine prints a line that would look something like:
// 12:30 Take a Walk
void printEntry()
{
cout<<this->m_hour<<":"<<this->m_minute<<" "<<this->m_todo<<"\n";
}
};

class Schedule
{
private:
// Array of Entry
Entry * m_entryArr;

// Max size of the Array
int m_maxEntries;

// Number of entries filled in with setData (starts out = 0)
int m_actualEntryCount;

public:
// This Constructor will initialize 2 ints and define the m_entryArr
Schedule(int maxEntries)
{
this->m_maxEntries=m_maxEntries;
this->m_actualEntryCount=0;
m_entryArr=new Entry[m_maxEntries];
  
}

// Copy Constructor – it is done for you

Schedule(Schedule & s)
{

m_actualEntryCount = s.m_actualEntryCount;

m_maxEntries = s.m_maxEntries;

m_entryArr = new Entry[m_maxEntries];

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

{

m_entryArr[i].setData(s.m_entryArr[i]);

}

}

// addEntry returns true if it succeeds, false if we are out of space
// Note that addEntry will merely call setData to fill in the next entry
// in the array and increment the m_actualEntryCount
bool addEntry(int hour, int minute, const char *todo)
{
if(m_actualEntryCount==m_maxEntries-1)
{
return false;
}
m_entryArr[m_actualEntryCount].setData(hour,minute,todo);
m_actualEntryCount++;
return true;
}

// This routine prints out all entries (i.e. as specified by m_actualEntryCount)
void printSchedule()
{
for (int i=0; i < m_actualEntryCount; i++)

{

m_entryArr[i].printEntry();

}
}
  
~Schedule()
{
delete [] m_entryArr;   
}
};

 class Entry { private: int m_hour; int m_minute; string m_todo; public: Entry() { m_hour = -1; m_minute = -1; m_todo = ""; } void setData(int hour, int minute, const char *td) { this->m_hour=hour; this->m_minute=minute; this->m_todo=td;      } void setData(Entry & e) { this->m_hour=e.m_hour; this->m_minute=e.m_minute; this->m_todo=e.m_todo; } //This routine prints a line that would look something like: // 12:30 Take a Walk void printEntry() { cout<<this->m_hour<<":"<<this->m_minute<<" "<<this->m_todo<<"\n"; } }; class Schedule { private: // Array of Entry Entry * m_entryArr; // Max size of the Array int m_maxEntries; // Number of entries filled in with setData (starts out = 0) int m_actualEntryCount; public: // This Constructor will initialize 2 ints and define the m_entryArr Schedule(int maxEntries) { this->m_maxEntries=m_maxEntries; this->m_actualEntryCount=0; m_entryArr=new Entry[m_maxEntries]; } // Copy Constructor – it is done for you Schedule(Schedule & s) { m_actualEntryCount = s.m_actualEntryCount; m_maxEntries = s.m_maxEntries; m_entryArr = new Entry[m_maxEntries]; for (int i=0; i < m_actualEntryCount; i++) { m_entryArr[i].setData(s.m_entryArr[i]); } } // addEntry returns true if it succeeds, false if we are out of space // Note that addEntry will merely call setData to fill in the next entry // in the array and increment the m_actualEntryCount bool addEntry(int hour, int minute, const char *todo) { if(m_actualEntryCount==m_maxEntries-1) { return false; } m_entryArr[m_actualEntryCount].setData(hour,minute,todo); m_actualEntryCount++; return true; } // This routine prints out all entries (i.e. as specified by m_actualEntryCount) void printSchedule() { for (int i=0; i < m_actualEntryCount; i++) { m_entryArr[i].printEntry(); } } ~Schedule() { delete [] m_entryArr; } };

Related Solutions

Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language...
Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language A Game store sells many types of gaming consoles. The console brands are Xbox, Nintendo, PlayStation. A console can have either 16 or 8 gigabytes of memory. Use can choose the shipping method as either Regular (Cost it $5) or Expedite (Cost is $10) The price list is given as follows: Memory size/Brand Xbox Nintendo PlayStation 16 gigabytes 499.99 469.99 409.99 8 gigabytes 419.99...
write a program in c++ that opens a file, that will be given to you and...
write a program in c++ that opens a file, that will be given to you and you will read each record. Each record is for an employee and contains First name, Last Name hours worked and hourly wage. Example; John Smith 40.3 13.78 the 40.3 is the hours worked. the 13.78 is the hourly rate. Details: the name of the file is EmployeeNameTime.txt Calculate the gross pay. If over 40 hours in the week then give them time and a...
Using C++ 1. Create a main function in a main.cpp file. The main function should look...
Using C++ 1. Create a main function in a main.cpp file. The main function should look as follows int main() {return 0;} 2. Create an array. 3. Ask user to enter numbers in size of your array. 4. Take the numbers and store them in your array. 5. Go through your array and add all the numbers. 6. Calculate the average of the numbers. 7. Display the numbers, sum and average.
HW_6b - Read and write a text file. Include the following in the main.cpp file. Add...
HW_6b - Read and write a text file. Include the following in the main.cpp file. Add code so that the numbers that are read from the data.txt file are written to an output           file named:   results.txt After the numbers are written to the file, the following message should be displayed:    The data has been written to the file. Open the results.txt file and verify that the file was written successfully. Please make the code based on C++,...
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file...
Complete the provided partial C++ Linked List program. Main.cpp is given and Link list header file is also given. The given testfile listmain.cpp is given for demonstration of unsorted list functionality. The functions header file is also given. Complete the functions of the header file linked_list.h below. ========================================================= // listmain.cpp #include "Linked_List.h" int main(int argc, char **argv) {      float           f;      Linked_List *theList;      cout << "Simple List Demonstration\n";      cout << "(List implemented as an Array - Do...
Using OOP, write a C++ program that will read in a file of names. The file...
Using OOP, write a C++ program that will read in a file of names. The file is called Names.txt and should be located in the current directory of your program. Read in and store the names into an array of 30 names. Sort the array using the selection sort or the bubblesort code found in your textbook. List the roster of students in ascending alphabetical order. Projects using global variables or not using a class and object will result in...
Write this program in C++ You are given a source file in your work area for...
Write this program in C++ You are given a source file in your work area for this assignment. It consists of a declaration for a Val node. There are declarations for three overloaded operator functions, which you must fill in: operator+, operator*, and operator!. operator+ should implement addition. operator* should implement multiplication. operator! should reverse the digits of its operand (i.e., of "this") and return the reversed integer. So for example !123 should return 321. It should be straightforward to...
C++ Code You will write a program to process the lines in a text file using...
C++ Code You will write a program to process the lines in a text file using a linked list and shared pointers. You will create a class “Node” with the following private data attributes: • Line – line from a file (string) • Next (shared pointer to a Node) Put your class definition in a header file and the implementation of the methods in a .cpp file. The header file will be included in your project. If you follow the...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT