Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Below is a function i must insert code into. Here is what the function should do

ID: 3768201 • Letter: B

Question

Below is a function i must insert code into. Here is what the function should do:

The member function write_out() of the class MilTime writes the military time in the format HH:MM to a given file output stream. Write code to ensure this format.

Below is the class MilTime with its attributes and member functions:

class MilTime
{
private:
int hour;
int minutes;

public:
int getHour() const;
int getMin() const;
void setHour(const int h);
void setMin(const int m);

void write_out(ofstream & fout);
};

Finally, can somebody insert into the /* Insert Code here */ section to fulfull the duties of the function write_out?

The only parameter into this function is the output file stream.

void MilTime::write_out(ofstream & fout)
{

/* insert code here*/
}

C++ please!!

Explanation / Answer

Here is the code for you. If you need any further refinements, just revert here.

#include <fstream>
#include <iomanip>
using namespace std;
class MilTime
{
private:
int hour;
int minutes;
public:
int getHour() const;
int getMin() const;
void setHour(const int h);
void setMin(const int m);

void write_out(ofstream & fout);
};

int MilTime::getHour() const
{
return hour;
}

int MilTime::getMin() const
{
return minutes;
}

void MilTime::setHour(const int h)
{
hour = h;
}

void MilTime::setMin(const int m)
{
minutes = m;
}

void MilTime::write_out(ofstream &fout)
{
fout<<setfill('0')<<setw(2)<<hour<<":"<<setfill('0')<<setw(2)<<minutes<<endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote