Question
Define a class named PrimeNumber that stores a prime number. The default con-structor should set the prime number to 1. Add another constructor that allows the caller to set the prime number. Also, add a function to get the prime number. Overload the prefix and postfix ++ and -- operators so they return a PrimeNumber object that is the next largest prime number ( for ++) and the next smallest prime number ( for --). For example, if the object's prime number is set to 13, then invoking ++ should return a PrimeNumber object whose prime number is set to 17. Overload the insertion operator (ie, operator<<) so that a PrimeNumber can be used with cout. Overlaod the extraction operator (i.e., operator>>) so that a PrimeNumber can be used with cin. Very Important: Create an appropriate test program for the class. This test program (main) should use demonstrate all the features in your class.
Explanation / Answer
/*Becoz of browser problem my code is not in right readable format....so you may also download the code from.......http://www.2shared.com/file/MJ-uJdD4/PRIMENUM.html*/ #include#include class PrimeNumber { int primeNum; public: PrimeNumber() { primeNum=1; } PrimeNumber(int value) { primeNum=value; } int getPrimeNum() { return primeNum; } void operator ++(); void operator --(); friend istream& operator>>(istream &input,PrimeNumber &p); friend ostream& operator(istream &input,PrimeNumber &p) { input>>p.primeNum; return input; } ostream& operator