Question
This assignment is focused on object oriented programming and inheritance. The problem requires you to create the definitations for the subclass primeFactorizationinherit from a particular
This assignment is focused on object oriented programming and inheritance. The problem requires you to create the definitations for the subclass primeFactorizationinherit from a particular class and create a new subclass with the given name. Most of this is createdYou need to use the concepts of creating a well-defined class as well. Use the attached files to define the functions for primeFactorization. As is the format of the textbook, you will need to use the integerManipulation.h, integerManipulation.cpp, primeFactorization.h, and primeFactorization.cpp files to complete your solution. They are attached to this assignment. You need to modify primeFactorization.cpp file to ensure that the class primeFactorization will work. You need to create a main program as well so you can test out the class primeFactorization. Put the main program in a file called assign02.cpp.
You need to upload three files (2 .cpp files and 1 .h file). You need to include the header comment as outlined below in each file. Not only do you need the header comment, you need commenting throughout your code so that it is clear the logic you are using to solve the problem. You will submit primeFactorization.h, primeFactorization.cpp, and assign02.cpp in Canvas when you have completed the assignment. Please pay attention to the due date for the assignment.
Program 1
#ifndef integerManipulation_H #define integerManipulation_H 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;
Program 2
//Implementation File for the class integerManipulation #include
void integerManipulation::setNum(long long n) { num = n; }
long long integerManipulation::getNum() { return num; }
void integerManipulation::reverseNum() { int rNum = 0; int number = num; bool isNegative = false; if (number < 0) { number = -number; isNegative = true; }
while (num > 0) { rNum = rNum * 10 + number % 10; number = number / 10; }
if (isNegative) rNum = -rNum; revNum = rNum; // final answer }
void integerManipulation::classifyDigits() { long long temp;
temp = abs(num);
int digit;
while (temp != 0) { digit = temp - (temp / 10 ) * 10; temp = temp / 10;
if (digit % 2 == 0) { evensCount++; if (digit == 0) zerosCount++; } else oddsCount++; }
Program 3
#ifndef primeFactorization_H #define primeFactorization_H
#include "integerManipulaiton.h" class primeFactorization: public integerManipulation { public:
void factorization(); //Function to output the prime factorization of num //Postcondition: Prime factorization of num is printed;
primeFactorization(long long n = 0); //Constructor with a default parameter. //The instance variables of the base class are set according //to the parameters and the array first125000Primes is //created. //Postcondition: num = n; revNum = 0; evenscount = 0; // oddsCount = 0; zerosCount = 0; // first125000Primes = first 125000 prime numbers.
private: long long first125000Primes[125000];
void primeFact(long long num, long long list[], int length, int firstPrimeFactIndex); void first125000PrimeNum(long long list[], int length); //Function to determine and store the first 125000 prime //integers. //Postcondition: The first 125000 prime numbers are // determined and stored in the array first125000Primes;
void primeTest(long long num, long long list[], int length, bool& primeNum, int& firstPrimeFactIndex); bool isPrime(long long number); };
#endi
program 4
#include
void primeFactorization::factorization() { //See Progamming Exercise 14. cout << "See Progamming Exercise 14." << endl; }
primeFactorization::primeFactorization(long long n) : integerManipulation(n) { first125000PrimeNum(first125000Primes, 125000); }
void primeFactorization::primeFact(long long num, long long list[], int length, int firstPrimeFactIndex) { //See Progamming Exercise 14. } void primeFactorization::first125000PrimeNum(long long list[], int length) { //See Progamming Exercise 14. }
void primeFactorization::primeTest(long long num, long long list[], int length, bool& primeNum, int& firstPrimeFactIndex) { //See Progamming Exercise 14. } bool primeFactorization::isPrime(long long number) { //See Progamming Exercise 14.
return false; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started