THIS NEEDS TO BE DONE IN C AND C ONLY PLEASE FOLLOW ALL DIRE

THIS NEEDS TO BE DONE IN C++ AND C++ ONLY!!! PLEASE FOLLOW ALL DIRECTIONS AND MAKE SURE IT WILL COMPILE AND OUTPUT IS CORRECT. PLEASE DOCUMENT EVERYTHING!! // AND EXPLAIN IF POSSIBLE TOO THANK YOU!!!!!

*********MAKE SURE THE OUTPUT IS THE SAME AT BOTTOM OR DONT ANSWER!! IT IS WRONG WITHOUT THE SAME EXACT OUTPUT!!!!!!!!***********

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 (**********NEEDS TO MATCH THIS OUTPUT EXACTLY OR DONT SUBMIT YOUR ANSWER!!!! IT IS WRONG WITHOUT THIS EXACT OUTPUT!!!!!************)

The number is 2700
----------------------------------------------------
Adding the digits result 9
Reversing the digits result 72

Odd digits 1
Even digits 3
Zeroes 2


The number is 18614
----------------------------------------------------
Adding the digits result 20
Reversing the digits result 41681

Odd digits 2
Even digits 3
Zeroes 0


The number is 31546
----------------------------------------------------
Adding the digits result 19
Reversing the digits result 64513

Odd digits 3
Even digits 2
Zeroes 0


The number is 18773
----------------------------------------------------
Adding the digits result 26
Reversing the digits result 37781

Odd digits 4
Even digits 1
Zeroes 0


The number is 26625
----------------------------------------------------
Adding the digits result 21
Reversing the digits result 52662

Odd digits 1
Even digits 4
Zeroes 0


The number is 818
----------------------------------------------------
Adding the digits result 17
Reversing the digits result 818

Odd digits 1
Even digits 2
Zeroes 0


The number is 21877
----------------------------------------------------
Adding the digits result 25
Reversing the digits result 77812

Odd digits 3
Even digits 2
Zeroes 0


The number is 5852
----------------------------------------------------
Adding the digits result 20
Reversing the digits result 2585

Odd digits 2
Even digits 2
Zeroes 0


The number is 32516
----------------------------------------------------
Adding the digits result 17
Reversing the digits result 61523

Odd digits 3
Even digits 2
Zeroes 0


The number is 673
----------------------------------------------------
Adding the digits result 16
Reversing the digits result 376

Odd digits 2
Even digits 1
Zeroes 0

Solution

#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;


class myInt{
private :
int data   ;
public :
//default constructor
   myInt(){
       this->data=0;
   }
   // paramaterized constructor
   myInt(int data){
       setInt(data);//calling the methid to set the data
   }
  
   //setter method
   void setInt(int data) {
   this->data = abs(data);
   }
   //getter method  
   int getInt() {
       return data;
   }  
   //print the data
   void print(){
   cout<< data << endl;
   }
     
   //sum of the digits of the number
   int sumDigits(){
   int temp=data;
           int sum=0;
           while(temp!=0){
           sum+=temp%10;//remainder of the number
           temp=temp/10;//quotient of the number
           }
          
           return sum;
          
   }
//reverse the number
   int reverse(){
   int temp=data;
       int reverseNum=0;
       while(temp!=0){
           reverseNum=reverseNum*10+temp%10;//adding remainder to the reverseNum
           temp=temp/10;//quotient of the number
           }
          
           return reverseNum;
   }
     
   // odd digit count
   int oddDigitCount(){
   int temp=data;
           int count=0;
           while(temp!=0){
           int num=temp%10;//remainder of the number
           if(num!=0 && !(num%2==0)){
           count++;
           }
           temp=temp/10;//quotient of the number
           }
          
           return count;
         
     
     
   }
     
   //even digit count
   int evenDigitCount(){
   int temp=data;
           int count=0;
           while(temp!=0){
           int num=temp%10;
           if(num==0 || num%2==0){
           count++;
           }
           temp=temp/10;
           }
          
           return count;
       }
     
   // zero count
   int zeroCount(){
   int temp=data;
           int count=0;
           while(temp!=0){
           int num=temp%10;
           if(num==0){
           count++;
           }
           temp=temp/10;
           }
          
           return count;
   }

};

int main()
{
  
   //seed with 815
srand(815);
for (int i =0;i<10; i++)// for loop for 10 times
{
  
int randNum=(rand()%10000)+1;//random number generator
cout<<\"\ The Number is \"<<randNum<<endl;
   cout<<\"----------------------------------------------------\";
   myInt obj(randNum);// creating object and passing the number to constructor
   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 digits \"<<obj.zeroCount()<<endl;

     
}

return 0;
}

----------------------------------------------------output--------------------------------------------------------------


The Number is 5680
----------------------------------------------------
Adding the digits result 19

Reversing the digits result 865

Odd digits 1

Even digits 3

Zeroes digits 1

The Number is 6930
----------------------------------------------------
Adding the digits result 18

Reversing the digits result 396

Odd digits 2

Even digits 2

Zeroes digits 1

The Number is 3456
----------------------------------------------------
Adding the digits result 18

Reversing the digits result 6543

Odd digits 2

Even digits 2

Zeroes digits 0

The Number is 4831
----------------------------------------------------
Adding the digits result 16

Reversing the digits result 1384

Odd digits 2

Even digits 2

Zeroes digits 0

The Number is 336
----------------------------------------------------
Adding the digits result 12

Reversing the digits result 633

Odd digits 2

Even digits 1

Zeroes digits 0

The Number is 6407
----------------------------------------------------
Adding the digits result 17

Reversing the digits result 7046

Odd digits 1

Even digits 3

Zeroes digits 1

The Number is 3949
----------------------------------------------------
Adding the digits result 25

Reversing the digits result 9493

Odd digits 3

Even digits 1

Zeroes digits 0

The Number is 1681
----------------------------------------------------
Adding the digits result 16

Reversing the digits result 1861

Odd digits 2

Even digits 2

Zeroes digits 0

The Number is 3443
----------------------------------------------------
Adding the digits result 14

Reversing the digits result 3443

Odd digits 2

Even digits 2

Zeroes digits 0

The Number is 1954
----------------------------------------------------
Adding the digits result 19

Reversing the digits result 4591

Odd digits 3

Even digits 1

Zeroes digits 0

THIS NEEDS TO BE DONE IN C++ AND C++ ONLY!!! PLEASE FOLLOW ALL DIRECTIONS AND MAKE SURE IT WILL COMPILE AND OUTPUT IS CORRECT. PLEASE DOCUMENT EVERYTHING!! // A
THIS NEEDS TO BE DONE IN C++ AND C++ ONLY!!! PLEASE FOLLOW ALL DIRECTIONS AND MAKE SURE IT WILL COMPILE AND OUTPUT IS CORRECT. PLEASE DOCUMENT EVERYTHING!! // A
THIS NEEDS TO BE DONE IN C++ AND C++ ONLY!!! PLEASE FOLLOW ALL DIRECTIONS AND MAKE SURE IT WILL COMPILE AND OUTPUT IS CORRECT. PLEASE DOCUMENT EVERYTHING!! // A
THIS NEEDS TO BE DONE IN C++ AND C++ ONLY!!! PLEASE FOLLOW ALL DIRECTIONS AND MAKE SURE IT WILL COMPILE AND OUTPUT IS CORRECT. PLEASE DOCUMENT EVERYTHING!! // A
THIS NEEDS TO BE DONE IN C++ AND C++ ONLY!!! PLEASE FOLLOW ALL DIRECTIONS AND MAKE SURE IT WILL COMPILE AND OUTPUT IS CORRECT. PLEASE DOCUMENT EVERYTHING!! // A
THIS NEEDS TO BE DONE IN C++ AND C++ ONLY!!! PLEASE FOLLOW ALL DIRECTIONS AND MAKE SURE IT WILL COMPILE AND OUTPUT IS CORRECT. PLEASE DOCUMENT EVERYTHING!! // A
THIS NEEDS TO BE DONE IN C++ AND C++ ONLY!!! PLEASE FOLLOW ALL DIRECTIONS AND MAKE SURE IT WILL COMPILE AND OUTPUT IS CORRECT. PLEASE DOCUMENT EVERYTHING!! // A
THIS NEEDS TO BE DONE IN C++ AND C++ ONLY!!! PLEASE FOLLOW ALL DIRECTIONS AND MAKE SURE IT WILL COMPILE AND OUTPUT IS CORRECT. PLEASE DOCUMENT EVERYTHING!! // A
THIS NEEDS TO BE DONE IN C++ AND C++ ONLY!!! PLEASE FOLLOW ALL DIRECTIONS AND MAKE SURE IT WILL COMPILE AND OUTPUT IS CORRECT. PLEASE DOCUMENT EVERYTHING!! // A

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site