Menu

Friday, 15 May 2015

Chapter 9, Problem 7: OOP By Robert Lafore

Problem Statement:

Start with the COUNTEN2 program in this chapter. It can increment or decrement a
counter, but only using prefix notation. Using inheritance, add the ability to use postfix
notation for both incrementing and decrementing. (See Chapter 8 for a description of
postfix notation.)

Solution:

//Ahmad Furqan
//P9.7
#include <iostream>
#include <conio.h>
using namespace std;
////////////////////////////////////////////////////////////////
class Counter
{
protected: //NOTE: not private
unsigned int count; //count
public:
Counter() : count() //constructor, no args
{ }
Counter(int c) : count(c) //constructor, one arg
{ }
unsigned int get_count() const //return count
{
return count;
}
Counter operator ++ () //incr count (prefix)
{
return Counter(++count);
}
};
////////////////////////////////////////////////////////////////
class CountDn : public Counter
{
public:
CountDn() : Counter() //constructor, no args
{ }
CountDn(int c) : Counter(c) //constructor, 1 arg
{ }
CountDn operator -- () //decr count (prefix)
{
return CountDn(--count);
}
};
////////////////////////////////////////////////////////////////
class Countupdown :public CountDn
{
public:
Countupdown() :CountDn()
{}
Countupdown(int c) :CountDn(c)
{}
Countupdown operator ++(int)
{
return Countupdown(count++);
}
Countupdown operator --(int)
{
return Countupdown(count--);
}
};
////////////////////////////////////////////////////////////////
void main(void)
{
CountDn c1; //class CountDn
CountDn c2(100);
cout << "\nc1 = " << c1.get_count(); //display
cout << "\nc2 = " << c2.get_count(); //display
++c1; ++c1; c1++; //increment c1
cout << "\nc1 = " << c1.get_count(); //display it
--c2; c2--; //decrement c2
cout << "\nc2 = " << c2.get_count(); //display it
CountDn c3 = c2--; //create c3 from c2
cout << "\nc3 = " << c3.get_count(); //display c3
cout << endl;
_getch();
}

Chapter 9, Problem 6: OOP By Robert Lafore

Problem Statement:

Start with the ARROVER3 program in Chapter 8. Keep the safearay class the same as in
that program, and, using inheritance, derive the capability for the user to specify both the
upper and lower bounds of the array in a constructor. This is similar to Exercise 9 in
Chapter 8, except that inheritance is used to derive a new class (you can call it safehilo)
instead of modifying the original class.

Solution:

//Ahmad Furqan
//P9.6
#include <iostream>
#include <conio.h>
using namespace std;
#include <process.h> //for exit()
const int LIMIT = 100; //array size
////////////////////////////////////////////////////////////////
class safearay
{
private:
int arr[LIMIT];
public:
int& operator [](int n) //note: return by reference
{
if (n< 0 || n >= LIMIT)
{
cout << "\nIndex out of bounds"; exit(1);
}
return arr[n];
}
};
////////////////////////////////////////////////////////////////
class safehilo :public safearay
{
private:
int llimit, ulimit;
public:
safehilo(int a, int b) :llimit(a), ulimit(b)
{
if ((b - a) > LIMIT)
{
cout << "Array limits exceed maximum permissible range."; exit(1);
}
}
int& operator [](int n)
{
if (n < llimit || n >= ulimit)
{
cout << "\nIndex out of bounds"; _getch(); exit(1);
}
safearay::operator[](n - llimit);
}
};
////////////////////////////////////////////////////////////////
void main(void)
{
safehilo sa1(100,175);
for (int j = 100; j<175; j++) //insert elements
sa1[j] = j * 10; //*left* side of equal sign
for (int j = 100; j<175; j++) //display elements
{
int temp = sa1[j]; //*right* side of equal sign
cout << "Element " << j << " is " << temp << endl;
}
_getch();
}

Chapter 9, Problem 5: OOP by Robert Lafore

Problem Statement:

Derive a class called employee2 from the employee class in the EMPLOY program in this
chapter. This new class should add a type double data item called compensation, and
also an enum type called period to indicate whether the employee is paid hourly, weekly,
or monthly. For simplicity you can change the manager, scientist, and laborer classes
so they are derived from employee2 instead of employee. However, note that in many
circumstances it might be more in the spirit of OOP to create a separate base class called
compensation and three new classes manager2, scientist2, and laborer2, and use
multiple inheritance to derive these three classes from the original manager, scientist,
and laborer classes and from compensation. This way none of the original classes
needs to be modified.

Solution:

//Ahmad Furqan
//P9.5
#include <iostream>
#include <conio.h>
using namespace std;
const int LEN = 80; //maximum length of names
////////////////////////////////////////////////////////////////
class employee //employee class
{
private:
char name[LEN]; //employee name
unsigned long number; //employee number
public:
void getdata()
{
cout << "\n Enter last name : "; cin >> name;
cout << " Enter number :"; cin >> number;
}
void putdata() const
{
cout << "\n Name : " << name;
cout << "\n Number : " << number;
}
};
////////////////////////////////////////////////////////////////
class employee2 :public employee
{
private:
double compen;
enum paytype{ hourly, weakly, monthly };
paytype period;
public:
void getdata(void)
{
char a;
employee::getdata();
cout << "Enter compensation: ";
cin >> compen;
cout << "Enter payment period (h,w,m): ";
cin >> a;
switch (a)
{
case 'h':
period = hourly;
break;
case 'w':
period = weakly;
break;
case 'm':
period = monthly;
break;
}
}
void putdata(void) const
{
employee::putdata();
cout << "Employee compensation: " << compen << endl;
switch (period)
{
case hourly:
cout << "hourly" << endl;
break;
case weakly:
cout << "weakly" << endl;
break;
case monthly:
cout << "monthly" << endl;
break;
}
}
};
////////////////////////////////////////////////////////////////
class manager : public employee2 //management class
{
private:
char title[LEN]; //"vice-president" etc.
double dues; //golf club dues
public:
void getdata()
{
employee2::getdata();
cout << " Enter title : "; cin >> title;
cout << " Enter golf club dues : "; cin >> dues;
}
void putdata() const
{
employee2::putdata();
cout << "\n Title : " << title;
cout << "\n Golf club dues : " << dues;
}
};
////////////////////////////////////////////////////////////////
class scientist : public employee2 //scientist class
{
private:
int pubs; //number of publications
public:
void getdata()
{
employee2::getdata();
cout << " Enter number of pubs : "; cin >> pubs;
}
void putdata() const
{
employee2::putdata();
cout << "\n Number of publications : " << pubs;
}
};
////////////////////////////////////////////////////////////////
class laborer : public employee2 //laborer class
{};
////////////////////////////////////////////////////////////////
void main(void)
{
manager m1, m2;
scientist s1;
laborer l1;
cout << endl; //get data for several employees
cout << "\nEnter data for manager 1";
m1.getdata();
cout << "\nEnter data for manager 2";
m2.getdata();
cout << "\nEnter data for scientist 1";
s1.getdata();
cout << "\nEnter data for laborer 1";
l1.getdata();
//display data for several employees
cout << "\nData on manager 1";
m1.putdata();
cout << "\nData on manager 2";
m2.putdata();
cout << "\nData on scientist 1";
s1.putdata();
cout << "\nData on laborer 1";
l1.putdata();
cout << endl;
_getch();
}

Chapter 9, Problem 4: OOP by Robert Lafore

Problem Statement:

Assume that the publisher in Exercises 1 and 3 decides to add a third way to distribute
books: on computer disk, for those who like to do their reading on their laptop. Add a
disk class that, like book and tape, is derived from publication. The disk class should
incorporate the same member functions as the other classes. The data item unique to this
class is the disk type: either CD or DVD. You can use an enum type to store this item.
The user could select the appropriate type by typing c or d.

Solution:

