You are on page 1of 8

CITY MONTESSORI INTER COLLEGE, PROGRAM WORKSHEET

IMPORTANT QUESTIONS FOR BOARDS


“The three great essentials to achieve anything worth while are: Hard work, Stick-to-itiveness, and Common sense.”

Programs For Practice


Read more at http://www.brainyquote.com/quotes/quotes/t/thomasaed149042.html#6ttFSBZpi4FS3MzG.99”

(Note: Define main function in all programs)


1. A class Quad contains the following:
Class name Quad
Data members
a, b, c, x1, x2 float type data
Member functions
Quad(float, float, float) constructor
float discriminant() to return the discriminant (b2-4ac)
void rootequal() to display the root if both root are equal.
void imag() to display the roots, if roots are imaginary.
void root_real() to display the two real, unequal roots.
void root() to call other appropriate functions to find the solution of the problem.
If ax + bx +c=0 is the quadratic equation then if b2-4ac > 0 roots are real, unequal
2

Where x1 = -b +  b2-4ac
2a

x2 = -b -  b2-4ac
2a
If b – 4ac = 0 roots are real and equal
2

x1 = x2 = -b/2a
If b – 4ac < 0 roots are imaginary.
2

Specify the class Quad giving details of the constructors and all the functions.

2. A class called Number has been defined to find the frequency of each digit present in it and the sum of the
digits and to display the results. Some of the members of the class Number are given below:
Class Name Number
Data members num-long integer type
Member functions
Number( ) constructor to assign 0 to num
Number(long n) constructor to assign n to num
void digitFrequency() to find the frequency of each digit and to display it.
int sumDigits() to return the sum of the digits of the number using
recursion.
Specify the class Number giving details of the two constructors and functions void digitFrequency() and int
sumDigits().

3. A number is said to be palindrome if it is equal to its reverse.


A non palindrome number can be converted into palindrome by adding the reverse of the numbers into
number itself until number does not become palindrome. Example
NUM  576 reverse  675
 576 + 675
 1251 (not palindrome)
1
 1251 + 1521
 2772 (palindrome)
Class name Palin
Data members
num an integer to store number
Member functions
Palin(int n) parameterized constructor
int reverse(int n) return reverse of n using recursion.
int palindrome() make palindrome(current num) if not
int ismagical() returns 1 if num is a magical number. A number is said to be magical if it sum of its digits till
single digit is 1.

4. A perfect square is a number which has square root of a natural number. Example 4 is a perfect square of 2,
9 is of 3 etc.
Square root of any perfect square can be calculated by resolving the given number into prime factors and
take the product of prime factors and take the product of prime factors choosing one out of every pair.
Eg. 1156= 2x2x17x17
1156 =2 x 17=34

Class name PerfectSquare


Data members
num to store number
Member functions
PerfectSquare(int n) Parameterized constructor
int isprime(int n) return 1 if n is prime 0 otherwise using recursion
int nextPrimeTo(int n) returns next prime number immediate after n
int isPerfectSquare() returns square root of num if perfect square, 0 otherwise.

5. A class called date has been defined to handle Date related functions i.e. finding the future date n days after
the current date, finding the number of days between the current date and the date on which a project ends.
You may assume that all the dates are in the year 2006 only and are valid dates.
Class name Date
Data members: dd-day, mm-month
Member functions:
Date(int nd,int nm) constructor
Date dateNumberTodate(int dn) returns the date equivalent to the given date Number dn.
Date futureDate(int n) returns the date that occurs n days after the current Date object. You may
assume that the future date will be in the year 2006 only.
Specify the class Date giving details of the constructors and all the functions.

6. A manager of an internet service provider company wants to analyze the system usage from the log records
to find the utilization of the system. He wants to know:
For how long did each user use the system?
When the user wants to use the system he must login to the system and after finishing the work he must log
out the system.
2
The time format is the 24-hour system hour and minutes.
You may assume that data is valid and a user will login for less than 24 hours.
If endtime is less than the starttime it means that the user logged in over the night.

Class name Time


Data members hh-hours
mm-minutes
Member functions:
Time() constructor
void readtime() to read time in 24 hour mode
void disptimeansi() to display the time in 24 hour mode
int timetominutes(Time) to find total number of minutes.
void minutestotime(int) to convert total number of minutes into hh mm.
void diff(Time endtime, Time starttime) to find the difference between endtime and starttime in hours
and minutes.

Specify the class Time giving details of the constructors and all the functions. You do not need to write the
main function.

