Operators
- How to stop your program from eating so much ram?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
*Use the hard drive, instead of RAM.
*Declare it in program memory, instead of on the stack.
*Find a way to work with the data one at a time.
- Pick out the correct syntax of operator conversion.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
operator float()const
- What is the output of this program?
#include
using namespace std;
class BoxExample
{
double L;
double B;
double H;
public:
double getVol(void)
{
return L * B * H;
}
void setL( double length )
{
L = length;
}
void setB( double breadth )
{
B = breadth;
}
void setH( double height )
{
H = height;
}
BoxExample operator+(const BoxExample& b)
{
BoxExample box;
box.L = this->L + b.L;
box.B = this->B + b.B;
box.H = this->H + b.H;
return box;
}
};
int main( )
{
BoxExample BoxA,BoxB,BoxC;
double vol = 0.0;
BoxA.setL(6.0);
BoxA.setB(7.0);
BoxA.setH(5.0);
BoxB.setL(12.0);
BoxB.setB(13.0);
BoxB.setH(10.0);
vol = BoxA.getVol();
cout << "Volume of BoxA : " << vol <vol = BoxB.getVol();
cout << "Volume of BoxB : " << vol <BoxC = BoxA + BoxB;
vol = BoxC.getVol();
cout << "Volume of BoxC : " << vol <return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
In this program, we finding the boxC area by adding boxA and boxB.
- What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
double P = 12.93099;
float Q = 11.120;
int R ;
R = (int) P;
cout << R <<" ";
R = (int) Q;
cout << R ;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
In this program, we casted the data type to integer.
- What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
class Example
{
public:
operator string ()
{
return "Converted...";
}
};
int main()
{
Example examp;
string str = examp;
cout << str << endl;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We casted the string to the object of the class.