//Ahmad Furqan
//P9.4
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
class publication
{
private:
string title;
float price;
public:
void getdata(void)
{
string t;
float p;
cout << "Enter title of publication: ";
cin >> t;
cout << "Enter price of publication: ";
cin >> p;
title = t;
price = p;
}
void putdata(void)
{
cout << "Publication title: " << title << endl;
cout << "Publication price: " << price << endl;
}
};
class sales
{
private:
float s1, s2, s3;
public:
void getdata(void)
{
cout << "Enter month 1 sale: $";
cin >> s1;
cout << "Enter month 2 sale: $";
cin >> s2;
cout << "Enter month 3 sale: $";
cin >> s3;
}
void putdata(void)
{
cout << "Month 1 sale: $" << s1 << endl;
cout << "Month 2 sale: $" << s2 << endl;
cout << "Month 3 sale: $" << s3 << endl;
}
};
class book :public publication, public sales
{
private:
int pagecount;
public:
void getdata(void)
{
publication::getdata();
sales::getdata();
cout << "Enter Book Page Count: ";
cin >> pagecount;
}
void putdata(void)
{
publication::putdata();
sales::putdata();
cout << "Book page count: " << pagecount << endl;
}
};
class tape :public publication, public sales
{
private:
float ptime;
public:
void getdata(void)
{
publication::getdata();
sales::getdata();
cout << "Enter tap's playing time: ";
cin >> ptime;
}
void putdata(void)
{
publication::putdata();
sales::putdata();
cout << "Tap's playing time: " << ptime << endl;
}
};
class disk :public publication
{
private:
enum dtype
{CD,DVD};
dtype userchoice;
public:
void getdata(void)
{
char a;
publication::getdata();
cout << "Enter disk type (c or d) for CD and DVD: ";
cin >> a;
if (a == 'c')
userchoice = CD;
else
userchoice = DVD;

}
void putdata()
{
publication::putdata();
cout  << "Disk type is: ";
if (userchoice == CD)
cout << "CD";
else
cout << "DVD";
}
};
void main(void)
{
disk d;
d.getdata();
d.putdata();
_getch();
}

Thursday, 14 May 2015

Chapter 9, Problem 3: OOP by Robert Lafore

Problem Statement:

Start with the publication, book, and tape classes of Exercise 1. Add a base class sales
that holds an array of three floats so that it can record the dollar sales of a particular
publication for the last three months. Include a getdata() function to get three sales
amounts from the user, and a putdata() function to display the sales figures. Alter the
book and tape classes so they are derived from both publication and sales. An object
of class book or tape should input and output sales data along with its other data. Write
a main() function to create a book object and a tape object and exercise their input/output
capabilities.

Solution:


//Ahmad Furqan
//P9.3
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
class publication
{
private:
string title;
float price;
public:
void getdata(void)
{
string t;
float p;
cout << "Enter title of publication: ";
cin >> t;
cout << "Enter price of publication: ";
cin >> p;
title = t;
price = p;
}
void putdata(void)
{
cout << "Publication title: " << title << endl;
cout << "Publication price: " << price << endl;
}
};
class sales
{
private:
float s1, s2, s3;
public:
void getdata(void)
{
cout << "Enter month 1 sale: $";
cin >> s1;
cout << "Enter month 2 sale: $";
cin >> s2;
cout << "Enter month 3 sale: $";
cin >> s3;
}
void putdata(void)
{
cout << "Month 1 sale: $" << s1 << endl;
cout << "Month 2 sale: $" << s2 << endl;
cout << "Month 3 sale: $" << s3 << endl;
}
};
class book :public publication,public sales
{
private:
int pagecount;
public:
void getdata(void)
{
publication::getdata();
sales::getdata();
cout << "Enter Book Page Count: ";
cin >> pagecount;
}
void putdata(void)
{
publication::putdata();
sales::putdata();
cout << "Book page count: " << pagecount << endl;
}
};
class tape :public publication,public sales
{
private:
float ptime;
public:
void getdata(void)
{
publication::getdata();
sales::getdata();
cout << "Enter tap's playing time: ";
cin >> ptime;
}
void putdata(void)
{
publication::putdata();
sales::putdata();
cout << "Tap's playing time: " << ptime << endl;
}
};
void main(void)
{
book b;
tape t;
b.getdata();
t.getdata();
b.putdata();
t.putdata();
_getch();
}

Chapter 9, Problem 2: OOP by Robert Lafore

Problem Statement:

Recall the STRCONV example from Chapter 8. The String class in this example has a
flaw: It does not protect itself if its objects are initialized to have too many characters.
(The SZ constant has the value 80.) For example, the definition
String s = “This string will surely exceed the width of the “
“screen, which is what the SZ constant represents.”;
will cause the str array in s to overflow, with unpredictable consequences, such as
crashing the system.
With String as a base class, derive a class Pstring (for “protected string”) that prevents
buffer overflow when too long a string constant is used in a definition. A new constructor
in the derived class should copy only SZ–1 characters into str if the string constant is
longer, but copy the entire constant if it’s shorter. Write a main() program to test different
lengths of strings.

