c++
cout << “Name: YOURNAME – Program Name: PROGRAM NAME – Date: MMDDYY” << endl;
Example: cout << “Name: Jon Smith – Program Name: Prog9Box – Date: 6/28/17” << end;
Program 3) Run the following Sample Code – Produce the correct output and Turn it in for credit
// Sample Class – Print and Study, RUN the code…
#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;
}
——————————————————————————————–
* Be sure to add your name as a cout in the first lines of each program – else 0 credit.
* Add constructors – a default and parameterized constructor to each.
* Write an .h interface and a .cpp implementation for each class
* Write an Drive/Test file that tests the constructors and functions
* Write a UML class diagram for each class
Expert Answer
aThing.h |
#ifndef ATHING_H
#define ATHING_H class aThing{ public: aThing(); aThing(double inWeight); double getWeight(void); void setWeight(double inWeight); private: double weight; }; #include”aThing.cpp” #endif |
aThing.cpp |
#include”aThing.h”
aThing::aThing() { }; aThing::aThing(double inWeight) { weight = inWeight; }; double aThing::getWeight() { return weight; }; void aThing::setWeight(double inWeight) { weight = inWeight; }; |
aThingDriver.cpp |
#include<iostream>
#include”aThing.h” using namespace std; int main() { cout << “Name: YourName – Program Name: aThing Class – Date: 09/15/17” << endl; aThing ThingOne; ThingOne.setWeight(110); cout << “Using Function getWeight() – “<< “Weight is: ” << ThingOne.getWeight() << endl; } |
Important Instructions: You need to create the exact .h (header) file and cpp files with exact case posted above. Always run the driver file myThingDriver.cpp file.
OUTPUT