C++ language
Given:
class Distance {
private:
int feet=0, inch=0;
public:
Distance(int ft, int in) : feet(ft), inch(in) { };
}
Distance a(2, 10), b(3, 4); // a is 2 feet, 10 inches, b is 3 feet,
4 inches
To enable syntax: Distance c = a + b; you have to define (provide a
single fill-in-the-blank answer with no spaces): [op1]
`Hey,
Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.
We have to define operator overloading
Kindly revert for any queries
Thanks.
C++ language Given: class Distance { private: int feet=0, inch=0; public: Distance(int ft, int in) :...
Given the following class: class Q2 { private int a; private int b; private int c; public void setA(int a){this.a = a; } public void setB(int b){this.b = b;} public void setc(int c){this.c = c;} public int geta(){return a; } public int gets(){return b;} public int getc(){return c;} public int m1(int a, int b){ return a + b; public boolean m2 (int x, int y){ return m1(x, y) + x + y < 10; What is the output of the...
public class Test { private static int i =0; private static int j =0; public static void main(String[] args) { int i = 2; int k = 3; { int j =3; System.out.println("i + j is : " + i + j); } k = i + j; System.out.println("K is " + k ); System.out.println("K is " + j); } } why is the output i + j = 23 K =2 K =0 Please explain a step by step...
Question 19 Given the following class: public class Swapper ( private int x; private String y public int z; public Swapper( int a, String b, int c) ( x-a; y b; zC; public String swap() ( int temp -x; x-z z temp; return y: public String tostring() ( if (x<z) return y: else return" +x+z What would the following code output? Swapper r new Suapper( 5, "no", 10); System.out.printin( r. swap ) ): no no510 510 e 15 Question 20...
Adapt your Rational class : public class Rational { private int num; private int denom; public Rational() { num = 0; denom = 1; } public Rational(int num, int denom) { this.num = num; this.denom = denom; } int getNum() { return num; } int getDenom() { return denom; } public Rational add(Rational rhs) { return new Rational(num * rhs.denom + rhs.num * denom, denom * rhs.denom); } public Rational subtract(Rational rhs) { return new Rational(num * rhs.denom - rhs.num...
Please write code in C++
class S ( private: int data; public: S0 0; S(int n); void Inc0; void Grow(int n); Problem 3: Given: void Reset(int n); int GetSO:3; S:S (int n) ( data n;) void S: Inc0 (data++) void S::Grow(int n) {data + =n;} void S: Reset(int n) data n;) int S: GetsO f return data; ) Find: int maino t S a(8), b(2); a.Inc0; cout<ca.GetsOendl; I.. b.Grow(4); cout<<b.GetsO<endl; II
Use JAVA language. public class DynamicArray2 { private String[] data; // the backing array private int virtualArrayLength; // the number of elements in the dynamic array // Throws an IndexOutOfBoundsException if i is not a valid index // for adding to the dynamic array, otherwise inserts s at index i. // Elements can be added from index 0 to this.size(). public void add(int i, String s) { // If there is no room for s in data, create a new...
C++ class Time { public: Time(); Time(int hrs, int min, int sec); private: int hours; int minutes; int seconds; }; 1. Write the class definition for ExtendedTime which derives from Time via public inheritance. Add private data member time_zone which is an enum type TimeZone (enum TimeZone { PACIFIC, MOUNTAIN, CENTRAL, EASTERN } ). Add a default and alternate constructors to ExtendedTime to initialize all class (including the base class) data; use the base member initialization list. NOTE: This implies...
public class ConsCell
{
private int head;
private ConsCell tail;
public ConsCell(int h, ConsCell t)
{
head = h;
tail = t;
}
public int getHead()
{
return head;
}
public ConsCell getTail()
{
return tail;
}
public void setTail(ConsCell t)
{
tail = t;
}
}
public class IntList
{
private ConsCell start;
public IntList (ConsCell s)
{
start = s;
}
public IntList cons(int h)
{
return new IntList(new ConsCell(h, start));
}
public int length()
{
int len...
Consider the Automobile class: public class Automobile { private String model; private int rating; // a number 1, 2, 3, 4, 5 private boolean isTruck; public Automobile(String model, boolean isTruck) { this.model = model; this.rating = 0; // unrated this.isTruck = isTruck; } public Automobile(String model, int rating, boolean isTruck) { this.model = model; this.rating = rating; this.isTruck = isTruck; } public String getModel()...
Need comments added please. public class TenDate { private int NMnth; private int NDy; private int NYr; private String [] MnthNm = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; private int [] MnthD = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; public TenDate() { NMnth = 1; NDy = 1;...