Question #20758

create aclass that imitates part of functionality of the basic data type int call the class int. 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 and to add two int values


write aprogram that exercises this class by creating two initialized values and placing the response in the uninitialized value and then displaying this result

with flowchart and algorithm

Expert's answer

#include <iostream>
using namespace std;

class Int {
private:
int k1,k2;

public:
Int(int _k1, int _k2):k1(_k1),k2(_k2){};
void print();
};

void Int::print(){
cout<<k1<<" quot;<<k2;
}

int main(int argc, const char * argv[])
{
int k1,k2;
cin>>k1>>k2;
Int obj(k1,k2);
obj.print();

return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS