Question

Write a C++ program that does the following : Define a class myInt that has as...

Write a C++ program that does the following :

Define a class myInt that has as its single attribute an integer variable and that contains member functions for determining the following information for an object of type myInt:

A. Is it multiple of 7 , 11 , or 13.

B. Is the sum of its digits odd or even.

C. What is the square root value.

D.Is it a prime number.

E. Is it a perfect number ( The sum of the factors of a perfect number is equal to the number itself – for example : 1 + 2 + 4 + 7 + 14 = 28 , so 28 is a perfect number ).

F. All of the above.

Z. Exit Write a interface that tests your functions

NOTES:

• Just one .cpp ( Header file , implementation of header file and the interface all in one program)

• Must define a class with at least 6 functions. • Do not use arrays … etc.

• Validation on the menu selection.

• Validation on the integer value that is entered by the user.

• Free output format.

• Test your functions by entering values such as 104 , 3773 , 13 , 121 , 77 , 3075

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

#include <iostream>
#include<math.h>

using namespace std;

class Special_Number
{

private:
int myInt;

public:

Special_Number(int num)
{
this->myInt=num;
}

void isMultiple()
{

if(myInt%7==0)
{
cout<<"Its a multiple of 7"<<endl;
}
else
{
cout<<"Its not a multiple of 7"<<endl;
}

if(myInt%11==0)
{
cout<<"Its a multiple of 11"<<endl;
}
else
{
cout<<"Its not a multiple of 11"<<endl;
}

if(myInt%13==0)
{
cout<<"Its a multiple of 13"<<endl;
}
else
{
cout<<"Its not a multiple of 13"<<endl;
}

}

void sumOfDigitsOddEven()
{

int num = myInt;
int sum=0;
while(num!=0)
{
sum +=num%10;
num = num/10;
}
if(sum%2==0)
{
cout<<"Sum of digits is even"<<endl;
}
else
{
cout<<"Sum of digits is odd"<<endl;
}

}

void squareRoot()
{
cout<<"Square Root is: "<<sqrt(myInt)<<endl;
}


void perfectNumber()
{

int factorSum=0;
for(int i=1; i<=myInt/2; i++)
{

if(myInt%i==0)
{
factorSum+=i;
}
}
if(factorSum==myInt)
{

cout<<"Its a perfect number"<<endl;
}
else
{
cout<<"Its not a perfect number"<<endl;
}


}
};


int main()
{

char choice;
int number;
cout<<"Enter a number to test: ";
cin>>number;
Special_Number aNumber(number);

cout<<"A. Is it multiple of 7 , 11 , or 13."<<endl;
cout<<"B. Is the sum of its digits odd or even."<<endl;
cout<<"C. What is the square root value."<<endl;
cout<<"D.Is it a prime number."<<endl;
cout<<"E. Is it a perfect number"<<endl;
cout<<"F. All of the above."<<endl;
cout<<"Enter A, B, C, D, E, F --> ";
cin>>choice;
if (choice=='A')
{
aNumber.isMultiple();
}
else if(choice=='B')
{
aNumber.sumOfDigitsOddEven();
}
else if(choice=='C')
{
aNumber.squareRoot();
}
else if(choice=='E')
{
aNumber.perfectNumber();
}
else if(choice=='F')
{
aNumber.isMultiple();
aNumber.sumOfDigitsOddEven();
aNumber.squareRoot();
aNumber.perfectNumber();
}
else
{
cout<<"Invalid selection"<<endl;
}


}

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that does the following : Define a class myInt that has as...
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
  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Write a C++ program that includes the following: Define the class Student in the header file Stu...

    Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...

  • Write a C program which computes the count of the prime and perfect numbers within a...

    Write a C program which computes the count of the prime and perfect numbers within a given limit Land U, representing the lower and upper limit respectively. Prime numbers are numbers that have only 2 factors: 1 and themselves (1 is not prime). An integer number is said to be perfect number if its factors, including 1 (but not the number itself), sum to the number. Sample Inputi: 1 100 Sample Outputs: Prime: 25 Perfect: 2 Sample Input2: 101 10000...

  • (Please use C language, not C++) Determine the following information about each value in a list...

    (Please use C language, not C++) Determine the following information about each value in a list of positive integers. a. Is the value a multiple of 7, 11, or 13? b. Is the sum of the digits odd or even? (parameter output returns 0 for even, 1 for odd) c. Is the value a prime number? (parameter output returns 0 nonprime, 1 for prime) Use an output file for results. The goal is to implement both pass by value and...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

  • Write a C++ program to define a class having a 4x4 matrix. Generate 32 random numbers...

    Write a C++ program to define a class having a 4x4 matrix. Generate 32 random numbers 1-10, in an output.txt file. Fill the generated numbers in two such class objects (first 16 numbers in one matrix and next 16 numbers in another. Create member functions each for adding, subtracting and multiplication of matrices. Write the algorithm defining steps of your program.

  • (i) Create a class square with attribute (integer) length which defaults to 5. Provide member functions...

    (i) Create a class square with attribute (integer) length which defaults to 5. Provide member functions that calculate the perimeter (4 * length) and the area (length*length) of the triangle. Also provide set and get functions for the length attribute. The set function should verify that length is between 0.0 to 100. Your class should also provide a display function that draws the aquare using * character. For example, if length = 5, the display function should draw             *****...

  • Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part...

    Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part 1: In this assignment, you are asked: Stage1:?Design and implement a class named memberType with the following requirements: An object of memberType holds the following information: • Person’s first name (string)?• Person’s last name (string)?• Member identification number (int) • Number of books purchased (int)?• Amount of money spent (double)?The class memberType has member functions that perform operations on objects of memberType. For the...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • 1. Define a class Rectangle with two attributes: (This is for C++) -length, an integer (default...

    1. Define a class Rectangle with two attributes: (This is for C++) -length, an integer (default value 1) -width, an integer (default value 1) Provide the following member functions: -default constructor -constructor that takes parameters used to initialize the data -get/set function for each attribute -a function perimeter that returns the perimeter of the rectangle -a function area that returns the area of the rectangle b. Write a program that uses the class Rectangle to create two rectangle objects with...

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