Question

Write the definitions of the member functions of the class integerManipulation not given in Example 10-11....

Write the definitions of the member functions of the class integerManipulation not given in Example 10-11. Also, add the following operations to this class:

Split the number into blocks of n-digit numbers starting from right to left and find the sum of these n-digit numbers. (Note that the last block may not have ndigits. If needed add additional instance variables.)

Determine the number of zeroes.

Determine the number of even digits.

Determine the number of odd digits

Also, write a program to test theclass integerManipulation.

The header file for class integerManipulation has been provided for you.

  
class integerManipulation
{
public:
void setNum(long long n);
//Function to set num.
//Postcondition: num = n;

long long getNum();
//Function to return num.
//Postcondition: The value of num is returned.

void reverseNum();
//Function to reverse the digits of num.
//Postcondition: revNum is set to num with digits in
// in the reverse order.

void classifyDigits();
//Function to count the even, odd, and zero digits of num.
//Postcondition: evenCount = the number of even digits in num.
// oddCount = the number of odd digits in num.

int getEvensCount();
//Function to return the number of even digits in num.
//Postcondition: The value of evensCount is returned.

int getOddsCount();
//Function to return the number of odd digits in num.
//Postcondition: The value of oddscount is returned.

int getZerosCount();
//Function to return the number of zeros in num.
//Postcondition: The value of zerosCount is returned.

int sumDigits();
//Function to return the sum of the digits of num.
//Postcondition: The sum of the digits is returned.

integerManipulation(long long n = 0);
//Constructor with a default parameter.
//The instance variable num is set accordingto the parameter,
//and other instance variables are set to zero.
//The default value of num is 0;
//Postcondition: num = n; revNum = 0; evenscount = 0;
// oddsCount = 0; zerosCount = 0;

private:
long long num;
long long revNum;
int evensCount;
int oddsCount;
int zerosCount;
};

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

#include <fstream>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <vector>
using namespace std;

class integerManipulation
{
public:
void setNum(long long n);
//Function to set num.
//Postcondition: num = n;

long long getNum();
//Function to return num.
//Postcondition: The value of num is returned.

void reverseNum();
//Function to reverse the digits of num.
//Postcondition: revNum is set to num with digits in
// in the reverse order.

void classifyDigits();
//Function to count the even, odd, and zero digits of num.
//Postcondition: evenCount = the number of even digits in num.
// oddCount = the number of odd digits in num.

int getEvensCount();
//Function to return the number of even digits in num.
//Postcondition: The value of evensCount is returned.

int getOddsCount();
//Function to return the number of odd digits in num.
//Postcondition: The value of oddscount is returned.

int getZerosCount();
//Function to return the number of zeros in num.
//Postcondition: The value of zerosCount is returned.

int sumDigits();
//Function to return the sum of the digits of num.
//Postcondition: The sum of the digits is returned.

integerManipulation(long long n = 0);
//Constructor with a default parameter.
//The instance variable num is set accordingto the parameter,
//and other instance variables are set to zero.
//The default value of num is 0;
//Postcondition: num = n; revNum = 0; evenscount = 0;
// oddsCount = 0; zerosCount = 0;

private:
long long num;
long long revNum;
int evensCount;
int oddsCount;
int zerosCount;
};
void integerManipulation::setNum(long long n)
{
   this->num=n;

}
long long integerManipulation::getNum()
{
   return num;
}
void integerManipulation::reverseNum()
{
   int num1=num;
   int remainder;
   int sum=0;
   long long reverse_number = 0;
   while (num1 > 0)
{
remainder = num1 % 10;

reverse_number = reverse_number * 10 +remainder;
num1 /= 10;
}
this->revNum=reverse_number;
cout<<"The Reverse Number is :"<<revNum<<endl;
}
void integerManipulation::classifyDigits()
{

   int remainder;
int num1=num;

   while (num1 > 0)
{
remainder = num1 % 10;
if (remainder % 2 == 0)
{
this->evensCount++;
}
else if(remainder%2!=0)
{
this->oddsCount++;
}
else if(remainder==0)
{
   this->zerosCount++;
           }
num1 /= 10;
}
  
}
int integerManipulation::getEvensCount()
{
   return evensCount;
}
int integerManipulation::getOddsCount()
{
   return oddsCount;
}
int integerManipulation::getZerosCount()
{
   return zerosCount;
}
int integerManipulation::sumDigits()
{
   // Declaring variables
   int sum=0;
       int remainder;
int num1=num;

   while (num1 > 0)
{
remainder = num1 % 10;
sum+=remainder;
num1 /= 10;
}
   return sum;
  
}
integerManipulation::integerManipulation(long long n)
{
   this->num=n;
   this->revNum = 0;
   this->evensCount= 0;
this->oddsCount = 0;
   this->zerosCount = 0;
  
}


