Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 created. You 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.

Files you need: integerManipulation.h integerManipulationImp.cpp primeFactorization.h primeFactorizationImp.cpp You need to upload three files (2 .cpp files and 1 .h 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.

PROGRAM 1: integerManipulation.h

#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;

int evensCount;

int oddsCount;

int zerosCount;

};

#endif

PROGRAM 2: integerManipulationImp.cpp

//Implementation File for the class integerManipulation

#include

#include

#include "integerManipulation.h"

using namespace std;

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++;

}

}

int integerManipulation::getEvensCount()

{

return evensCount;

}

int integerManipulation::getOddsCount()

{

return oddsCount;

}

int integerManipulation::getZerosCount()

{

return zerosCount;

}

int integerManipulation::sumDigits()

{

//int num;

int tempNum = num;

int digit;

int sum = 0;

int pwr = 0;

if (tempNum < 0)

tempNum = -tempNum;

//Find the highest power of 10 that divides the number

while (tempNum / static_cast(pow(10.0, pwr)) > 10)

pwr++;

while (tempNum > 0)

{

digit = tempNum / static_cast(pow(10.0, pwr));

cout << digit << " ";

sum = sum + digit;

tempNum = tempNum % static_cast(pow(10.0, pwr));

pwr--;

}

return sum;

}

integerManipulation::integerManipulation(long long n)

{

num = n;

revNum = 0;

evensCount = 0;

oddsCount = 0;

zerosCount = 0;

}

PROGRAM 3: primeFactorization.h

#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);

};

#endif

PROGRAM 4: primeFactorizationImp.cpp

#include

#include "integerManipulation.h"

#include "primeFactorization.h"

using namespace std;

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;

}

I currently have this as my main source.cpp. It seems that there is a problem with integerManipulation in this file not being recognized as a class. I've added comments to the right of these errors along with what Visual Studio is telling me the problem is for each one. If you feel the need to scrap my current source.cpp that's fine, although i'd prefer to keep the work that's been done. Whatever help I can get is appreciated.

*Source.cpp*

#include "primeFactorization.h" #include

using namespace std;

primeFactorization::primeFactorization(long long n) : integerManipulation(n) // "integerManipulation" is not a nonstatic data member or base class of class "primeFactorization" { first125000PrimeNum(first125000Primes, 125000); }

void primeFactorization::factorization() { long long original = integerManipulation::getNum(); // name followed by '::' must be a class or namespace name first125000PrimeNum(first125000Primes, 125000);

if (first125000Primes[0] == original) cout << original << "is a prime number"; else cout << original << "is not a prime number";

cout << original << "Its factorization is:" << endl; cout << original << " = ";

for (int i = 0; i < 125000; i++) { if (first125000Primes[i] != -1) { cout << first125000Primes[i];

if (i != 125000 - 1 && first125000Primes[i + 1] != -1) cout << "*"; } else break; } cout << endl; }

void primeFactorization::first125000PrimeNum(long long list[], int length) { for (int i = 0; i < length; i++) list[i] = -1;

long long number = integerManipulation::getNum(); // name followed by '::' must be a class or namespace name

int index = 0; for (long long i = 2; i <= number; i++) { while (number % i == 0) { list[index] = i; index++; number = number / i; } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago