Overview For this assignment implement and use the methods f
Overview
For this assignment, implement and use the methods for a class called myInt.
myInt class
The myInt class is used to represent a non-negative integer and some tasks that can be performed on the integer.
Data Members
The class contains one data member.
An integer that holds a value
Constructor
This class has two constructors.
The first constructor is a default constructor (i.e. one that takes no arguments). It should simply initialize the integer data member to 0.
The second constructor takes one argument: an integer that will be used to initialize the integer data member. Call the setInt method that is described below to do the initialization.
Methods
void print()
This method displays the integer data member. It takes no arguments and returns nothing.
int getInt()
This accessor method returns the value of the integer data member. It takes no arguments and returns an integer.
void setInt( int )
This accessor method is used to change the value of the integer data member. It takes one argument: an integer that will potentially be used to update the value of the integer data member. It returns nothing.
If the passed in value is non-negative, use it to update the value of the integer data member. If the passed in value is negative, use the absolute value of the passed in value to update the value of the integer data member.
The cmath library has a function called abs that takes one integer as its argument. It returns the absolute value of the integer.
int sumDigits()
This method will calculate and return the sum of adding the individual digits of the integer data member. For example, if an object contains an integer data member with the value 641, the method should return 11 (the sum of 6 + 4 + 1).
The method takes no arguments and returns an integer: the sum of the digits.
To isolate each of the digits in an integer number, use modulus division by 10. For example, 641 % 10 = 1. To remove a digit from an integer number, use integer division by 10. For example, 641 / 10 = 64. Therefore, to calculate the sum of the digits in an integer number, the logic that is described above can be put inside of a loop that executes until there are no longer any digits to remove from the integer number. Each iteration of the loop should take each isolated number and add it to a running total.
One final not about sumDigits, the value in the integer data member should not be changed.
int reverse()
This method will reverse the digits in the integer data member. For example, if an object contains an integer data member with the value 641, the method should return 146.
The method takes no argument and returns an integer that has a value equal to the reversed number.
To reverse the digits in a number, take advantage of the two properties that were described in the description of the sumDigits method. Namely, that modulus division by 10 can be used to isolate a number and integer division by 10 can be used to remove a number. The reversed number can then be calculated by using simple addition.
To start the process, initialize a variable (say reverseNum) to 0. This will be the variable that holds the reversed number. Inside of a loop that executes as long as the integer number has digits to be removed:
multiply reverseNum by 10
isolate a digit from the number
add the isolated digit to reverseNum
remove a digit from the number
For example, assuming the original value is 641, following the process described above results in:
Iteration #1:
0 * 10 = 0 (remember that reverseNum initially contains 0)
isolate the 1 from 641
0 + 1 = 1
remove the 1 from 641 so the next value is 64
Iteration #2:
1 * 10 = 10
isolate the 4 from 64
10 + 4 = 14
remove the 4 from 64 so the next value is 6
Iteration #3:
14 * 10 = 140
isolate the 6 from 6
140 + 6 = 146
remove the 6 from 6 so the next value is 0
Now the digits have been reversed and the result is 146 and is saved in reverseNum.
As with the sumDigits method, the value in the integer data member should not be changed.
int oddDigitCount()
This method will count the number of odd digits that are part of the value in the integer data member. It takes no argument and returns an integer: the count of the odd digits.
To count the number of odd digits in a number, take advantage of the two properties that have been used in the sumDigits and reverse methods.
The value in the integer data member should not be changed.
int evenDigitCount()
This method will count the number of even digits that are part of the value in the integer data member. It takes no argument and returns an integer: the count of the even digits.
To count the number of even digits in a number, take advantage of the two properties that have been used in the sumDigits and reverse methods.
The value in the integer data member should not be changed.
Note: zero is considered an even number.
int zeroCount()
This method will count the number of zeroes that are part of the value in the integer data member. It takes no argument and returns an integer: the count of the zeroes.
To count the number of zeroes in a number, take advantage of the two properties that have been used in the sumDigits and reverse methods.
The value in the integer data member should not be changed.
Using the myInt class
For this part of the program, a myInt object will be created and the various methods that were written for the class will be called.
In a loop that executes exactly 10 times, get a random number, use the random number to set the value of the myInt object, and display the number, the sum of the digits, the reversed digits, the number of odd digits, the number of even digits, and the number of zeros.
Programming Requirements
Use a seed value of 815 for the random number generator.
Make sure to add #include statements for the cstdlib library.
Each method must have a documentation box like a function.
Hand in a copy of the source code using Blackboard.
Output
Extra Credit
For up to 5 points of extra credit, modify the class so that it can hold integer values with a range larger than the current + 2 billion. This should be done by changing the data type of the data member from int to long long. The long long data type will increase the range of possible values to roughly + 9 quintillion.
Any method that uses the numeric value should be updated to use the data type long long rather than int. However, don\'t simply change every single int in the class to long long. Change only the ones that need to be changed.
After updating the data type, make sure that the code that was previously written in main still works as before.
Finally, add code to main that will create a new myInt object with the value 90237104628012645. Call the sumDigits, reverse, oddDigitCount, evenDigitCount, and zeroCount methods for the new object and display the values that are returned with labels. Use the setInt method to try to change the value to -5058675309. Call the 5 methods again and display the new results.
Note about extra credit: the points will ONLY be awarded if the required portions of the assignment work correctly. In other words, don\'t take short cuts in the rest of the program because it is assumed that 5 extra points will be awarded.
Extra Credit Output
Solution
#include<bits/stdc++.h>
 using namespace std;
 class myInit
 {
 long long myint;
 public:
myInit()
 {
    myint=0;
 }
myInit(long long a)
 {
    if(a<0)
    {
        myint=abs(a);
   }
    else
    myint=a;
 }
void setint(long long a) //ser int
 {
    if(a<0)
    {
        myint=abs(a);
   }
    else
    myint=a;
 }
void print()//print number
 {
    cout<<\"The number is \"<<myint<<endl;
 }
 int getint(long long a)//get number
 {
    return myint;
 }
int sumDigits()//get sum of digits
 {
    long long a=myint;
    int sum=0,rem;
   while(a)
    {
        rem=a%10;
        sum+=rem;
        a=a/10;
    }
 return sum;
 }
long long reverse() //reverse number
 {
            long long reverse=0;
            long long a=myint;
           while(a!=0)
            {
                reverse=reverse*10;
                reverse=reverse+a%10;
                a=a/10;
            }
            return reverse;
 }
int oddDigitCount()//count odd digits in number
 {
   long long a=myint;
    int oddcount=0,rem;
   while(a)
    {
        rem=a%10;
        if(rem%2!=0)
            oddcount++;
        a=a/10;
    }
    return oddcount;
 }
int evenDigitCount() //count even digits in number
 {
   long long a=myint;
    int evencount=0,rem;
   while(a)
    {
        rem=a%10;
        if(rem%2==0)
            evencount++;
        a=a/10;
    }
    return evencount;
 }
int zeroDigitCount()//count zero in number
 {
    long long a=myint;
    int zerocount=0,rem;
   while(a)
    {
        rem=a%10;
        if(rem==0)
            zerocount++;
        a=a/10;
    }
    return zerocount;
}
 };
