Computer Practical File Questions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Program – 1

A class telcall calculates the monthly phone bill of a consumer. Some of the members of the
class are: -
Class name: telcall
Data Members: i) phno = No. Of Consumer
ii) name = Name of Consumer
iii) n = No. Of calls made (Integer)
iv) amt = Bill Amount
Member Functions / Methods: -
 telcall (int x , string y , int k) = Parameterized constructor to assign details & value to
data members.
 void compute( ) = To calculate the amount of bill according to the criteria given
below.
 void display( ) = To display the details in specified format.

NO. OF CALLS CHARGE


1-100 ₹ 500 at rental charge only
101-200 ₹ 1.00 per call + rental charge
201-300 ₹ 1.20 per call + rental charge
Above 300 ₹ 1.50 per call + rental charge

 In the main function , create an object & display as follows: -


Phone no: XXXXX XXXXX
Name: XXXXXX
Total Call: XXXX
Amount: XXXXXXX
Program – 2
A class digits performs an extraction of digits from a number, some of the members of class
are: -
Class name: digits
Data Members: i) num = To store an integer number
ii) p = To store product (Integer)
iii) s = To store sum (Integer)
Member Functions / Methods: -
 digits( ) = Default constructor to assign value to data members.
 digits (int nx) = Parameterized constructor to assign data member num = nx.
 void extraction( ) = To calculate & store product of the first and last integer of the
number and , store the sum of integers between them in data member s.
 void display( ) = To display the number , products & sum of remaining into suitable
heading.

Specify the class digit, giving the details of functions, void extraction() and void
display( ). Define a main function & create an object and call the member methods to
enable the task.
Program – 3
A class function defines to calculate the result of the relation: -

Some of the member of the class are given below:-

Class name: Function

Data Members:
 Function( ) = Default constructor to assign value to data members.
 void readnum( ) = To return the factorial of argument ‘d’.
 void show( ) = To display the value of ‘F’ by invoking the function int factorial
(int d).
Specify the class function , giving the details of constructor , functions , void
readnum( ) , int factorial (int d) and void show( ).
Define a main function to create an object & call the methods accordingly to enable the
task.
Program – 4

A class string is to declare to perform string related operations. The details of the class are
given below.
Class name: string
Data Members: I) str - To store a string.
II) rev - To store the reverse of the string
III) s - Integer to store spaces.
IV) w - Integer to store words.
Member functions:
 string( ) = Constructor to store legal initial values to data members.
 void inputstr( ) = To read a string str from input. The words in the string can be
separated by one or more blank spaces.
 void getrev ( ) = To store the reverse of of the string stored in str into rev terminated
by full stop. Do not use reverse() function. Print the original string and the reverse
string.
 void count ( ) = To count and print total no of spaces and total no of words from the
original str.
Specify the class string, giving details of the constructor functions void inputstr(), void
getrev ( ) , void getstr( ) and void count( ) . Also write a main () function to create the
object and invoke the methods.
Program – 5
A class process has been defined to count vowels and consonants. The details of the
class are given below: -

Class name: Process

Data members: I) st - string to store a sentence

II) newst- string to store a changed sentence.

III) cv - integer to store vowels (no.)

IV) cc- integer to store consonant (no.)

Member functions ():

 Process( ) - Default constructor


 Process(String ns) - Parameterized constructor to assign st = ns.
 void changecase( ) - Converts the sentence in st to lowercase and store in newst.
 void countletters( ) - To count and print no of vowels and no. of consonants in
each word of the string newst in the given format.

Eg:- INPUT: sky is Blue

OUTPUT : Word Vowel Consonants

sky 0 3

is 1 1

blue 2 2

Specify the class process, giving details of the constructors, functions void
changecase() and void countletters(). Also, write a main () function to create the
object and invoke necessary methods to enable the tasks.
Program – 6

Input a word in uppercase and check for the position for the first occurring vowel and
perform the following operations:

(i) Words that begins with a vowel are concatenated with "Y".

For example: EUROPE becomes EUROPEY

(ii) Words that contain a vowel in-between should have the first part from the position
of the vowel till end followed by the part of the string from beginning till position of
the vowel and is concatenated with C.

For example: PROJECT becomes OJECTPRC

