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

In C++ Your role is to design a class called TrackProp. The class\'s purpose is

ID: 3702629 • Letter: I

Question

In C++

Your role is to design a class called TrackProp. The class's purpose is to store a value that represents a property tracked hours and covert it to a number of days. For example, 8 hours would be converted to 1 day, 12 hours would be converted to 1.5 days, and 18 hours would be converted to 2.25 days.

The class should have a constructor that accepts a number of hours, street address and zip code, as well as member functions for storing and retrieving the hours and days. The class should also have the following overloaded operators:

+ Addition operator. When two trackProp objects are added together, the overloaded + operator should return the sum of the two objects' hour members

- Subtraction operator. When one trackProp object is subtracted from another, the overloaded - operator should return the difference of the two objects' hours members.


++ prefix and postfix increment operators. These operators should increment the number of hours stored in the object. When incremented, the number of days should be automatically recalculated.

-- prefix and postfix decrement operators. These operators should decrement the number of hours stored in the object. When decremented, the number of days should be automatically recalculated.

Demonstrate each of your functions by creating multiple property class objects to show functionality. Thoughtfully consider how your output will show the details of your program

Explanation / Answer

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
#include<math.h>
class TrackProp
{
private:
char add[50];
long int zip;
int hours;
double days;
public:
TrackProp(); //DEFAULT CONSTRUCTOR
TrackProp(int,char [], long int); //PARAMETERIZED CONSTRUCT

void show(); // DISPLAY THE MEMBERS
void convert(); //CONVERT HOURS TO DAYS
TrackProp operator +(TrackProp p); // ADD TWO OBJECTS
TrackProp operator -(TrackProp p); // SUBSTRACT TWO OBJECTS
void operator++(); // INCREMENT OPERATOR OVERLOADING
void operator--(); // DECREMENT OPERATOR OVERLOADING
};
TrackProp :: TrackProp()
{
hours=0;
zip=0;
}
TrackProp :: TrackProp(int n, char s[50], long int z)
{
hours=n;
zip=z;
strcpy(add,s);
}
/*void TrackProp :: input()
{
cout<<endl<<"Enter the number of hours";
cin>>hours;
}*/
void TrackProp :: show()
{
cout<<endl<<"ADDRESS :"<<add;
cout<<endl<<"ZIP CODE :"<<zip;
cout<<endl<<"NUMBER OF HOURS :"<<hours;
}
void TrackProp :: convert()
{
float q;
q=float(hours)/24;
days=q;
cout<<endl<<hours<<" Hours" <<"="<<setprecision(2)<<days<<" Days";
}
TrackProp TrackProp::operator -(TrackProp k)
{
TrackProp n;
n.hours=abs(hours-k.hours);
cout<<endl<<"AFTER SUBSTRATION TOTAL NUMBER OF HOURS :"<<n.hours;
return n;
}
TrackProp TrackProp::operator +(TrackProp k)
{
TrackProp n;
n.hours=hours+k.hours;
cout<<endl<<"AFTER ADDITION TOTAL NUMBER OF HOURS :"<<n.hours;
return n;
}
void TrackProp :: operator++()
{
++hours;
days=float(hours)/24;
cout<<endl<<hours<<" Hours" <<"="<<setprecision(2)<<days<<" Days";
}
void TrackProp :: operator--()
{
--hours;
days=float(hours)/24;
cout<<endl<<hours<<" Hours" <<"="<<setprecision(2)<<days<<" Days";
}
void main ()
{
int h;
char a[50];
long int zipc;
cout<<endl<<"Enter the number of hours";
cin>>h;
cout<<endl<<"Enter the address";
gets(a);
cout<<endl<<"Enter the ZIP code";
cin>>zipc;
TrackProp t(h,a,zipc);

cout<<endl<<"Enter the number of hours";
cin>>h;
cout<<endl<<"Enter the address";
gets(a);
cout<<endl<<"Enter the ZIP code";
cin>>zipc;
TrackProp s(h,a,zipc);
TrackProp r;
clrscr();
cout<<endl<<endl<<"FIRST OBJECT"<<endl;
t.show();
t.convert();
cout<<endl<<endl<<"SECOND OBJECT"<<endl;
s.show();
s.convert();
cout<<endl<<endl<<"TWO OBJECTS ARE ADDED"<<endl;
r=s+t;
//r.convert();

cout<<endl<<endl<<"TWO OBJECTS ARE SUBTRACTED"<<endl;
r=s-t;
r.convert();

cout<<endl<<"Enter any key to continue..."; getch();
clrscr();

cout<<endl<<"PRE INCREMENTATION AND DECREMENTATIONS"<<endl;
cout<<endl<<endl<<"FIRST OBJECT DECREMENTATION"<<endl;
--t;
cout<<endl<<endl<<"SECOND OBJECT DECREMENTATION"<<endl;
--s;
cout<<endl<<endl<<"FIRST OBJECT INCREMENTATION"<<endl;
++t;
cout<<endl<<endl<<"SECOND OBJECT INCREMENTATION"<<endl;
++s;
cout<<endl<<"Enter any key to continue..."; getch();
clrscr();
cout<<endl<<"POST INCREMENTATION AND DECREMENTATIONS"<<endl;
cout<<endl<<endl<<"FIRST OBJECT DECREMENTATION"<<endl;
t--;
cout<<endl<<endl<<"SECOND OBJECT DECREMENTATION"<<endl;
s--;
cout<<endl<<endl<<"FIRST OBJECT INCREMENTATION"<<endl;
t++;
cout<<endl<<endl<<"SECOND OBJECT INCREMENTATION"<<endl;
s++;
cout<<endl<<"Enter any key to terminate..."; getch();
}