Solution:

//Ahmad Furqan
//P9.2
#include <iostream>
#include <conio.h>
using namespace std;
class String
{
protected:
enum { SZ = 80 }; //max size of Strings
char str[SZ]; //array
public:
String() //constructor, no args
{
str[0] = '\0';
}
String(char s[]) //constructor, one arg
{
strcpy_s(str, s);
}
void display() //display string
{
cout << str;
}
void concat(String s2) //add arg string to
{ //this string
if (strlen(str) + strlen(s2.str) < SZ)
strcat_s(str, s2.str);
else
cout << "\nString too long";
}
};
class Pstring :public String
{
public:
Pstring()
{}
Pstring(char s[])
{
int len = strlen(s);
if (len < SZ)
strcpy_s(str, s);
else
{
for (int i = 0; i < (SZ); i++)
{
str[i] = s[i];
}
}
}
};
void main(void)
{
Pstring s, s1;
s = "Awais Irfan";
s1 = "This string will surely exceed the width of the screen, which is what the SZ constant represents.";
s.display();
cout << endl;
s1.display();
cout << endl;
_getch();
}

Chapter 9,Problem 1:OOP by Robert Lafore


Problem Statement:


Imagine a publishing company that markets both book and audiocassette versions of its
works. Create a class publication that stores the title (a string) and price (type float)
of a publication. From this class derive two classes: book, which adds a page count (type
int), and tape, which adds a playing time in minutes (type float). Each of these three
classes should have a getdata() function to get its data from the user at the keyboard,
and a putdata() function to display its data.
Write a main() program to test the book and tape classes by creating instances of them,
asking the user to fill in data with getdata(), and then displaying the data with putdata().

Solution:

//Ahmad Furqan
//P9.1
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
class publication
{
private:
string title;
float price;
public:
void getdata(void)
{
string t;
float p;
cout << "Enter title of publication: ";
cin >> t;
cout << "Enter price of publication: ";
cin >> p;
title = t;
price = p;
}
void putdata(void)
{
cout << "Publication title: " << title << endl;
cout << "Publication price: " << price<<endl;
}
};
class book :public publication
{
private:
int pagecount;
public:
void getdata(void)
{
publication::getdata(); //call publication class function to get data
cout << "Enter Book Page Count: "; //Acquire book data from user
cin >> pagecount;
}
void putdata(void)
{
publication::putdata();  //Show Publication data
cout << "Book page count: " << pagecount << endl; //Show book data
}
};
class tape :public publication
{
private:
float ptime;
public:
void getdata(void)
{
publication::getdata();
cout << "Enter tap's playing time: ";
cin >> ptime;
}
void putdata(void)
{
publication::putdata();
cout << "Tap's playing time: " << ptime << endl;
}
};
void main(void)
{
book b;
tape t;
b.getdata();
t.getdata();
b.putdata();
t.putdata();
_getch();
}

Wednesday, 13 May 2015

Chapter 5,Problem k: Let Us C

Problem Statement:

Write a function to compute the greatest common divisor
given by Euclid’s algorithm, exemplified for J = 1980, K =
1617 as follows:
1980 / 1617 = 1 1980 – 1 * 1617 = 363
1617 / 363 = 4 1617 – 4 * 363 = 165
363 / 165 = 2 363 – 2 * 165 = 33
5 / 33 = 5 165 – 5 * 33 = 0
Thus, the greatest common divisor is 33.

Solution:

//Ahmad Furqan
//P5.k
#include <iostream>
#include <conio.h>
using namespace std;
int gcd_euclid(int j, int k)
{
int a, b;
while (k > 0)
{
a = j / k;
b = k;
k = j - a*k;
j = b;
}
return j;
}
void main(void)
{
int j, k;
cout << "Enter a number: ";
cin >> j;
cout << "Enter second number: ";
cin >> k;
cout << "Greatest common divisor of " << j << " and " << k << " is: " << gcd_euclid(j, k);
_getch();
}

Chapter 5,Problem j: Let Us C

Problem Statement:

