Click here to Skip to main content
16,010,114 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: TCP and UDP difference Pin
Mike Dimmick30-Jun-05 2:26
Mike Dimmick30-Jun-05 2:26 
GeneralRe: TCP and UDP difference Pin
David Crow30-Jun-05 2:49
David Crow30-Jun-05 2:49 
GeneralRe: TCP and UDP difference Pin
David Chamberlain30-Jun-05 4:42
David Chamberlain30-Jun-05 4:42 
Generalcould not able to see the text box fields while data while debugging the dialog cpp file code Pin
Prasannajit Dash30-Jun-05 1:06
Prasannajit Dash30-Jun-05 1:06 
GeneralRe: could not able to see the text box fields while data while debugging the dialog cpp file code Pin
David Crow30-Jun-05 2:51
David Crow30-Jun-05 2:51 
GeneralUrgent : GetTimeZoneInformation Pin
15711730-Jun-05 0:22
15711730-Jun-05 0:22 
GeneralRe: Urgent : GetTimeZoneInformation Pin
«_Superman_»30-Jun-05 0:49
professional«_Superman_»30-Jun-05 0:49 
Generalplz guide me in this code!!!!!!! Pin
29-Jun-05 23:08
suss29-Jun-05 23:08 
Write a C++ program that has class

1) math
Our math class has only one data member number and member function display that will display the data member number.
Write the constructor of our math class that will initialize the data member number with the value zero.
Our program will overload the following operators.

1. Plus +
2. Minus -
3. Multiplication *

After overloading these three operators our program will be able to add, subtract and multiply our math class object with the integer in main() after overloading these operators we 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 we also overload the multiplication operator * and minus operator – so that our math class object will be able to multiply and subtract from integer values.

Also our plus + overloaded operator should be intelligent enough to accommodate the following statement in the main() function.

math obj1, obj2;
obj2= 10 + obj1;

for this we 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 we will be able to write the following statement in the main() function.

math obj1, obj2;
obj2= 10 *obj1;
obj2= 10 - obj1;



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


The Code i wrote is below:

#include <iostream.h>
#include <stdlib.h>
#include <conio.h>

class math
{
private:
// Private data member of the calss math
int number ;

public:

// Constructor for math class
math() : number(0) {}

// friend functions
friend int operator+(int,math);
friend int operator-(int,math);
friend int operator*(int,math);
};


// Main function of the programm
void main ( )
{
math m1,m2 ; //create an object of class myClass1
int obj2;
cout << "adding integer 10 in the object using statement: obj=obj + 10 "<
GeneralRe: plz guide me in this code!!!!!!! Pin
Cedric Moonen29-Jun-05 23:16
Cedric Moonen29-Jun-05 23:16 
GeneralRe: plz guide me in this code!!!!!!! Pin
29-Jun-05 23:24
suss29-Jun-05 23:24 
GeneralRe: plz guide me in this code!!!!!!! Pin
David Crow30-Jun-05 2:54
David Crow30-Jun-05 2:54 
GeneralRe: plz guide me in this code!!!!!!! Pin
Cedric Moonen29-Jun-05 23:43
Cedric Moonen29-Jun-05 23:43 
GeneralRe: plz guide me in this code!!!!!!! Pin
toxcct30-Jun-05 0:49
toxcct30-Jun-05 0:49 
GeneralRe: plz guide me in this code!!!!!!! Pin
toxcct30-Jun-05 1:18
toxcct30-Jun-05 1:18 
GeneralRe: plz guide me in this code!!!!!!! Pin
Cedric Moonen30-Jun-05 1:21
Cedric Moonen30-Jun-05 1:21 
GeneralRe: plz guide me in this code!!!!!!! Pin
toxcct30-Jun-05 1:26
toxcct30-Jun-05 1:26 
GeneralRe: plz guide me in this code!!!!!!! Pin
ThatsAlok30-Jun-05 1:32
ThatsAlok30-Jun-05 1:32 
GeneralRe: plz guide me in this code!!!!!!! Pin
toxcct30-Jun-05 1:36
toxcct30-Jun-05 1:36 
GeneralRe: plz guide me in this code!!!!!!! Pin
Cedric Moonen30-Jun-05 1:53
Cedric Moonen30-Jun-05 1:53 
GeneralRe: plz guide me in this code!!!!!!! Pin
ThatsAlok30-Jun-05 2:40
ThatsAlok30-Jun-05 2:40 
Generalto get the column properties Using Oledb Pin
pratapvjil29-Jun-05 23:04
pratapvjil29-Jun-05 23:04 
GeneralDialog background picture Pin
aarontan29-Jun-05 22:57
aarontan29-Jun-05 22:57 
GeneralRe: Dialog background picture Pin
Jose Lamas Rios30-Jun-05 2:43
Jose Lamas Rios30-Jun-05 2:43 
GeneralRe: Dialog background picture Pin
aarontan30-Jun-05 15:22
aarontan30-Jun-05 15:22 
Questioncode to estimate center of sphere? Pin
Member 208234129-Jun-05 21:56
Member 208234129-Jun-05 21:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.