Page 222 - Computer science 868 Class 12
P. 222
Data Members
n : integer to be checked whether it is triangular or not.
Member Functions
void getnum() : To accept integer n
int check(int) : To check if n is triangular
void dispnum() : To display message whether n is triangular or not
Specify the class Numbers giving details of the functions void getnum(), int check(int) and void dispnum(). The main function need
not be written.
12. A special number is a number in which the sum of the factorial of each digit is equal to the number itself.
For example: 145 = 1! + 4! + 5!
= 1 + 24 + 120
Design a class Special to check if a given number is a special number. Some of the members of the class are given below.
Class name : Special
Data Members
N : Integer
Member Functions
Special() : constructor to assign 0 to n
Special(int) : parameterised constructor to assign a value to ‘n’
void sum() : calculate and display the sum of the first and last digit of n
void isSpecial() : check and display if the number n is a special number
Specify the class Special giving details of the constructor, void sum() and void isSpecial(). You need not write the main function.
13. Define a class Taximeter having the following description.
Data Members/instance variables
int taxino : to store taxi number
String name : to store passenger’s name
int km : to store number of kilometres travelled
Member Functions
Taximeter() : constructor to initialise taxino to 0, name to "" and km to 0
input() : to store taxino, name, km
calculate() : to calculate bill for a customer according to given conditions
Travelled(km) Rate/km
1 km `25
1 < km ≤ 6 `10/km
6 < km ≤ 12 `15/km
12 < km ≤ 18 `20/km
>18 km `25/km
display() : to display the details in the following format
Taxino Name Kilometres travelled Bill amount
----- ----- --------- ------
14. You are asked to print the telephone bill of a subscriber.
Create a class having the following data members:
Phone_Number : long data type (for storing the phone number)
Name : String type (for storing the name of a subscriber)
Hire_Charge (a symbolic constant) : int type (to store monthly hire charge say `200)
Units_Consumed : int type (to store the monthly units consumed)
Bill_Amount : float type (to store the bill amount that is payable)
Create member functions for the following:
i. Constructor to initialise all data members except Hire_Charge and Bill_Amount
ii. Calculate the bill amount payable which is Hire Charge + (`1 per unit for the first 100 units, `1.50 per unit for the next 100 units
and `2.00 per unit there after)
iii. Display the Bill for the subscriber
220220 Touchpad Computer Science-XII