Write a function to compute the distance between two points
and use it to develop another function that will compute the
area of the triangle whose vertices are A(x1, y1), B(x2, y2),
and C(x3, y3).

Solution:

//Ahmad Furqan
//P5.j
#include <iostream>
#include <conio.h>
using namespace std;
float pdist(int x1, int y1, int x2, int y2)
{
float dist;
dist = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
return dist;
}
float triarea(float a, float b, float c)
{
float s;
float area;
s = (a + b + c) / 2;
area = sqrt(s*(s - a)*(s - b)*(s - c));
return area;
}
void main(void)
{
int x1, x2, x3, y1, y2, y3;
float a, b, c;
cout << "Enter point 1: ";
cout << "Enter x: ";
cin >> x1;
cout << "Enter y:";
cin >> y1;
cout << "Enter point 2:";
cout << "Enter x:";
cin >> x2;
cout << "Enter y";
cin >> y2;
cout << "Enter point 3:";
cout << "Enter x:";
cin >> x3;
cout << "Enter y:";
cin >> y3;
a = pdist(x1, y1, x2, y2);
b = pdist(x2, y2, x3, y3);
c = pdist(x1, y1, x3, y3);
cout << "Area of triangle bounded by these points is: " << triarea(a, b, c);
_getch();
}

Chapter 5,Problem i: Let Us C

Problem Statement:

If the lengths of the sides of a triangle are denoted by a, b,
and c, then area of triangle is given by
area = S(S a)(S b)(S c)
where, S = ( a + b + c ) / 2

Solution:

//Ahmad Furqan
//P5.i
#include <iostream>
#include <conio.h>
using namespace std;
float triarea(int a, int b, int c)
{
int s;
float area;
s = (a + b + c) / 2;
area = sqrt(s*(s - a)*(s - b)*(s - c));
return area;
}
void main(void)
{
int a, b, c;
cout << "Enter triangle side lengths:" << endl;
cout << "a: ";
cin >> a;
cout << "b: ";
cin >> b;
cout << "c: ";
cin >> c;
cout << "Area of the triangle is: " << triarea(a, b, c);
_getch();

}

Chapter 5,Problem h: Let Us C

Problem Statement:

Write a function to find the binary equivalent of a given
decimal integer and display it.

Solution:

//Ahmad Furqan
//P5.h
#include <iostream>
#include <conio.h>
using namespace std;
void num2bin(int num)
{
bool bin[25];
int i = 0;
for (i = 0; i < 25; i++)
{
bin[i] = num % 2; //divide number by 2 successively and save remainders
if (num < 2)
break;
num /= 2;
}
for (i; i >= 0; i--)
{
cout << bin[i];  //show remainders in reverse order
}
}
void main(void)
{
int num;
cout << "Enter a number: ";
cin >> num;
cout << "The binary equivalent of this number is: ";
num2bin(num);
_getch();
}

Chapter 5, Problem g: Let Us C

Problem Statement:

Given three variables x, y, z write a function to circularly shift
their values to right. In other words if x = 5, y = 8, z = 10 after
circular shift y = 5, z = 8, x =10 after circular shift y = 5, z = 8
and x = 10. Call the function with variables a, b, c to
circularly shift values.

Solution:

//Ahmad Furqan
//P5.g
#include <iostream>
#include <conio.h>
using namespace std;
void rotate(int &a, int &b, int &c)
{
int temp;
temp = c; //store c to a temporary variable
c = b; //move b to c
b = a; //move a to b
a = temp; //move temp to a,where temp contains c's original value
return;
}
void main(void)
{
int a, b, c;
a = 15;
b = 13;
c = 53;
cout << "Before Rotation:" << endl;
cout << "a=" << a << " ,b=" << b << " ,c=" << c << endl;
rotate(a, b, c);
cout << "After Rotation:" << endl;
cout << "a=" << a << " ,b=" << b << " ,c=" << c << endl;
_getch();
}

Chapter 5,Problem f: Let Us C

Problem Statement:

Write a C function to evaluate the series 
sin(x) = x − (x 3 / 3!) + (x 5 / 5!) − (x 7 / 7!) +Lto five significant digits.

Solution:

