| | |
please someone help me urgent
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2005
Posts: 13
Reputation:
Solved Threads: 0
please someone give me some idea to write this program
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
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
Follow the instructions as best you can to begin developing some code. When you get stuck, post the code you have (within [code][/code] tags) and any error messages you get; then you can ask a more specific question. [And "I don't even know where to begin" is not the kind of post that will get much attention --please read the Announcement -- especially when the instructions provide many clues .]
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include<iostream> class math { public: math() { i= 0; }; math(int i ) { i = i; }; ~math() { }; int operator+ ( int x) { return(x+i); }; int operator-(int x) { return(i -x ); }; int operator*(int x) { return(i*x); }; friend int operator +( int x , math obj) { return( x+obj.i); }; friend int operator -( int x , math obj) { return(x - (obj.i) ); }; friend int operator *( int x , math obj) { return(obj.i*x); }; void Display() { cout << "i=" << i << endl; }; private: int i; }; int main() { math obj1, obj2, obj3; obj2= obj1 + 20 ; obj3 = 20 + obj1; return 0; }
To grab from the standard namespace, you'll need to say so. For now, just do this to get cout and endl.
This doesn't give me a warm fuzzy feeling.
Perhaps do something like this so it's easier to figure out which is who. [edit]Function definitions don't end with a semicolon after the closing brace.[/edit]
Here it would be a good idea to initialize obj1. [edit]Oops. C-mode. Forgot about default constructor.[/edit]
And don't forget to ask questions when you post your code.
#include<iostream>
using namespace std; math(int i )
{
i = i;
}; C++ Syntax (Toggle Plain Text)
math(int init) { i = init; }
int main()
{
math obj1, obj2, obj3;
obj2= obj1 + 20 ;
obj3 = 20 + obj1;
return 0;
} "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: May 2005
Posts: 13
Reputation:
Solved Threads: 0
i write following program but my program does not run and not given required output. please someone check this and correct this or write this in better form.thanks. program and coding is given below:
program:
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
Code:
<< moderator edit: added [code][/code] tags >>
program:
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
Code:
C++ Syntax (Toggle Plain Text)
#include<iostream.h> class mth { friend class number; Public: class math(): int (0){} void print member (){ cout<<number<<endl; } operator float(); object add (+); object sub(-); object multi (*); { //The implementation is object:add,sub,multi,} Private: i=10; }; //friend functions friend float add both(class math,number class); friend float sub both(class math,number class); friend float multi both(class math,number class); }; class number {Private: float value; public: number class() { value=10; } //friend functions friend float add both(class math,number class); friend float sub both(class math,number class); friend float multi both(class math,number class); }; void int main() { mth obj1,obj2; obj1=obj2+10; obj2=10+obj1; obj2=10*obj1; char choice; cout<<"pleae enter one of the operator +,-,*:"; if (choice=='+') {cout<<"adding integer 10 in the object using statement:"; if (choice=='+') {cout<<"adding object 10 in the object using statement:"; if (choice=='*') {cout<<"multi object 20 in the object using statement:"; if (choice=='*') {cout<<"multi integer 20 in the object using statement:"; if (choice=='-') {cout<<"sub 20 from the object using statement:"; if (choice=='-') {cout<<"sub obj from 10 using statement:"; } system("PAUSE"); getch(); }
![]() |
Similar Threads
- pls heeeeeeeeelp its urgent. (C)
- Urgent! (C++)
- URGENT: Need help on I/O code! (Java)
- Urgent help (Networking Hardware Configuration)
- Homepage keeps switching back to a porn site (Web Browsers)
- Importing SQL Script File - Urgent !! (Database Design)
Other Threads in the C++ Forum
- Previous Thread: Double Arrays HELP!!!!!!
- Next Thread: Linking Error
Views: 1696 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project python random read recursion recursive reference return sort stream string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






