C++ Test3 2009
C++ Test3 2009
Max.Marks:50
// to keep the real part a COMPLEX // NUMBER // to keep the imaginary part of a COMPLEX // NUMBER
public: complx() {real = imag = 0.0;} complx(double r, double img = 0) {real = r; imag = img;} void setval(double r, double i) {real = r; imag = i;} void getval(); void showval(); double r2pabs(); double r2pang(); complx operator + (complx); complx operator - (complx); complx operator * (complx); complx operator / (complx); }; 15.
// allows user to set the values // // // // // // // // // // // // gets the values from user displays the complex number in the usual format of displaying complex numbers returns the absolute value returns the angle in degrees adding two complex nos. and returns the result as an object of class complx. subtract one from another multiply two complex nos. divide one from another
Give the complete class specification for showing the length as a user defined data in meters and centimeters. Call this class length. Let there be two private data members like int mt and float cm and appropriate public member functions so that one can use the length as any standard data. Show a simple test program to use the objects of this class.