Create a class that imitates part of the functionality of the basic data type int. Call the class int (note different capitalization). The only data in this class is an int variable. Include member functions to initialize an int to 0, to initialize it to an int value, to display it (it looks just like an int), and to add two int values. Write a program that exercises this
Answers
Answered by
3
what a big question.......
Answered by
2
Answer:
#include <iostream>
using namespace std;
class Integer
{
private:
int num,num1;
public:
Integer()
{}
Integer(int n)
{
num=n;
}
int add(Integer Int1,Integer Int2)
{
num1=Int1.num+Int2.num;
return num1;
}
};
void main()
{
int number;
Integer Int1(90),Int2(78),Int3;
number=Int3.add(Int1,Int2);
cout<<"1st object number: "<<90<<"\n2nd object number: "<<78<<endl;
cout<<"\n3rd ojbect is sum of 1st and 2nd object: "<<number<<"\n";
}
Explanation:
Similar questions