| | |
Cannot get PAIR::big to just display greater number
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hi,
Appreciate any help. My code compiles... builds.... executes just fine. Only problem I'm having is... I cant figure out how to get PAIR::big() to simply print out the larger #. When I execute... it displays... the Larger # like I want... but then for some reason it displays the smaller number next to it. I want to get rid of the smaller #.
Any suggestions?
Thanks Mike
Appreciate any help. My code compiles... builds.... executes just fine. Only problem I'm having is... I cant figure out how to get PAIR::big() to simply print out the larger #. When I execute... it displays... the Larger # like I want... but then for some reason it displays the smaller number next to it. I want to get rid of the smaller #.
Any suggestions?
Thanks Mike
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; class PAIR { private: int a; int b; public: void print(); PAIR(); PAIR(int); PAIR(int,int); ~PAIR(); void swap(); int diff(); int big(); int area(); }; int main() { PAIR c, d(2), e(12,13); int ans; c.print(); d.print(); e.print(); e.swap(); e.print(); ans = c.diff(); cout << ans << endl; e.big(); e.print(); return 0; } PAIR::PAIR() { a = 2; b= 3; } void PAIR::print() { cout << a << " " << b << endl; } PAIR:: ~PAIR() { cout << "Display Destructor Message" << endl; } PAIR::PAIR(int p1) { a=p1; b=p1; } PAIR::PAIR(int p1,int p2) { a=p1; b=p2; } void PAIR::swap() { int c; c=a; a=b; b=c; } int PAIR::diff() { return b - a; } int PAIR::big() { if (a > b) { return a; } else { return b; } }
Last edited by ToySoldier; Sep 26th, 2006 at 6:00 pm.
•
•
•
•
Hi,
#include <iostream> using namespace std; class PAIR { private: int a; int b; public: void print(); PAIR(); PAIR(int); PAIR(int,int); ~PAIR(); void swap(); int diff(); int big(); int area(); }; int main() { PAIR c, d(2), e(12,13); int ans; c.print(); d.print(); e.print(); e.swap(); e.print(); ans = c.diff(); cout << ans << endl; e.big(); e.print(); return 0; } PAIR::PAIR() { a = 2; b= 3; } void PAIR::print() { cout << a << " " << b << endl; } PAIR:: ~PAIR() { cout << "Display Destructor Message" << endl; } PAIR::PAIR(int p1) { a=p1; b=p1; } PAIR::PAIR(int p1,int p2) { a=p1; b=p2; } void PAIR::swap() { int c; c=a; a=b; b=c; } int PAIR::diff() { return b - a; } int PAIR::big() { if (a > b) { return a; } else { return b; } }
C++ Syntax (Toggle Plain Text)
int big = e.big () ; cout << "\nThe bigger number is " << big ;
Hope it helped, bye.
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- The greater number (C++)
- Last CLASS method needs help... PAIR::area() (C++)
- Anyway to display the Row Number in DataGrid? (ASP.NET)
- Newmember with big problem!!! (C)
- C++ Data Types (C++)
Other Threads in the C++ Forum
- Previous Thread: setprecision
- Next Thread: Soduku puzzle solver
Views: 1510 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






