Page 255 - Cs_withBlue_J_C11_Flipbook
P. 255
int hr : Hours worked
double rate : Stores rate per hour
double wg : Stores wage received by the guard
Member Methods
gurad(String n, int h) : Constructor to assign n to gn and h to hr
void calwage() : Calculates the wage of the guard as per the table given below
Hours worked Rate
Up to 48 hrs. ` r per hr.
Next 5 hrs. ` 1r per hr.
Next 2 hrs. ` 1.5r per hr.
Restriction No one is allowed to work more than 55 hrs. per week
void display() : Prints in the following way
Name Hours worked Total wage
--------- --------- ---------
2. Define a class triplet with the following details.
Data Members
int n1, n2, n3
Member Methods
triplet() : constructor to initialise data members with default values
void input() : accepts three numbers
void check_triplet() : checks whether the numbers are Pythagorean Triplets or not
3. Define a class shop with the following data members.
Data Members
String item : Name of the item
int nom : Number of materials in stock
Member Methods
shop() : Constructor to initialise with default values
shop(String i, int n) : Assigns i to item and n to nom
void buy(int n) : Checks whether the number in stock is more or equal to n. If, less than n, shows a message cannot
buy, else after the sale, maintains a balance nom-n
4. A perfect square is an integer that is the square of another integer. For example, 4, 9,16 are perfect squares.
Design a class Perfect with the following description:
Data Members/Instance variables
n : stores an integer number
Member Functions
Perfect( ) : Default constructor
Perfect(int) : Parameterised constructor to assign a value to ‘n’
void perfect_sq() : Displays the first 5 perfect squares larger than ‘n’ (if n = 15, then displays next 3 perfect squares 6,
25, 36)
void sum_of() : Displays all the combinations of consecutive integers whose sum is equal to n.
The number n = 15 can be expressed as:
1 2 3 4 5
4 5 6
7 8
Also, define the main function to create an object and call the methods accordingly to enable the task.
5. A happy number is a number in which the eventual sum of the square of the digits of the number is equal to 1.
Example 1:
2
2
28 = (2) + (8) = 4 + 64 = 68
253
Methods and Constructors 253

