A. Define a class (you pick the name!) that includes: an int variable and a floa
ID: 3832485 • Letter: A
Question
A. Define a class (you pick the name!) that includes: an int variable and a float variable among its private data members; get and set member functions that simply return the values of the private data members and set the values of the data members, respectively; and a constructor that sets the initial values of the private data members. b. Overload the = operator so that, if objects first and second are of the class that you defined, the statement second = first; swaps the corresponding variables of the two classes (i.e., it swaps the two integer variables and the two float variables).Explanation / Answer
Here is the code for you:
#include<iostream>
using namespace std;
class Test
{
private:
int x;
float y;
public:
int getX() { return x; }
float getY() { return y; }
void setX(int a) { x = a; }
void setY(float b) { y = b; }
Test(int a, int b) { x = a; y = b; }
void operator=(Test other)
{
int temp = x;
x = other.x;
other.x = temp;
float tempF = y;
y = other.y;
other.y = tempF;
}
};
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.