Answer to Question #242055 in C++ for Imran

Question #242055
Create a class that imitates part of the functionality of the basic data type int, call the
class Int. The only data in this class is an integer variable. Include member functions to
initialize an Int to zero, to initialize it to an integer value and to display it. Write a
program that exercises this class by creating an Int variable and calling its member
functions.
1
Expert's answer
2021-09-25T05:20:34-0400
#include <iostream>


using namespace std;


class Int{
    private:
        int x;
    public:
        void initialize1(){
            x=0;
        }
        void initialize2(int a){
            x=a;
        }
        void disp(){
            cout<<x<<"\n";
        }
};
int main()
{
    Int i;
    i.initialize1();
    i.disp();
    i.initialize2(45);
    i.disp();


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS