#include<iostream>
using namespace std;
class TwoDimensions{
private:
double x,y;
public:
TwoDimensions(double _x , double _y){
x=_x;
y=_y;
}
friend ostream & operator << (ostream &
out, const TwoDimensions & ob){
out<<"x :
"<<ob.x<<" y: "<<ob.y<<"\n";
return out;
}
};
class ThreeDimensions{
private:
double x,y,z;
public:
ThreeDimensions(double _x , double _y , double
_z){
x=_x;
y=_y;
z = _z;
}
friend ostream & operator << (ostream &
out, const ThreeDimensions & ob){
out<<"x :
"<<ob.x<<" y: "<<ob.y<<" z:
"<<ob.z<<"\n";
return out;
}
};
int main(){
TwoDimensions ob1(3,4);
ThreeDimensions ob2(12,16,15);
cout<<ob1;
cout<<ob2;
return 0;
}
//No it could not be a member function
12. Declare the operator< as a friend function. }: II This is the end of the...
1. Write a virtual member function named length , which specifies that the function is constant (that is does not modify the member data) and returns the square root of x squared plus y squared. 2.write the operator << function to have a member of the ostream class as its left hand operand and a member of the Two Dimensions class as its right hand operand. This function shall take the left hand operand by reference, This function shall return...
Implement the friend function to overload the stream insertion operator (<<) so that the value contained in the PlainBox object can be output using the << operator. The prototype is given in the header file. plainbox.h typedef double T; class PlainBox{ private: Titem; public: PlainBox(): PlainBox(const T& theltem): void setItem(const T& itemltem); T getitem() const; friend ostream& operator<<(ostream & out, const PlainBox & theBox); bool operator<(const PlainBox & theBox);
choices:
supporting function
default constructor
friend function
static member
class
getter
setter
attribute
assignment operator
Identify the parts of the following class definition: class Student { string name; const int ID; float gpa; const char gender; public: Student(); Student& operator (const Student&); string getName() const {return name; } friend ostream& operator<<(ostream&, const Student); }; void outputStudent (const Student&); name [Choose Student) [Choose operator Choose) outputStudent Choose operator<< Choose) getNamel) [Choose
27. Suppose the unary ! operator is an overloaded member function of class String. For a String object s, which function call is generated by the compiler when it finds the expression Is? a. s.operator!0 b. s.operator!(default valuel, default value?,...) c. operator!(s d. A compiler error results because no arguments are given 28. Select the false statement regarding inheritance. a. A derived class can contain more attributes and behaviors than its base class b. A derived class can be the...
Write a statement that declares sObj to be an object of type
strange such that the private member variables a and b are of type
int.
Write statement that shows the the declaration in the class
strange to overload the operator == as a member function.
Assume that two objects of type strange are equal if their
corresponding member variables are equal. Write the definition of
the function operator== for the class strange, which is overloaded
as a member function....
1. Questions on inheritance. (a) Consider the following program segment: 1 class Array2 2 private: ClassX a: // ClassY b: // assume class ClassY is defined. assume class ClassX is defined . 3 4 5 public: 6 Array2 (int size) ( a new Clas sX [ size]; // a is an array of ClassX objects b new ClassY [size]: 1/ b is an array of ClassY objects 7 8 9 ) 10 ClassX getA() (return a; ) ClassY getB ()...
Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...
OUTCOMES After you finish this assignment, you will be able to do the following: Define an abstract class Create concrete classes from an abstract class Overload an operator Split classes into .h and .cpp files Open files for reading Write to files Use output manipulators such as setw, fixed, and setprecision DESCRIPTION A binary arithmetic operation takes two double operands (left and right) to perform addition, subtraction, multiplication, or division on. For example, 10 + 11 is an addition (+)...
The following program contains the definition of a class called List, a class called Date and a main program. Create a template out of the List class so that it can contain not just integers which is how it is now, but any data type, including user defined data types, such as objects of Date class. The main program is given so that you will know what to test your template with. It first creates a List of integers and...
1. Create an “include guard” (all lines of code required) for a file “plane.h” 2. When you look at a constructor, how can you determine if it is THE default constructor? 3. What can a “friend” function do that other non-member functions can not do? 4. class plane { int x;} ---------------- is x public or private? 5. What kind of a search first sorts the data into ascending or descending order, then splits the data in half, searches, splits,...