I need a Programme in C++ ?

Home » Programming & Design » I need a Programme in C++ ?
Programming & Design No Comments

Write a Program to find largest of four integer numbers in C++, Program should have three class and each class should have 1 Integer?

Other answer:

Nepali:
Having three classes would be a terrible design. A class that has an integer is what you want, then you'll use instances of that class. For example:

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <ctime>

using namespace std;

const int N(99);
int random(int range);

class MyInt {
. public:
. . MyInt() : _val(0) { }
. . MyInt(int val) : _val(val) { }
. . ~MyInt() { }
. . MyInt(const MyInt &i2) { _val = i2._val; }
. . inline int val() { return _val; }
. . void operator=(const MyInt &i2) { _val = i2._val; }
. . bool operator<(const MyInt &i2) { return _val < i2._val; }
. private:
. . int _val;
};

ostream &operator<<(ostream &os, MyInt &i) {
. . os << i.val();
. . return os;
}

int main(int argc, char *argv[]) {
. . time_t t;
. . srand((unsigned)time(&t));
. . MyInt x(random(N)), y(random(N)), z(random(N)), w(random(N));

. . cout << x << ' ' << y << ' ' << z << ' ' << w << ' ' << endl;
. . cout << "max = " << max(x.val(), max(y.val(), max(z.val(), w.val()))) << endl;

. . return 0;
}

int random(int range) {
. . double x = (rand() % range);
. . return static_cast<int>(x);
}

#if 0

Sample runs:

62 8 27 59
max = 62

40 67 29 69
max = 69

0 23 26 2
max = 26

#endif

Saya:
Do it yourself
Pankaj Adiley:
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,d,big;
clrscr();
cout<<"Enter four numbers\n";
cin>>a>>b>>c>>d;
big=a;
if(big>b) big=b;
if(big>c) big=c;
if(big>d) big=d;
count<<"Big="<<big;
getch();
}
megan:
Idk

LEAVE A COMMENT