SlideShare a Scribd company logo
C++ code only
(Retrieve of Malik D., 2015, p. 742) Programming Exercises 24., Chapter 10.
Consider the integer 6203851479017652638. Some of the operations that can be performed on
this integer are:
(5) Determine whether the number is prime.
(6) Find the prime factorization of the number.
Write the definitions of the member functions of the class integerManipulation .
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 evenCcount;
int oddsCount;
int zerosCount;
};
void integerManipulation::setNum(long long n) {
num = n;
}
long long integerManipulation::getNum() {
return num;
}
void integerManipulation::reverseNum() {
cout << "Programming Exercise" << endl;
}
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++;
}
}
integerManipulation::getEvensCount() {
return evensCount;
}
int integerManipulation::getOddsCount() {
return oddsCount;
}
int integerManipulation::getZerosCount() {
return zerosCount;
}
int integerManipulation::sumDigits() {
cout << "Programming Exercise " << endl;
return 0;
}
integerManipulation::integerManipulation(long long n) {
num = n;
revNum = 0;
evensCount = 0;
oddsCount = 0;
zerosCount = 0;
}
#include
#include "integerManipulation.h"
using namespace std;
int main(){
integerManipulation number;
long long num;
cout << "Enter an integer: ";
cin >> num;
cout << endl;
number.setNum(num);
number.classifyDigits();
cout << "The number of even digits: "
<< number.getEvensCount() << endl
<< "The number of zeros: "
<< number.getZerosCount() << endl
<< "The number of odd digits: "
<< number.getOddsCount() << endl;
return 0;
}//end main
Sample Run :
Enter an integer : 6203851479017652638
The number of even digits : 10
The number of zeros : 2
The number of odd digits : 9
Retrieve of Malik D., 2015, p. 816) Programming Exercises 14., Chapter 11.
Write the definitions of the functions of the class primeFactorization and write a program that
uses this class to output the prime factorization of an integer.
#ifndef primeFactorization_H
#define primeFactorization_H
#include "integerManipulation.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 first125000Primes[125000];
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.
//Add additional functions as needed.
};
#endif
primeFactorization::primeFactorization(long long n)
: integerManipulation(n) {
first125000PrimeNum(first125000Primes, 125000);
}
void primeFactorization::factorization() {
cout << "Programming Exercise " << endl;
}
#include
#include "primeFactorization.h"
using namespace std;
int main()
{
primeFactorization number;
long long num;
cout << "Enter an integer between 2 and "
<< "270,000,000,000,000: ";
cin >> num;
cout << endl;
number.setNum(num);
number.factorization();
return 0;
} //end main
Sample Run 1 :
Enter an integer between 2 and 270, 000, 000, 000, 000 : 3614457253
3614457253 is not a prime number.
Its factorization is : 3614457253 = 11 * 29 * 151 * 75037
Sample Run 2 :
Enter an integer between 2 and 270, 000, 000, 000, 000 : 2457829012772
2457829012772 is not a prime number.
Its factorization is : 2457829012772 = 2 * 2 * 7 * 37 * 41 * 67 * 863641
Sample Run 3 :
Enter an integer between 2 and 270, 000, 000, 000, 000 : 151383311
151383311 is a prime number.
Its factorization is : 151383311 = 151383311
Consider the integer 6203851479017652638. Some of the operations that can be performed on
this integer are: Count the number of even digits, odd digits, and zeros. Find the sum of the
digits. Reverse the digits; split the number into blocks of three-digit numbers; and find the sum
of these numbers. 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 n digits. If needed
add additional instance variables.)
(5) Determine whether the number is prime.
(6) Find the prime factorization of the number.
Write the definitions of the member functions of the class integerManipulation .
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 evenCcount;
int oddsCount;
int zerosCount;
};
void integerManipulation::setNum(long long n) {
num = n;
}
long long integerManipulation::getNum() {
return num;
}
void integerManipulation::reverseNum() {
cout << "Programming Exercise" << endl;
}
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++;
}
}
integerManipulation::getEvensCount() {
return evensCount;
}
int integerManipulation::getOddsCount() {
return oddsCount;
}
int integerManipulation::getZerosCount() {
return zerosCount;
}
int integerManipulation::sumDigits() {
cout << "Programming Exercise " << endl;
return 0;
}
integerManipulation::integerManipulation(long long n) {
num = n;
revNum = 0;
evensCount = 0;
oddsCount = 0;
zerosCount = 0;
}
#include
#include "integerManipulation.h"
using namespace std;
int main(){
integerManipulation number;
long long num;
cout << "Enter an integer: ";
cin >> num;
cout << endl;
number.setNum(num);
number.classifyDigits();
cout << "The number of even digits: "
<< number.getEvensCount() << endl
<< "The number of zeros: "
<< number.getZerosCount() << endl
<< "The number of odd digits: "
<< number.getOddsCount() << endl;
return 0;
}//end main
Sample Run :
Enter an integer : 6203851479017652638
The number of even digits : 10
The number of zeros : 2
The number of odd digits : 9
Retrieve of Malik D., 2015, p. 816) Programming Exercises 14., Chapter 11.
Write the definitions of the functions of the class primeFactorization and write a program that
uses this class to output the prime factorization of an integer.
#ifndef primeFactorization_H
#define primeFactorization_H
#include "integerManipulation.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 first125000Primes[125000];
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.
//Add additional functions as needed.
};
#endif
primeFactorization::primeFactorization(long long n)
: integerManipulation(n) {
first125000PrimeNum(first125000Primes, 125000);
}
void primeFactorization::factorization() {
cout << "Programming Exercise " << endl;
}
#include
#include "primeFactorization.h"
using namespace std;
int main()
{
primeFactorization number;
long long num;
cout << "Enter an integer between 2 and "
<< "270,000,000,000,000: ";
cin >> num;
cout << endl;
number.setNum(num);
number.factorization();
return 0;
} //end main
Sample Run 1 :
Enter an integer between 2 and 270, 000, 000, 000, 000 : 3614457253
3614457253 is not a prime number.
Its factorization is : 3614457253 = 11 * 29 * 151 * 75037
Sample Run 2 :
Enter an integer between 2 and 270, 000, 000, 000, 000 : 2457829012772
2457829012772 is not a prime number.
Its factorization is : 2457829012772 = 2 * 2 * 7 * 37 * 41 * 67 * 863641
Sample Run 3 :
Enter an integer between 2 and 270, 000, 000, 000, 000 : 151383311
151383311 is a prime number.
Its factorization is : 151383311 = 151383311
Add the member functions to integerManipulation Class.Implement the code of the member
function of primeFactorization Class.Implement an Options Menu in the driver program with the
following operations:Count the number of even digits, odd digits, and zeros.Find the sum of the
digits.Reverse the digits.Split the number into blocks of three-digit numbers and find the sum of
these numbers.Split the number into blocks of n-digit numbers from right to left and find the sum
of these n-digit numbers. (Note that the last block may not have n digits. If needed, add
additional instance variables.)Determine whether the number is prime.Find the prime
factorization of the number.Quit of program.
Implement your code's Constructors, Destructor, Copy Constructor, Mutators, and Accessor
functions.Overload operators in the classes.The solution must contain the following:Source
code.Separate class specifications from implementation.Program output.