int main(int argc, char const *argv[])
 {
    srand (815);
    myInit obj;
   
   for (int t=0;t<10;t++)
    {
 long long num;
 
    num= rand();
   
    obj.setint(num);//create object
    obj.print();//print number
    cout<<\"----------------------------------------------------\ \";
    
    cout<<\"Adding the digits result \"<<obj.sumDigits()<<endl;
    cout<<\"Reversing the digits result \"<<obj.reverse()<<endl;
    cout<<\"Odd digits \"<<obj.oddDigitCount()<<endl;
    cout<<\"Even digits \"<<obj.evenDigitCount()<<endl;
    cout<<\"Zeroes \"<<obj.zeroDigitCount()<<endl;
 cout<<endl;
 cout<<endl;
   }
      
    return 0;
 }
=============================================================
output:
The number is 90237104628012645
 ----------------------------------------------------
 Adding the digits result 60
 Reversing the digits result 54621082640173209
 Odd digits 6
 Even digits 11
 Zeroes 3
 The number is 90237104628012645
 ----------------------------------------------------
 Adding the digits result 60
 Reversing the digits result 54621082640173209
 Odd digits 6
 Even digits 11
 Zeroes 3
 The number is 90237104628012645
 ----------------------------------------------------
 Adding the digits result 60
 Reversing the digits result 54621082640173209
 Odd digits 6
 Even digits 11
 Zeroes 3
 The number is 90237104628012645
 ----------------------------------------------------
 Adding the digits result 60
 Reversing the digits result 54621082640173209
 Odd digits 6
 Even digits 11
 Zeroes 3
 The number is 90237104628012645
 ----------------------------------------------------
 Adding the digits result 60
 Reversing the digits result 54621082640173209
 Odd digits 6
 Even digits 11
 Zeroes 3
 The number is 90237104628012645
 ----------------------------------------------------
 Adding the digits result 60
 Reversing the digits result 54621082640173209
 Odd digits 6
 Even digits 11
 Zeroes 3
 The number is 90237104628012645
 ----------------------------------------------------
 Adding the digits result 60
 Reversing the digits result 54621082640173209
 Odd digits 6
 Even digits 11
 Zeroes 3
 The number is 90237104628012645
 ----------------------------------------------------
 Adding the digits result 60
 Reversing the digits result 54621082640173209
 Odd digits 6
 Even digits 11
 Zeroes 3
 The number is 90237104628012645
 ----------------------------------------------------
 Adding the digits result 60
 Reversing the digits result 54621082640173209
 Odd digits 6
 Even digits 11
 Zeroes 3
 The number is 90237104628012645
 ----------------------------------------------------
 Adding the digits result 60
 Reversing the digits result 54621082640173209
 Odd digits 6
 Even digits 11
 Zeroes 3
 akshay@akshay-Inspiron-3537:~/Chegg$ g++ myint.cpp
 akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
 The number is 1202725679
 ----------------------------------------------------
 Adding the digits result 41
 Reversing the digits result 9765272021
 Odd digits 5
 Even digits 5
 Zeroes 1
 The number is 294946929
 ----------------------------------------------------
 Adding the digits result 54
 Reversing the digits result 929649492
 Odd digits 4
 Even digits 5
 Zeroes 0
 The number is 1369563455
 ----------------------------------------------------
 Adding the digits result 47
 Reversing the digits result 5543659631
 Odd digits 7
 Even digits 3
 Zeroes 0
 The number is 783894830
 ----------------------------------------------------
 Adding the digits result 50
 Reversing the digits result 38498387
 Odd digits 4
 Even digits 5
 Zeroes 1
 The number is 451510335
 ----------------------------------------------------
 Adding the digits result 27
 Reversing the digits result 533015154
 Odd digits 7
 Even digits 2
 Zeroes 1
 The number is 962006406
 ----------------------------------------------------
 Adding the digits result 33
 Reversing the digits result 604600269
 Odd digits 1
 Even digits 8
 Zeroes 3
 The number is 1512983948
 ----------------------------------------------------
 Adding the digits result 50
 Reversing the digits result 8493892151
 Odd digits 6
 Even digits 4
 Zeroes 0
 The number is 895491680
 ----------------------------------------------------
 Adding the digits result 50
 Reversing the digits result 86194598
 Odd digits 4
 Even digits 5
 Zeroes 1
 The number is 968143442
 ----------------------------------------------------
 Adding the digits result 41
 Reversing the digits result 244341869
 Odd digits 3
 Even digits 6
 Zeroes 0
 The number is 2097951953
 ----------------------------------------------------
 Adding the digits result 50
 Reversing the digits result 3591597902
 Odd digits 8
 Even digits 2
 Zeroes 1