(iii) Words that do not contain a vowel are concatenated with "N".

For example: SKY becomes SKYN

Design a class using the description given below:-

Class name: Rearrange

Data members/instance variables:

(i) txt: String to store a word.


(ii) cxt: String to store the rearrange word.
(iii) len: Integer to store length of the word.

Member functions/methods:

 Rearrange(): A constructor to initialize the instance variables.


 void readword( ): To accept the word input int txt in UPPER CASE.
 void convert( ): Convert the word into string cxt.
 void display():to print original and the changed word.

Specify the class and rearrange giving details of the constructor, functions void
readword(), void convert() and void display(). Write a main() function to create an
object and call the function to enable the task.
Program – 7
A class TheString accepts a string of maximum of 100 characters with only one blank
space between the two words. Some of the members of the class are given below:-

Class name: TheString

Data members/instance variables :-

I) str: To store a string.

II) len :Integer to store the length of the string.

Member functions/methods:-

 TheString(): Constructor to initialize the data members with initial values.


 TheString(String ds): Parameterized constructor to assign str = ds.
 void printFreq(): Converts the string into uppercase form using suitable function
and to count the frequency each alphabet. Print the alphabet and its frequency in
two columns.
For example:
Input: This is a ball

OUTPUT: - Alphabet Frequency

A 2
B 1
H 1
I 2
L 2
S 1
T 1

Specify the class TheString, giving details of the constructors and function void printFreq().
Define a main function to create the object and call the methods to enable the task.
Program – 8
The strength of uppercase letters is measured as: A = 1 , B = 2 , C = 3 , D = 4 ..... Z=26
The potential of a word is measured by adding the strength of each alphabet in the word. For
Example:
INPUT: BEST, its potential = 2+5+19+20 = 46
(as B = 2 , E = 5 , S = 19 & T = 20)
Design a class Strength with the following details: -
Class name: Strength

Data members: I) st – Stores a String

II) str- Stores a String in Uppercase form.

Member functions ():

 Strength( ) - Constructor to initialize the data members.


 void readStr( ) - To accept a sentence in st and store its uppercase form in str.
 void show( ) - To print the original & uppercase sentence with suitable message.
 void Potential( ) - To find and print the potential of each word of Str (using the
method described above) in two columns as per the given format: -
For Example:
INPUT: BEST OF LUCK
OUTPUT : WORD POTENTIAL
BEST 46
OF 21
LUCK 47

Specify the class Strength giving details of the constructor , functions void
readStr( ), void show( ) & void Potential( ). Define a main( ) function to create
the object and call the methods accordingly to enable the task.
Program – 9
A class PrimeFact generates all the prime factors of a positive integer greater than
0.

For Example: If the number is 24, then its prime factors will be: 2, 2, 2, 3. If the
number is 11, its prime factors will be: 11.

Design a class PrimeFact with the following details: -


Class name: PrimeFact
Data members/instance variables:
I) num - Integer to store a number.
II) sum - Integer to store sum of all the prime factors.

Member functions/methods : -
 PrimeFact( ) : Constructor to initialize the data members with initial values.
 void Accept( ): To input the value of the data member num.
 void generateFacts( ): To generate and print all the prime factors of 'num' and
also store the sum of all the prime factors to the data member 'sum'.
 void print( ): To display the original number and the sum of prime factors.

Specify the class PrimeFact, giving details of the constructor, functions void
Accept(), void generateFacts() and void Print(). Define a main() function to
create the object and call the methods accordingly to enable the task.

Program – 10
A class sort contains an array of 50 integers. Some of the member functions and data
members are given:

Class name: sort

Data members/instance variables:

I) arr[ ] - Integer array to store numbers.

II) item - Number to be searched from the array.

Member functions/methods: -

 void inpdata( ): To input 50 integers (no duplicate numbers are to be entered).


 void bubsort( ) : to sort the array in ascending order using the bubble sort
technique and display the sorted list.
 void binsearch( ): To input item and search for it using the binary search
technique: found, print the item searched and its position in the sorted lis
otherwise, print an appropriate message.

Specify the class sort giving details of the functions void inpdata( ), void bubsort()
and void binsearch( ). Define main() function to create an object and call the methods
to enable the task..

You might also like