[go: up one dir, main page]

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

14 - Programs To Practice

The document outlines the design of four classes in programming: Convert for converting day numbers to dates, ArmNum for checking Armstrong numbers, Special for identifying special numbers based on digit factorials, and Number for calculating the sum of digits and prime factors. Each class includes data members, constructors, and specific methods to perform their respective tasks. Additionally, a main function is suggested for creating objects and invoking these methods.

Uploaded by

narayansarvagya
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)
15 views2 pages

14 - Programs To Practice

The document outlines the design of four classes in programming: Convert for converting day numbers to dates, ArmNum for checking Armstrong numbers, Special for identifying special numbers based on digit factorials, and Number for calculating the sum of digits and prime factors. Each class includes data members, constructors, and specific methods to perform their respective tasks. Additionally, a main function is suggested for creating objects and invoking these methods.

Uploaded by

narayansarvagya
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

Programs to Practice

Question No. 1
Design a class Convert to find the date and the month from a given day number for a particular year .
Example: If day number is 64 and the year is 2020, then the corresponding date would be:
March 4, 2020 i.e. (31 + 29 + 4 = 64)
Some of the members of the class are given below:
Class Name : Convert
Data Members/Instance Variables:
n : integer to store the day number
d : integer to store the day of the month (date)
m : integer to store the month
y : integer to store the year
Methods/Member Functions:
Convert() : constructor to initialize the data member s with legal initial values
void accept( ) : to accept the day number and the year
void day_to_date( ) : converts the day number to its corresponding date for a particular year and store
the date in ‘d’ and the month in ‘m’
void display( ) : displays the month name, date and year
Specify the class Convert giving details of the constructor( ), void accept( ), void day_to_date() and void
display( ). Define a main( ) function to create an object and call the functions accordingly to enable the task

Question No. 2
Design a class ArmNum to check if a given number is an Armstrong number or not. [A number is said to be
Armstrong if sum of its digits raised to the power of length of the number is equal to the number]
Example : 371 = 33+73+13
1634 = 14+ 64+ 34+ 44
54748 = 55+ 45+ 75+ 45+ 85
Thus 371, 1634 and 54748 are all examples of Armstrong numbers.
Some of the members of the class are given below:
Class Name : ArmNum
Data Members/Instance Variables :
n : to store the number
l : to store the length of the number
Methods/Member Functions :
ArmNum(int nn) : parameterized constructor to initialize the data member n=nn
int sum_pow(int i) : returns the sum of each digit raised to the power of the length of the number
void isArmstrong( ) : checks whether the given number is an Armstrong number by invoking the
function sum_pow() and displays the result with an appropriate message.
Specify the class ArmNum giving details of the constructor(),int sum_pow(int) and void isArmstrong( ).
Define a main( ) function to create an object and call the functions accordingly to enable the task.

Question No. 3
A special number is a number in which the sum of the factorial of its digits is equal to the number.
Example : 145(1!+4!+5!=145). Thus 145 is a special number.
Design a class Special to check if the given number is a Special number or not. Some of the members of the
class are given below:
Class Name : Special
Data Members/Instance Variables:
n : integer to store the number
Methods/Member Functions :
Special() : default constructor
void read() : to accept the number
int factorial(int x) : return the factorial of the number
boolean isSpecial() : checks for the special number by invoking the function factorial() and returns true
if Special otherwise returns false
void display() : to show the result with an appropriate message.
Specify the Special , giving details of the Constructor, void read(), int factorial(int), boolean isSpecial() and void
display(). Define the main() function to create an object and call the member function according to enable the
task.
Question No. 4
A class Number has been defined to find the sum of each digit present in the number and the Prime factors of the
number and display the results. Some of the members of the class Number are given below:
Class name : Number
Data member :
num : integer type
Member functions :
Number( ) : constructor to assign 0 to num
Number(int a) : constructor to assign a to num
int sumDigit( ) : to find the sum of each digit of the number and display it.
void PrimeFactors( ) : to find the prime factors of the number and display them.
Specify the class Number giving the details of the two constructors and functions void PrimeFactors() and
int sumDigits( ). Define the main() function to create an object and call the member function according to enable
the task.

You might also like