Page 223 - Computer science 868 Class 12
P. 223
15. Define a class PhoneBill with the following description.
Data Members
customerName : character type array
phoneNumber : long type
no_of_units : int type
rent : int type
amount : float type
Member Functions
calculate() : to calculate the value of amount as rent + cost for the units where cost for the
units can be calculated according to the following conditions.
No_of_units Cost
First 50 calls Free
Next 100 calls 0.80 @ unit
Next 200 calls 1.00 @ unit
Remaining calls 1.20 @ unit
constructor : to assign initial values
accept() : to enter customerName, phoneNumber, no_of_units and rent and call function
calculate()
display() : to display the values of all the data members on the screen
16. Create a class called PrimeDigits to find the sum of the prime digits in an integer. The class should have the following members.
Data Members:
n : int data type
Member Functions
Parameterised constructor to initialise the value of n
isPrime() : to accept an integer as a parameter and return true if it is a prime number
otherwise return false
sumOfPrimeDigits() : to accept an integer as a parameter and find the sum of prime digits only
17. Using the switch case, perform the following:
a. To calculate and print the sum of the following series: x+x/2!+x/3!+x/4!+...+x/n!
n
3
4
b. To calculate and print the sum of the following series: x/2!+x /3!+x /4!+x /5!+…+x /(n+1)!
2
2
c. To calculate and print the sum of the following series: x/2! - x /3!+x3/4! - x /5!+…±x /(n+1)! where the symbol ! stands for
n
4
factorial e.g., 5!=5*4*3*2*1, 3!=3*2*1
18. Write a program to calculate and print the sum of each of the following series, using the switch case.
(a) Sum (S) = 2 – 4 + 6 – 8 + ………. -20
(b) Sum (S) =x/2 + x/5 + x/8 + x/11 +…+ x/20
19. Write a program to generate a triangle or an inverted triangle till n terms based upon the user’s choice of triangle to be displayed.
Type 1 for a triangle and Type 2 for an inverted triangle
Input: 1 Input: 2
Enter the number of terms - 5 Enter the number of terms - 6
1 666666
22 55555
333 4444
4444 333
55555 22
1
20. Write a program to input a number and check whether it is a Smith number or not.
Smith number is a composite number in which the sum of its digits is equal to the sum of the digits of all its prime factors.
For example, 378 is a Smith Number as the sum of the digits of 378 are : 3+7+8 = 18.
The prime factors of 378 are: 2, 3, 3, 3, 7 (sum = 2+3+3+3+7 = 18).
Similarly, 22 is a Smith Number as the sum of the digits are : 2+2=4.
The prime factors of 22 are: 2 and 11 (Sum = 2+(1+1) = 4
Other examples include 27, 58, 85, 94, 121, 166, 202, 265, etc.
21. Write a program to accept a number and check and display whether it is a spy number or not. A number is a spy number if the
sum of its digits equals the product of its digits.
For example, consider the number 1124, the sum of the digits = 1 + 1 + 2 + 4 = 8. Product of the digits = 1 × 1 × 2 × 4 = 8
221
Statements and Scope 221