7. A ticket at a ticket selling booth at a fair is priced at Rs. 2.50/-. The booth keeps track of the total number of
people who have visited the booth, the number of people who have actually purchased a ticket and the total
amount of money collected. Design a class called Ticbooth which includes the following members:
Class name Ticbooth
Data members
no_people number of people who have visited the booth
amount total amount of money collected
Member functions:
void initial() to assign initial value to data members
void notsold() increment total number of people only visiting the booth and not purchasing a ticket.
void sold() increment total number of people purchasing a ticket and the amount collected when
a ticket is sold.
void disp_totals() to display the total number of people visiting the booth(the total number of people
purchasing the ticket as well as those not purchasing a ticket).
void disp_ticket() to display the total number of ticket sold and the amount collected.
Specify the class Ticbooth giving details of the constructors and all the functions.

8. sum=1 + x + x3 + x5 + ………….. + x2n-1


1! 2! 3! n!
Class name SeriesSum
Data members x, n (integer), sum (double)
SeriesSum() constructor
int factorial(int n) returns factorial of n using recursion.
double term(int p, int q) returns the value of p/q! by making use of
factorial(int).
void accept() input the value of x and n.
void displaysum() display the value of sum.
double calsum() calculates the sum of the given series using the appropriate data and other member
function.

9. sin(x) can be computed by the following infinite series:


3
x-x3/3!+x5/5!-x7/7!+….x is radians and(0<=x<=/2)
A class called Trig has been defined to calculate the rigonometric functions. Some of the functions in Trig
are:
Class name Trig
Data members:
double x to store the value of x
Member functions:
double abs(double x) calculates and return the absolute value of x.

double sin(double x) calculates and returns the value of sin(x) correct to 5 places after the decimal using
the infinite series above.
(a) Specify the class Trig giving the details of the constructor, double abs (double x), double sin(double x)
only.
(b) What care do you need to take while designing double sin(double x).

10. There is class Ascending that contains integers that are already arranged in ascending order. Some of the
member functions af Ascending are given below:
Class name Ascending
Data members:
int al[] an array of integers sorted in ascending order
int size numbers of integers in the array
Member functions:
Ascending(int n) constructor to create an Ascending list of size n
void displayList() to display the list of integers
Ascending merge(Ascending al) to merge the Ascending list al with the current Ascending list object and
return a third Ascending list which is also sorted in ascending order.
Important: While generating the final Ascending list both the original Ascending list must be scanned only
once. Elements common to the two lists should appear only once in the third Ascending list.
Specify the class Ascending giving details of the functions void displayList() and Ascending
merge(Ascending al) only.

11. Your computer teacher is trying to analyze the performance of the class in the previous exam. He has a class
called Performance, which contains the marks of 100 students in the class. These are not sorted. He wants to
find the two quantities:
mode- the most frequently occurring mark in the class. If two or more marks occur equally frequently then
the highest of these marks is the mode.
mode frequency- frequency at mode
You can make following assumptions:
The class has 600 students the maximum marks anyone can get are 100 and the minimum is 0. All students
marks are whole numbers.
Important: You are not allowed to sort the marks.

Class name Performance


Data members: mark[] an array to store the marks of 600 students.
Member functions:
Performance() constructor
void readmarks() for reading the marks into an array.
int getmode() for returning the mode
int getfreqatmode() for returning the frequency at mode
void calcmodeandfrequncy() a single function that calculates both mode and frequency at mode.
4
12. A class Stringop is designed to handle string related operation. Some members of the class are given below:
Class name Stringop
Data members txt --- to store the given string of maximum length 100.
Member functions
Stringop() constructor
void readstring() to accept the string
char caseconvert(int, int) to convert the letter to other case
void circulardecode() to decode the string by replacing each letter by converting it to opposite case and
then by the next character in a circular way. Hence “Abz” will be decoded as “bCa”.

13. Design a class Stringfun to perform various operations on strings without using built-in functions except for
finding the length of the string. Some of the member functions are given below:
Class name Stringfun
Data members:
str to store the strings
Member functions:
void input() to accept the string
void words() to find the and display the number of words, number of vowels and number of
uppercase characters in the strings.
void frequency() to display frequency of each character within the string.

14. You are given a string with English sentences as data. You have to read it and output it in formatted way so
that each sentence is on a new line with no leading blanks. A sentence is recognized by the following
patterns: full stop followed by a space followed by a capital alphabetic letter. Note that just a full stop by
itself does not indicate a sentence since the full stop may be part of a decimal number.
Class name Format
Data member str- to store the given string
len-length of the given string
Member functions:
Format() constructor
void readstring() reads the given string
char charat(int index) returns the character at position index of the string.
void writechar(char c) write a single character to the output
void writenewline() write a new line character to the output
int isupperc(char c) returns 1 if c is an uppercase character otherwise 0.
int isendofsentence(str,i) returns 1 if the end of a sentence has been reached at the character position I in
the string str and 0 otherwise.
void formatstr() using the method isendofsentence() formats and outputs the given string in such a
way that each sentence is on new line with no leading blanks.

15. A class Modify has been defined with the following details :
Class name : Modify
Data members:
St : stores a string.
Len : to store the length of the string.
Member functions:
void read() : to accept the string in Uppercase Alphabets.
void putin(int, char) :to insert a character at the specified position in the string and display the changed
string.
5
void takeout(int) :to remove character from the specified position in the string and display the changed
string.
void change() :to replace each character in the original string by the character which is a distance of 2
moves ahead. For example,
“ABCD” becomes “CDEF”
“XYZ” becomes “ZAB”

16. Specify the class counter whose class description is given below:
Class name Counter
Data member
count to store the count
Member functions
Counter() constructor
int inccount() increments count by 1.
int givecount() returns the value of count
Design a program to use this class counter to count the number of ladies, the number of gentleman and the
number of children type array guest[]. It consists of the following code:
Code Stands for
‘g’ gentleman
‘l’ lady
‘c’ child
The guest list may have codes for 15 people. For eg. The input data could be:
c, c, l, g, l, g, l, l, g, c, l, l, g, c. l
The output should be in the following format:
No. of ladies:
No. of gentleman:
No. of children:

17. Class MyArray contains an array of n integers(n<=100) that are already arranged in ascending order. The
subscripts of the array elements vary from 0 to n-1.
Class name MyArray
Data members: arr-an array of n integers
n-size of the array
Member functions:
MyArray() constructor
void readArray() array reads n integers that are arranged in ascending order.
void displayArray() displays n integers
int binarySeaarch(int value) searches for the value in the array using the binary search technique. It
returns the subscript of the array element if the value is found otherwise it returns –
999.

18. A set is a collection in which there is no duplication of elements. S=(1,6,9,24) is a set of 4 integer elements.
An array of integers may be used to represent a set. You may assume that there will be a maximum of 50
elements in the set. Following are some member functions of the class set:

Class name Set


Data members arr- an array of integers to store the elements of the set
n- an integer to store the total number of elements in the set
Member functions:
Set(int nn) constructor
6
void readElements() read the elements of the set
void displayElements() display the elements of the set
int getSize() returns n, the number of elements in the set
int has(int ele) reurns 1 if ele belongs to the current set object and 0 otherwise.
Set intersection(Set d) returns the intersection of set object d and the current set object i.e. the set
containing the elements that are common to both the sets.
Set unions(Set d) returns the union of set object d and the current set object i.e. the set containing the
elements that are present in both the sets

19. A class Binary is designed for having 16 bit Binary numbers


For example 42-> 0000 0000 0010 1010
Class name Binary
Data members:
bin[] an integer array to store binary number
Member functions:
Binary(int num) parameterized constructor to convert and store num into bin[] as a binary number.
int compareTo(Binary b) to compare Binary b to current binary number and return 1,0 or –1 if current
binary is greater than equals to or less than argument binary number respectively.
Binary addBinary(Binary b) to add and return Binary b with current Binary

20. In a continuous frequency distribution, arithmetic mean can be calculated by Direct method. The following
procedure is adopted for calculating arithmetic mean.
(a) Mid values of the class intervals are to be found out.
(b) Each mid value is to be multiplied by its respective frequency (mxf) and product is denoted by fm.
(c) All the product (fm) and frequencies (f) are to be added upto  fm. Add up number of frequency ( f).
(d) Divide  fm by  f

Arithmetic mean = x =  fm
f
for example
Class Intervals Mid values frequency fm
0-5 2.5 5 12.5
5-10 7.5 10 75.0
10-15 12.5 14 175.0
15-20 17.5 20 787.5

Observations 2, 4, 3, 7, 6, 9, 2, 1, 5, 6, 6, 7, 8, 9, 8, 15, 11, 12, 11, 11, ………etc

Class name Mean


Data members
data[] an integer array to store observations(<=200)
low to store lowest interval
high to store highest interval
n to store total number of observations
size to store size of interval
Member functions
void readObservations() to input data and other details for data members
int getfrequency(int s,int e) to calculate and return frequency of observations in between range s and e.
double Amean() to calculate and return arithmetic mean by direct method.

7
21. A data file contains name and telephone number as two of its fields. Write a program using an object to do
the following:
(a) Add records in the file
(b) Searching of a telephone number for a given name
(c) Determine the name if telephone number is known
(d) Updating the data file whenever there is a change in telephone number
(e) A menu to implement above mentioned task.

(  Happy Coding  )
******************

You might also like