Please some one write this program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2005
Posts: 13
Reputation: shahid is an unknown quantity at this point 
Solved Threads: 0
shahid shahid is offline Offline
Newbie Poster

Please some one write this program

 
0
  #1
Jun 28th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Please some one write this program

 
0
  #2
Jun 28th, 2005
> Please some one write this program
No. If you're too lazy to do it then you deserve a failing grade.
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Please some one write this program

 
0
  #3
Jun 30th, 2005
Originally Posted by Dogtree
No. If you're too lazy to do it then you deserve a failing grade.
Exactly. Please show your work, and we'll help you troubleshoot your code.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC