| | |
Please some one write this program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2005
Posts: 13
Reputation:
Solved Threads: 0
Write a C++ program that has class
1) math
Math class has only one data member number and member function display that will display the data member number.
Write the constructor of your math class that will initialize the data member number with the value zero.
Program will overload the following operators.
1. Plus +
2. Minus -
3. Multiplication *
After overloading these three operators program will be able to add, subtract and multiply your math class object with the integer in main() after overloading these operators you should be able to write these statements in main().
math obj1, obj2;
obj1= obj2 + 10;
Above statement will call the member function operator + () and will add the 10 in the data member of obj2 and finally will return the math class object. Similarly you also overload the multiplication operator * and minus operator – so that your math class object will be able to multiply and subtract from integer values.
Also your plus + overloaded operator should be intelligent enough to accommodate the following statement in the main() function.
math obj1, obj2;
obj2= 10 + obj1;
for this you will have to write friend function that will be called automatically and will add the integer value 10 in the data member of obj1 and finally will return the math class object . Similarly write two more friend functions that will overload the multiplication and subtraction operator so that you will be able to write the following statement in the main() function.
math obj1, obj2;
obj2= 10 *obj1;
obj2= 10 - obj1;
Your output should be similar to the following:
Sample output 1:
adding integer 10 in the object using statement: obj= obj + 10 ;
10
adding integer 10 in the object using statement: obj= 10 + obj;
20
Multiplying object with integer 20 using statement: obj= obj * 20 ;
400
Multiplying integer 20 with object using statement: obj= 20 * obj ;
8000
Subtracting 20 from object using statement: obj= obj - 20 ;
7980
Subtracting object from 10 using statement: obj= 10 - obj ;
-7970
1) math
Math class has only one data member number and member function display that will display the data member number.
Write the constructor of your math class that will initialize the data member number with the value zero.
Program will overload the following operators.
1. Plus +
2. Minus -
3. Multiplication *
After overloading these three operators program will be able to add, subtract and multiply your math class object with the integer in main() after overloading these operators you should be able to write these statements in main().
math obj1, obj2;
obj1= obj2 + 10;
Above statement will call the member function operator + () and will add the 10 in the data member of obj2 and finally will return the math class object. Similarly you also overload the multiplication operator * and minus operator – so that your math class object will be able to multiply and subtract from integer values.
Also your plus + overloaded operator should be intelligent enough to accommodate the following statement in the main() function.
math obj1, obj2;
obj2= 10 + obj1;
for this you will have to write friend function that will be called automatically and will add the integer value 10 in the data member of obj1 and finally will return the math class object . Similarly write two more friend functions that will overload the multiplication and subtraction operator so that you will be able to write the following statement in the main() function.
math obj1, obj2;
obj2= 10 *obj1;
obj2= 10 - obj1;
Your output should be similar to the following:
Sample output 1:
adding integer 10 in the object using statement: obj= obj + 10 ;
10
adding integer 10 in the object using statement: obj= 10 + obj;
20
Multiplying object with integer 20 using statement: obj= obj * 20 ;
400
Multiplying integer 20 with object using statement: obj= 20 * obj ;
8000
Subtracting 20 from object using statement: obj= obj - 20 ;
7980
Subtracting object from 10 using statement: obj= 10 - obj ;
-7970
![]() |
Similar Threads
- Need help to write jdbc program (JSP)
- Can you please help me write this word count program in another way (Python)
- Trying to write a program for an assignment... (Java)
- errors make me close program (C#)
- C++ multiplication program (C++)
- help writing a grep program (C)
- help with program to convert integers to roman numerals (Java)
- correct errors in this program (C)
- Read and write to an ASCII Text file (Java)
Other Threads in the C++ Forum
- Previous Thread: Controls on form disappears when auto-generated controls code modified
- Next Thread: Drag and Drop of images ??
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






