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

7. Assume the definition of class bagType as given in Exercise 6. Answer the fol

ID: 3865345 • Letter: 7

Question

7. Assume the definition of class bagType as given in Exercise 6. Answer the following questions: (1, 2, 3, 5, 7) a. Write the definition of the member function set so that private b. Write the definition of the member function print that prints the members are set according to the parameters. values of the data members. Write the definition of the default constructor of the class bagType so that the private member variables are initialized to 0.0, respectively. Write a C++ statement that prints the value of the object newBag. Write a C++ statement that declares the object tempBag of type bagType, and initializes the member variables of tempBag to c. 0.0, 0.0. 0.0 d. e. "backPack". 15, 8. 20, and 49.99, respectively.

Explanation / Answer

ClockType.h file

#ifndef CLOCKTYPE_H
#define CLOCKTYPE_H

class ClockType
{
private :
int hour;
int minute;
int second;
public :

//constructor
ClockType(const int h = 0, const int m = 0, const int s = 0);
  
//   setter function
void setHour(const int h);
void setMinute(const int m);
void setSecond(const int s);
  
// getter function
int getHour();
int getMinute();
int getSecond();
  
// Print object of format "hh:mm:ss"
void print();
};

#endif

ClockType.cpp file

#include <iostream>
#include <iomanip>
#include "ClockType.h"
using namespace std;

ClockType :: ClockType(const int h, const int m, const int s)
: hour(h), minute(m), second(s)
{}

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

void ClockType :: setMinute(const int m){
minute = m;
}

void ClockType :: setSecond(const int s){
second = s;
}

int ClockType :: getHour(){
return hour;
}

int ClockType :: getMinute(){
return minute;
}

int ClockType :: getSecond(){
return second;
}

void ClockType :: print()
{
cout << setw(2) << setfill('0') << hour << ":"
   << setw(2) << setfill('0') << minute << ":"
    << setw(2) << setfill('0') << second << " ";  

}

Lab18ClockTypeMain.cpp file

#include <iostream>
#include "ClockType.h"
using namespace std;
int main()
{
ClockType t1(5, 4, 3);
t1.print();
ClockType t2;
t2.print();
t2.setHour(12);
t2.setMinute(30);
t2.setSecond(0);
t2.print();

return 0;
}

/* sample output

05:04:03
00:00:00
12:30:00

*/

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