0% found this document useful (0 votes)
84 views2 pages

Constructors Programs

The document provides specifications for 7 constructors programs involving classes. Program 1 involves a Factorial class with methods to input and display the factorial of a number. Program 2 involves a Prime class to check if a number is prime. Program 3 involves a Pay class to calculate employee salary details. Program 4 involves a Latin class to convert words to pig latin. Program 5 involves string operations like encoding characters. Programs 6 and 7 specify Furniture and Employee classes with methods to input, calculate, and display item and employee data.

Uploaded by

Debadrito Ray
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views2 pages

Constructors Programs

The document provides specifications for 7 constructors programs involving classes. Program 1 involves a Factorial class with methods to input and display the factorial of a number. Program 2 involves a Prime class to check if a number is prime. Program 3 involves a Pay class to calculate employee salary details. Program 4 involves a Latin class to convert words to pig latin. Program 5 involves string operations like encoding characters. Programs 6 and 7 specify Furniture and Employee classes with methods to input, calculate, and display item and employee data.

Uploaded by

Debadrito Ray
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

GLOBAL IQ COMPUTER EDUCATION CENTRE

P9, A. M. BOSE ROAD, KOLKATA-74


Ph: 25297261/ 9433103218
CONSTRUCTORS PROGRAMS
Prog1. Write a class Program with the following specifications:
Class Name: factorial
Data Members: int a;
Member Functions:
factorial( ): default constructor to initialize the data member
void input (int m) : to assign a with m
void display( ) : to print the factorial of the number.
Prog2. Write a class Program by using a class with the following specifications:
Class Name: prime
Data Members/ Instance variables: int n
Member Functions:
prime() : constructor to initialize n
void input(int x): to assign n with x
void display(): to check and print whether number n is prime or not.
Prog3. Write a class Program in Java with the following specifications:
Class name -- pay
Data members – String name, address, city
double salary
Member Functions –
pay ( ) – constructor to initialize the data members as given below
name: “Ashok Kumar”
address: “43, Ram Nagar”
city : “Jamshedpur”
salary : 6800.00
void outputdata( ) – to display initialized values
void calculate ( ) – to find and print the followings:
da = 15% of salary
hra = 10% of salary
pf = 12% of salary
gross = salary + da + hra
net = gross – pf
void display ( ) – to display the complete information
Prog4. Write a Program by using a class with the following specifications:
Class Name: latin
Data Members: String name – to contain a word
Member Functions:
latin( ) : default constructor to initialize the string
void input (String n) : to assign name with n
void display () : to display the piglatin form of the word.
Prog5. Write a class Program in Java with the following specifications:
Class Name: Stringop
Data Members: String str
Member Functions:
Stringop( ): to initialize str with NULL
void encode ( ): to replace and print each character of the string with second next character in ASCII table
example: A with C, B with D and so on………
void print ( ): to print each word of the string in a separate line

Page 1
GLOBAL IQ COMPUTER EDUCATION CENTRE
P9, A. M. BOSE ROAD, KOLKATA-74
Ph: 25297261/ 9433103218
Prog6. Define a class named Furniture with the following description:
Instance variables/ Data Members:

int item_code - stores the item code number


String item_name - stores the name of the item
double item_weight - stores the weight of the item (in kg)
int item_price - stores the cost of the item (in Rs.)

Member Methods:
i. Furniture ( ) - Default constructor to initialize data member to 0 / empty value
ii. void input ( ) - To input values for data member
iii. void calc ( ) - To modify item_price by reducing 10% of item_weight is more than 15 kg.
iv. void disp ( ) - Print all data members.

Prog7. Define a class Employee having the following description:


Data Members/ instance variables:
int pan- to store personal account number
String name- to store employee’s name
double taxincome- to store tax that is calculated
double tax- to store tax that is calculated
Member Functions:
Employee()- constructor to initialize pan to 0, name to “” and taxincome & tax to 0
void input ()- to store pan number, name and taxable income
void calculate()- to calculate tax of an employee
Total Annual Taxable Income Tax Rate
Upto Rs. 1,00,000 No Tax
From 1,00,001 to 1,50,000 10% of the income Exceeding Rs.1,00,000
From 1,50,001 to 2,50,000 Rs. 5000+20%of the income Exceeding
Rs.1,50,000
Above Rs.2,50,000 Rs. 25000+30%of the income Exceeding
Rs.2,50,000
void display()- to display the details in the following format
Pan No. Name Tax Income Tax
---------- -------- ---------------- ---------
Create an object in the main() method and call the above methods in it of ‘N’ number of
employees of an organization.

Page 2

You might also like