Write a C++ program to read two float numbers. Perform arithmetic binary operations like +, - , *, / on these numbers using Inline Function. Display resultant value with a precision of two digits.
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<conio.h>
#include<iostream.h>
#include<iomanip.h>
class opr
{
public:
inline float mul(float a,float b) //inline functions
{
return (a*b);
}
inline float add(float a,float b)
{
return (a+b);
}
inline float sub(float a,float b)
{
return (a-b);
}
inline float div(float a,float b)
{
return (a/b);
}
};
int main()
{
float p,p1; //p=point1 p1=point2
opr o;
cout<<"\nEnter value of a: ";
cin>>p;
cout<<"\nEnter value of b: ";
cin>>p1;
cout<<"\nAddition of a & b : "<<setw(5); //setw is manipulator
cout<<o.add(p,p1);
cout<<"\nSubstraction of a & b : "<<setw(5);
cout<<o.sub(p,p1);
cout<<"\nMultiplication of a & b : "<<setw(5);
cout<<o.mul(p,p1);
cout<<"\nDivision of a & b : "<<setw(5);
cout<<o.div(p,p1);
getch();
return(0);
}
-
Next Create a Vector class to represent a series of integer values. Allocate memory for Vector object using new operator. Write a C++ menu driven program with following member functions: i. To accept a vector ii. To display a vector in the form (10,20,30,…) iii. To multiply by a scalar value iv. To modify the value of a given position from vector
-
Previous Write a C++ program to create a class Person which contains data members as P_Name, P_City, P_Contact_Number. Write member functions to accept and display five Persons information. Design User defined Manipulator to print P_Contact_Number. (For Contact Number set right justification, maximum width to 10 and fill remaining spaces with ‘*’)
0 Comments