More Related Content

Similar to C++ code only(Retrieve of Malik D., 2015, p. 742) Programming Exer.pdf

4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
ShifatiRabbi
 
C important questions
C important questionsC important questions
C important questions
JYOTI RANJAN PAL
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
arjurakibulhasanrrr7
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
Quratulain Naqvi
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
Sowri Rajan
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
Warui Maina
 
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
Please use the code below and make it operate as one program- Notating.pdf
Please use the code below and make it operate as one program- Notating.pdfPlease use the code below and make it operate as one program- Notating.pdf
Please use the code below and make it operate as one program- Notating.pdf
seoagam1
 
Functional C++
Functional C++Functional C++
Functional C++
Kevlin Henney
 
C programming
C programmingC programming
C programming
Samsil Arefin
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
Farhan Ab Rahman
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
Tushar B Kute
 
functions
functionsfunctions
functions
teach4uin
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
Ashutoshprasad27
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
Ashutoshprasad27
 
Lecture#5 Operators in C++
Lecture#5 Operators in C++Lecture#5 Operators in C++
Lecture#5 Operators in C++
NUST Stuff
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
Chandrakant Divate
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
mallik3000
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
harman kaur
 
C++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdfC++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdf
lakshmijewellery
 

Similar to C++ code only(Retrieve of Malik D., 2015, p. 742) Programming Exer.pdf (20)