//Ahmad Furqan
//P5.f
#include <iostream>
#include <conio.h>
using namespace std;
int fact(int num)
{
int f = num;
for (int i = num-1; i > 0; i--)
f = f*i;
return f;
}
int pow(int a, int b)
{
int p = a;
for (int i = 1; i < b; i--)
p *= a;
return p;
}
float sin_ser(float ang)
{
float s;
s = ang - (pow(ang, 3) / fact(3)) + (pow(ang, 5) / fact(5)) - (pow(ang, 7) / fact

(7))+(pow(ang,9)/fact(9));
return s;
}
void main(void)
{
float ang;
cout << "Enter an angle: ";
cin >> ang;
cout << "sin(" << ang << ")= " << sin_ser(ang);
_getch();
}

Chapter 5,Problem e:Let Us C by Yashawant Kanetkar Solution manual

Problem Statement:

Write a recursive function to obtain the running sum of first
25 natural numbers.

Solution:

//Ahmad Furqan
//P5.e
#include <iostream>
#include <conio.h>
using namespace std;
int sum_nat(int num)
{
if (num == 25)
return num;
return num + sum_nat(num + 1);  //return current num + sum of numbers above this num and upto 25
}
void main(void)
{
cout << "Sum of first 25 Natural Numbers is: ";
cout << sum_nat(1);
_getch();
}

Chapter 5,Problem d: Let Us C by Yashawant Kanetkar Solution Manual

Problem Statement:

A positive integer is entered through the keyboard, write a
function to find the binary equivalent of this number using
recursion.

Solution:

//Ahmad Furqan
//P5.d
#include <iostream>
#include <conio.h>
using namespace std;
int num2bin_rec(int num)
{
//if number is less than 2 return it
if (num < 2)
return num;
//show num/2's binary equivalent
cout<<num2bin_rec(num/2);
//return 1st binary digit of number
return num % 2;
}
void main(void)
{
int num;
cout << "Enter a positive number: ";
cin >> num;
cout << num2bin_rec(num);
_getch();
}

Chapter 5,Problem c: Let Us C by Yashawant Kanetkar Solution Manual

Problem Statement:

Write a recursive function to obtain the first 25 numbers of a
Fibonacci sequence. In a Fibonacci sequence the sum of two
successive terms gives the third term. Following are the first
few terms of the Fibonacci sequence:
1 1 2 3 5 8 13 21 34 55 89...

Solution:

//Ahmad Furqan
//P5.c
#include <iostream>
#include <conio.h>
using namespace std;
int fabb[25],index=0;
void fabb_rec(int a, int b)
{
if (index == 25)
return;
fabb[index] = a + b; //add previous terms
//update last two terms
a = b;
b = fabb[index];
index++;
return fabb_rec(a, b);
}
void main(void)
{
cout << "First 25 numbers of a Fibnocci sequence are: " << endl;
index = 2;
fabb[0] = 1;
fabb[1] = 1;
fabb_rec(1, 1);
for (int i = 0; i < 25; i++)
cout << " " << fabb[i];
_getch();
}

Chapter 5,Problem b: Let Us C by Yashawant Kanetkar Solution Manual

Problem Statement:

A positive integer is entered through the keyboard, write a
program to obtain the prime factors of the number. Modify the
function suitably to obtain the prime factors recursively.

Solution:

//Ahmad Furqan
//P5.b
#include <iostream>
#include <conio.h>
using namespace std;
bool is_prime(int num)
{
if (num == 2 || num == 3)
return true;
if (num < 2 || num%2==0)  //If number is less than 2 or even its not prime
return false;
//starting from 3 we try dividing by odd numbers,
//since its not even its not divisible by any even number
//we need to go upto num/2
for (int i = 3; i < num / 2; i += 2)
{
if (num%i == 0)
return false;
}
return true;
}
void show_prime_fact_rec(int num)
{
if (is_prime(num)) //if num is prime show it and return since it don't have any factors
{
cout << num << endl;
return;
}
//find smallest prime factor of the number and show it
int i;
for (i = 2; i < num / 2; i++)
{
if (num%i == 0)
{
if (is_prime(i))
break;
}
}
cout << i << endl;
//call function with num divided with lowest prime factor to find other factors
return show_prime_fact_rec(num/i);
}
void main(void)
{
int num;
cout << "Enter a number: ";
cin >> num;
cout << "Prime factors of the number are:" << endl;
show_prime_fact_rec(num);
_getch();
}