Professional Documents
Culture Documents
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().
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
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.
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.
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.
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:
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
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 )
******************