4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
 
C important questions
C important questionsC important questions
C important questions
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
 
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
 
Please use the code below and make it operate as one program- Notating.pdf
Please use the code below and make it operate as one program- Notating.pdfPlease use the code below and make it operate as one program- Notating.pdf
Please use the code below and make it operate as one program- Notating.pdf
 
Functional C++
Functional C++Functional C++
Functional C++
 
C programming
C programmingC programming
C programming
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
functions
functionsfunctions
functions
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
Lecture#5 Operators in C++
Lecture#5 Operators in C++Lecture#5 Operators in C++
Lecture#5 Operators in C++
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
 
C++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdfC++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdf
 

More from andreaplotner1

Also Share your Excel How it look likeCreate an excel file consist.pdf
Also Share your Excel How it look likeCreate an excel file consist.pdfAlso Share your Excel How it look likeCreate an excel file consist.pdf
Also Share your Excel How it look likeCreate an excel file consist.pdf
andreaplotner1
 
C++ Error upon run �Description Resource Path Location Type expected.pdf
C++ Error upon run �Description Resource Path Location Type expected.pdfC++ Error upon run �Description Resource Path Location Type expected.pdf
C++ Error upon run �Description Resource Path Location Type expected.pdf
andreaplotner1
 
Alex Jones is the majority owner and CEO of Harbour City Investments.pdf
Alex Jones is the majority owner and CEO of Harbour City Investments.pdfAlex Jones is the majority owner and CEO of Harbour City Investments.pdf
Alex Jones is the majority owner and CEO of Harbour City Investments.pdf
andreaplotner1
 
C++ Improper Function Definitions in Header FilesExplanation Ensu.pdf
C++ Improper Function Definitions in Header FilesExplanation Ensu.pdfC++ Improper Function Definitions in Header FilesExplanation Ensu.pdf
C++ Improper Function Definitions in Header FilesExplanation Ensu.pdf
andreaplotner1
 
Book Review Symposium on �Shareholder Value Myth�by Lynn StoutTh.pdf
Book Review Symposium on �Shareholder Value Myth�by Lynn StoutTh.pdfBook Review Symposium on �Shareholder Value Myth�by Lynn StoutTh.pdf
Book Review Symposium on �Shareholder Value Myth�by Lynn StoutTh.pdf
andreaplotner1
 
Background Maersk, headquartered in Denmark, is the world�s largest.pdf
Background Maersk, headquartered in Denmark, is the world�s largest.pdfBackground Maersk, headquartered in Denmark, is the world�s largest.pdf
Background Maersk, headquartered in Denmark, is the world�s largest.pdf
andreaplotner1
 
a3.html code!DOCTYPE HTMLhtml lang=enhead meta c.pdf
a3.html code!DOCTYPE HTMLhtml lang=enhead    meta c.pdfa3.html code!DOCTYPE HTMLhtml lang=enhead    meta c.pdf
a3.html code!DOCTYPE HTMLhtml lang=enhead meta c.pdf
andreaplotner1
 
Application of Computational Vision in theMedicine Diagnosis of.pdf
Application of Computational Vision in theMedicine Diagnosis of.pdfApplication of Computational Vision in theMedicine Diagnosis of.pdf
Application of Computational Vision in theMedicine Diagnosis of.pdf
andreaplotner1
 
asap and all of those Draw an ER diagram for keeping track of inf.pdf
asap and all of those  Draw an ER diagram for keeping track of inf.pdfasap and all of those  Draw an ER diagram for keeping track of inf.pdf
asap and all of those Draw an ER diagram for keeping track of inf.pdf
andreaplotner1
 
AssignmentActivity 1 Identifying Privacy ConcernsObjective T.pdf
AssignmentActivity 1 Identifying Privacy ConcernsObjective T.pdfAssignmentActivity 1 Identifying Privacy ConcernsObjective T.pdf
AssignmentActivity 1 Identifying Privacy ConcernsObjective T.pdf
andreaplotner1
 
Assessment 2 - Case Study Report � Groups of 3Susan Day is employe.pdf
Assessment 2 - Case Study Report � Groups of 3Susan Day is employe.pdfAssessment 2 - Case Study Report � Groups of 3Susan Day is employe.pdf
Assessment 2 - Case Study Report � Groups of 3Susan Day is employe.pdf
andreaplotner1
 

More from andreaplotner1 (11)

Also Share your Excel How it look likeCreate an excel file consist.pdf
Also Share your Excel How it look likeCreate an excel file consist.pdfAlso Share your Excel How it look likeCreate an excel file consist.pdf
Also Share your Excel How it look likeCreate an excel file consist.pdf
 
C++ Error upon run �Description Resource Path Location Type expected.pdf
C++ Error upon run �Description Resource Path Location Type expected.pdfC++ Error upon run �Description Resource Path Location Type expected.pdf
C++ Error upon run �Description Resource Path Location Type expected.pdf
 
Alex Jones is the majority owner and CEO of Harbour City Investments.pdf
Alex Jones is the majority owner and CEO of Harbour City Investments.pdfAlex Jones is the majority owner and CEO of Harbour City Investments.pdf
Alex Jones is the majority owner and CEO of Harbour City Investments.pdf
 
C++ Improper Function Definitions in Header FilesExplanation Ensu.pdf
C++ Improper Function Definitions in Header FilesExplanation Ensu.pdfC++ Improper Function Definitions in Header FilesExplanation Ensu.pdf
C++ Improper Function Definitions in Header FilesExplanation Ensu.pdf
 
Book Review Symposium on �Shareholder Value Myth�by Lynn StoutTh.pdf
Book Review Symposium on �Shareholder Value Myth�by Lynn StoutTh.pdfBook Review Symposium on �Shareholder Value Myth�by Lynn StoutTh.pdf
Book Review Symposium on �Shareholder Value Myth�by Lynn StoutTh.pdf
 
Background Maersk, headquartered in Denmark, is the world�s largest.pdf
Background Maersk, headquartered in Denmark, is the world�s largest.pdfBackground Maersk, headquartered in Denmark, is the world�s largest.pdf
Background Maersk, headquartered in Denmark, is the world�s largest.pdf
 
a3.html code!DOCTYPE HTMLhtml lang=enhead meta c.pdf
a3.html code!DOCTYPE HTMLhtml lang=enhead    meta c.pdfa3.html code!DOCTYPE HTMLhtml lang=enhead    meta c.pdf
a3.html code!DOCTYPE HTMLhtml lang=enhead meta c.pdf
 
Application of Computational Vision in theMedicine Diagnosis of.pdf
Application of Computational Vision in theMedicine Diagnosis of.pdfApplication of Computational Vision in theMedicine Diagnosis of.pdf
Application of Computational Vision in theMedicine Diagnosis of.pdf
 
asap and all of those Draw an ER diagram for keeping track of inf.pdf
asap and all of those  Draw an ER diagram for keeping track of inf.pdfasap and all of those  Draw an ER diagram for keeping track of inf.pdf
asap and all of those Draw an ER diagram for keeping track of inf.pdf
 
AssignmentActivity 1 Identifying Privacy ConcernsObjective T.pdf
AssignmentActivity 1 Identifying Privacy ConcernsObjective T.pdfAssignmentActivity 1 Identifying Privacy ConcernsObjective T.pdf
AssignmentActivity 1 Identifying Privacy ConcernsObjective T.pdf
 
Assessment 2 - Case Study Report � Groups of 3Susan Day is employe.pdf
Assessment 2 - Case Study Report � Groups of 3Susan Day is employe.pdfAssessment 2 - Case Study Report � Groups of 3Susan Day is employe.pdf
Assessment 2 - Case Study Report � Groups of 3Susan Day is employe.pdf
 

Recently uploaded

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 

C++ code only(Retrieve of Malik D., 2015, p. 742) Programming Exer.pdf

  • 1. C++ code only (Retrieve of Malik D., 2015, p. 742) Programming Exercises 24., Chapter 10. Consider the integer 6203851479017652638. Some of the operations that can be performed on this integer are: (5) Determine whether the number is prime. (6) Find the prime factorization of the number. Write the definitions of the member functions of the class integerManipulation . 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.
  • 2. //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 evenCcount; int oddsCount; int zerosCount; }; void integerManipulation::setNum(long long n) { num = n; } long long integerManipulation::getNum() { return num; } void integerManipulation::reverseNum() { cout << "Programming Exercise" << endl; }
  • 3. 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++; } } integerManipulation::getEvensCount() { return evensCount; } int integerManipulation::getOddsCount() { return oddsCount; } int integerManipulation::getZerosCount() { return zerosCount; } int integerManipulation::sumDigits() { cout << "Programming Exercise " << endl; return 0; } integerManipulation::integerManipulation(long long n) {
  • 4. num = n; revNum = 0; evensCount = 0; oddsCount = 0; zerosCount = 0; } #include #include "integerManipulation.h" using namespace std; int main(){ integerManipulation number; long long num; cout << "Enter an integer: "; cin >> num; cout << endl; number.setNum(num); number.classifyDigits(); cout << "The number of even digits: " << number.getEvensCount() << endl << "The number of zeros: " << number.getZerosCount() << endl << "The number of odd digits: " << number.getOddsCount() << endl; return 0; }//end main Sample Run : Enter an integer : 6203851479017652638 The number of even digits : 10 The number of zeros : 2 The number of odd digits : 9 Retrieve of Malik D., 2015, p. 816) Programming Exercises 14., Chapter 11. Write the definitions of the functions of the class primeFactorization and write a program that uses this class to output the prime factorization of an integer.
  • 5. #ifndef primeFactorization_H #define primeFactorization_H #include "integerManipulation.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 first125000Primes[125000]; 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. //Add additional functions as needed. }; #endif primeFactorization::primeFactorization(long long n) : integerManipulation(n) { first125000PrimeNum(first125000Primes, 125000); }
  • 6. void primeFactorization::factorization() { cout << "Programming Exercise " << endl; } #include #include "primeFactorization.h" using namespace std; int main() { primeFactorization number; long long num; cout << "Enter an integer between 2 and " << "270,000,000,000,000: "; cin >> num; cout << endl; number.setNum(num); number.factorization(); return 0; } //end main Sample Run 1 : Enter an integer between 2 and 270, 000, 000, 000, 000 : 3614457253 3614457253 is not a prime number. Its factorization is : 3614457253 = 11 * 29 * 151 * 75037 Sample Run 2 : Enter an integer between 2 and 270, 000, 000, 000, 000 : 2457829012772 2457829012772 is not a prime number. Its factorization is : 2457829012772 = 2 * 2 * 7 * 37 * 41 * 67 * 863641 Sample Run 3 : Enter an integer between 2 and 270, 000, 000, 000, 000 : 151383311 151383311 is a prime number. Its factorization is : 151383311 = 151383311
  • 7. Consider the integer 6203851479017652638. Some of the operations that can be performed on this integer are: Count the number of even digits, odd digits, and zeros. Find the sum of the digits. Reverse the digits; split the number into blocks of three-digit numbers; and find the sum of these numbers. 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 n digits. If needed add additional instance variables.) (5) Determine whether the number is prime. (6) Find the prime factorization of the number. Write the definitions of the member functions of the class integerManipulation . 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.
  • 8. 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 evenCcount; int oddsCount; int zerosCount; }; void integerManipulation::setNum(long long n) { num = n; } long long integerManipulation::getNum() { return num; } void integerManipulation::reverseNum() {
  • 9. cout << "Programming Exercise" << endl; } 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++; } } integerManipulation::getEvensCount() { return evensCount; } int integerManipulation::getOddsCount() { return oddsCount; } int integerManipulation::getZerosCount() { return zerosCount; } int integerManipulation::sumDigits() { cout << "Programming Exercise " << endl; return 0; }
  • 10. integerManipulation::integerManipulation(long long n) { num = n; revNum = 0; evensCount = 0; oddsCount = 0; zerosCount = 0; } #include #include "integerManipulation.h" using namespace std; int main(){ integerManipulation number; long long num; cout << "Enter an integer: "; cin >> num; cout << endl; number.setNum(num); number.classifyDigits(); cout << "The number of even digits: " << number.getEvensCount() << endl << "The number of zeros: " << number.getZerosCount() << endl << "The number of odd digits: " << number.getOddsCount() << endl; return 0; }//end main Sample Run : Enter an integer : 6203851479017652638 The number of even digits : 10 The number of zeros : 2 The number of odd digits : 9 Retrieve of Malik D., 2015, p. 816) Programming Exercises 14., Chapter 11.
  • 11. Write the definitions of the functions of the class primeFactorization and write a program that uses this class to output the prime factorization of an integer. #ifndef primeFactorization_H #define primeFactorization_H #include "integerManipulation.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 first125000Primes[125000]; 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. //Add additional functions as needed. }; #endif primeFactorization::primeFactorization(long long n) : integerManipulation(n) { first125000PrimeNum(first125000Primes, 125000);
  • 12. } void primeFactorization::factorization() { cout << "Programming Exercise " << endl; } #include #include "primeFactorization.h" using namespace std; int main() { primeFactorization number; long long num; cout << "Enter an integer between 2 and " << "270,000,000,000,000: "; cin >> num; cout << endl; number.setNum(num); number.factorization(); return 0; } //end main Sample Run 1 : Enter an integer between 2 and 270, 000, 000, 000, 000 : 3614457253 3614457253 is not a prime number. Its factorization is : 3614457253 = 11 * 29 * 151 * 75037 Sample Run 2 : Enter an integer between 2 and 270, 000, 000, 000, 000 : 2457829012772 2457829012772 is not a prime number. Its factorization is : 2457829012772 = 2 * 2 * 7 * 37 * 41 * 67 * 863641 Sample Run 3 : Enter an integer between 2 and 270, 000, 000, 000, 000 : 151383311 151383311 is a prime number. Its factorization is : 151383311 = 151383311
  • 13. Add the member functions to integerManipulation Class.Implement the code of the member function of primeFactorization Class.Implement an Options Menu in the driver program with the following operations:Count the number of even digits, odd digits, and zeros.Find the sum of the digits.Reverse the digits.Split the number into blocks of three-digit numbers and find the sum of these numbers.Split the number into blocks of n-digit numbers from right to left and find the sum of these n-digit numbers. (Note that the last block may not have n digits. If needed, add additional instance variables.)Determine whether the number is prime.Find the prime factorization of the number.Quit of program. Implement your code's Constructors, Destructor, Copy Constructor, Mutators, and Accessor functions.Overload operators in the classes.The solution must contain the following:Source code.Separate class specifications from implementation.Program output.