int main() {
   //Declaring variables
integerManipulation im(123456789);
cout<<"Original Number :"<<im.getNum()<<endl;
   im.reverseNum();
   im.classifyDigits();
cout<<"Sum of digits :"<<im.sumDigits()<<endl;
cout<<"No of odd Digits :"<<im.getOddsCount()<<endl;
cout<<"No of even digits :"<<im.getEvensCount()<<endl;
cout<<"No of Zero digits :"<<im.getZerosCount()<<endl;
  
  
   return 0;
}

____________________________

Output:

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Write the definitions of the member functions of the class integerManipulation not given in Example 10-11....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can some help me with my code I'm not sure why its not working. Thanks In...

    Can some help me with my code I'm not sure why its not working. Thanks In this exercise, you are to modify the Classify Numbers programming example in this chapter. As written, the program inputs the data from the standard input device (keyboard) and outputs the results on the standard output device (screen). The program can process only 20 numbers. Rewrite the program to incorporate the following requirements: a. Data to the program is input from a file of an...

  • Functions can return a string, not just an int or a float. Write a function called...

    Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a number:...

  • (use only variables, expression, conditional statement and loop of c programming) ***C programming** int sum_of_cubes(int n)...

    (use only variables, expression, conditional statement and loop of c programming) ***C programming** int sum_of_cubes(int n) { } int quadrant(int x, int y) { } int num_occurrences_of_digit(long num, int digit) { return 0; } 3.1 int sum_of_cubes(int n) This function should return the sum of the cubes of the first n integers. For example, if n is 4, it should return 13 +23+ 39 +4°. There is a simple formula for the result: 3x = ((n + 1)) = +...

  • need help..... sudoku.h class sudoku { public: sudoku(); //default constructor //Postcondition: grid is initialized to 0...

    need help..... sudoku.h class sudoku { public: sudoku(); //default constructor //Postcondition: grid is initialized to 0 sudoku(int g[][9]); //constructor //Postcondition: grid = g void initializeSudokuGrid(); //Function to prompt the user to specify the numbers of the //partially filled grid. //Postcondition: grid is initialized to the numbers // specified by the user. void initializeSudokuGrid(int g[][9]); //Function to initialize grid to g //Postcondition: grid = g; void printSudokuGrid(); //Function to print the sudoku grid. bool solveSudoku(); //Funtion to solve the sudoku problem....

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • Given the following date class interface: class date {private: int month;//1 - 12 int day;//1 -...

    Given the following date class interface: class date {private: int month;//1 - 12 int day;//1 - 28. 29. 30. 31 depending on month & year int year;//4-digit, e.g.. 2017 public: date();//Default constructor (investigate; find what it is used for)//Postcondition: the newly declared date object is initialized to 01/01/2000 date(int mm, int dd, int yyyy);//Second constructor//Postcondition: the newly declared data object is initialized to mm/dd/yyyy void setDate(int mm. int dd. int yyyy);//Postcondition: set the contents of the calling date object to...

  • Write in C++ please In Chapter 10, the class clockType was designed to implement the time...

    Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...

  • 2 Class Vec Message1 2.1 Introduction • Write a class Vec Message1 with the following declaration....

    2 Class Vec Message1 2.1 Introduction • Write a class Vec Message1 with the following declaration. class Vec_Message1 { public: Vec_Message1(); Vec_Message1(int n); Vec_Message1(int n, const Message1 &a); Vec_Message1(const Vec_Message1 &orig); Vec_Message1& operator= (const Vec_Message1 &rhs); ~Vec_Message1(); int capacity() const; int size() const; Message1 front() const; Message1 back() const; void clear(); void pop_back(); void push_back(const Message1 &a); Message1& at(int n); private: void allocate(); void release(); int _capacity; int _size; Message1 * _vec; }; 2.2 allocate() and release() • Examine the...

  • Write a C++ program that simulate a menu based binary number calculator.You don't have to write the main part of the...

    Write a C++ program that simulate a menu based binary number calculator.You don't have to write the main part of the program just the two functions for my C++ program. I wanted to post the sample code from my class but it won't allow me it's too long. This calculate shall have the following five functionalities: Provide sign extension for a binary number Provide two’s complement for a binary nunber string signed_extension(string b);              // precondition: s is a string that...

  • The table shows the PPT functions we learned in class. You will try to get the...

    The table shows the PPT functions we learned in class. You will try to get the sum of 0 to N. First, modify the following function. And translate the C code to ARM assembly code. Describe the process by substituting 3 for the N value. (You have to briefly write comment at each lines in your ARM code!!!) int function (int num) if (num< 1) return 1; else return num * function(num - 1);

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT