In lab tomorrow we will give you a class that is partially completed and some co
ID: 3733361 • Letter: I
Question
In lab tomorrow we will give you a class that is partially completed and some code in main. The class code we give you will have a default constructor and public data members.
You will need to write:
1)Another constructor
2)A copy constructor
3)Some sort of comparison member function
Your code will not compile unless the declarations for the above three elements are there (even if they don't work correctly). If your program doesn't compile you will not receive any points.
PLEASE CAN SOMEONE WRITE A SAMPLE OF THIS CODE FOR ME
Explanation / Answer
class Sample {
private double data, dance;
//Constructor
public Sample(double data, double dance) {
this.data = data;
this.dance = dance;
}
//COPY CONSTRUCTOR
Sample (Sample c)
{
data = c.data;
dance = c.dance;
}
//Compare function for comparing objects
@Override
public boolean equals(Object o) {
if(o instanceof Sample) {
Sample rhs = (Sample)o;
return data.equals(rhs.data) && dance.equals(rhs.dance)
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.