Convert problems 3 in to template classes, of week 5 and week 4. Test each with Implicit int, float, double, long int. Test each with explicit int, float, double, long int. Filenames: Week6YourNameProg3 Program 3 - Change the code below to match the questions above. #include #include using namespace std; // STEP 1 - DEFINE THE new datatype/Class 'aThing' class aThing { public: // Public means that is can be access in step 3 with the dot notation double getWeight(void) { return weight; } // public functions accessible by dot notation void setWeight( double inWeight ) { weight = inWeight; } private: // Private means that it can NOT be accessed with the dot notation, but indirectly with a public function double weight; // private variables only accessible by a function }; int main() { // STEP 2 - DECLARATION - USE the new datatype/class 'aThing' in a Declaration statement to create 'ThingOne'. aThing ThingOne; // STEP 3 - Use the OBJECT defined in step 2 - With dot notation ThingOne.setWeight(110); cout << "Use Function/Method get Weight - "<< "Weight is: " << ThingOne.getWeight() << endl; system("PAUSE"); // MAC User comment this line out. return 0; }
Part 1
Convert problems 3 in to template classes, of week 5 and week 4.
Test each with Implicit int, float, double, long int.
Test each with explicit int, float, double, long int.
Filenames: Week6YourNameProg3
Program 3 - Change the code below to match the questions above.
#include <iostream>
#include <string>
using namespace std;
// STEP 1 - DEFINE THE new datatype/Class 'aThing' class aThing {
public: // Public means that is can be access in step 3 with the dot notation
double getWeight(void) { return weight;
} // public functions accessible by dot notation void setWeight( double inWeight ) { weight = inWeight; }
private: // Private means that it can NOT be accessed with the dot notation, but indirectly with a public function double weight;
// private variables only accessible by a function };
int main() { // STEP 2 - DECLARATION - USE the new datatype/class 'aThing' in a Declaration statement to create 'ThingOne'. aThing ThingOne;
// STEP 3 - Use the OBJECT defined in step 2 - With dot notation
ThingOne.setWeight(110);
cout << "Use Function/Method get Weight - "<< "Weight is: " << ThingOne.getWeight() << endl;
system("PAUSE"); // MAC User comment this line out.
return 0; }
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images