tashi namgyal academytashinamgyalacademy.com/theme/file_repository/d95803a24... · web viewsum of...

30
TASHI NAMGYAL ACADEMY ISC PROJECT 2017 SUBJECT: COMPUTER SCIENCE 1) A smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 27, 58, 85, 94, 121 ………………………………… Example: 1. 666 Prime factors are 2, 3, 3, 37 Sum of digits are ( 6 + 6 + 6) = 18 Sum of the digits of the factors ( 2 + 3 + 3 + ( 3 + 7)) = 18 2. 4937775 Prime factors are 3, 5, 5, 65837 Sum of the digits are ( 4 + 9 + 3 + 7 + 7 + 7 + 5) = 42 Sum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program to input a number and display whether the number is a smith number or not. 2) An ISBN (International Standard Book Number) is a ten digit code which uniquely identifies a book. The first nine digits represent the group, publisher and title of the book and the last digit is used to check whether ISBN is correct or not. Each of the first nine digits of the code can take a value between 0 to 9. Sometimes it is necessary to make the last digit equal to ten. This is done by writing the last digit of the code as X. To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus 8 times the third digit and so on until we add 1 time the last digit. If the final number leaves no remainder while divided by 11, the code is a valid ISBN For example: 0201103311=10*0+9*2+8*0+7*1+6*1+5*0+4*3+3*3+2*1+1*1=55 This is a valid ISBN 007462542X=10*0+9*0+8*7+7*4+6*6+5*2+4*5+3*4+2*2+1*10=176 This is a valid ISBN Similarly 0112112425 is not a valid ISBN. Test Data: Input code: 0201530821 Output: Sum=99 Leaves no remainder – valid ISBN Input code: 356680324 Output: Sum=invalid input Input code: 0231428031

Upload: lamliem

Post on 18-Mar-2018

220 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

TASHI NAMGYAL ACADEMYISC PROJECT 2017

SUBJECT: COMPUTER SCIENCE

1) A smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 27, 58, 85, 94, 121 …………………………………

Example:1. 666

Prime factors are 2, 3, 3, 37Sum of digits are ( 6 + 6 + 6) = 18Sum of the digits of the factors ( 2 + 3 + 3 + ( 3 + 7)) = 18

2. 4937775Prime factors are 3, 5, 5, 65837Sum of the digits are ( 4 + 9 + 3 + 7 + 7 + 7 + 5) = 42Sum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42

Write a program to input a number and display whether the number is a smith number or not.

2) An ISBN (International Standard Book Number) is a ten digit code which uniquely identifies a book.The first nine digits represent the group, publisher and title of the book and the last digit is used to check whether ISBN is correct or not.Each of the first nine digits of the code can take a value between 0 to 9. Sometimes it is necessary to make the last digit equal to ten. This is done by writing the last digit of the code as X.To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus 8 times the third digit and so on until we add 1 time the last digit. If the final number leaves no remainder while divided by 11, the code is a valid ISBNFor example:0201103311=10*0+9*2+8*0+7*1+6*1+5*0+4*3+3*3+2*1+1*1=55This is a valid ISBN007462542X=10*0+9*0+8*7+7*4+6*6+5*2+4*5+3*4+2*2+1*10=176This is a valid ISBNSimilarly 0112112425 is not a valid ISBN. Test Data:Input code: 0201530821Output: Sum=99Leaves no remainder – valid ISBNInput code: 356680324Output: Sum=invalid inputInput code: 0231428031Output: Sum=122Leaves remainder – invalid ISBN

3) Write a program to declare a square matrix A[][] of order (MXN) where ‘M’ is the number of rows and the number of columns. ‘M’ should be greater than 2 and less than 20. Allow user to enter integers into this matrix. Display appropriate error message for an invalid input. Perform the following tasks.

1.    Display the input matrix

2.    Create a mirror image of the inputted matrix.3.    Display the mirror image matrix

Test Data:

Page 2: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

Input: M=34  16  12

8   2  14

6   1   3

Output:Original matrix4  16  12

8   2  14

6   1   3

Mirror image matrix:12  16  4

14  2    8

3   1    6

Input: M=22Output: Size out of range

4) A palindrome is a word that may be read the same in either direction.Accept a sentence in upper case which is terminated by either ‘.’  ,  ’,’  ,  ‘? ’ ,  ‘!’. Each word in the sentence is separated by a blank space.Perform the following tasks:Test Data:Input: MOM AND DAD ARE COMING AT NOON.Output: MOM DAD NOONNumber of palindromic words: 3Input: HOW ARE YOU?Output: No palindromic words

5) A bank intends to design a program to display the denomination of an input amount, up to 5 digits. The available denomination with the bank are of rupees 1000 , 500 , 100 , 50 , 20 , 10 , 5 , 2 , and 1.

Design a program to accept the amount from the user and display the break-up in descending order of denomination. (i.e. preference should be given to the highest denomination available) along with the total number of notes. [Note: Only the denomination used should be displayed]. Also print the amount in words according to the digits.Example 1INPUT:   14856OUTPUT:ONE FOUR EIGHT FIVE SIXDENOMINATION  :1000    x          14        =          14000500      x            1        =              500100      x            3        =              300

Page 3: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

50        x           1        =                505          x            1        =                  51          x            1        =                  1TOTAL                       =          14856TOTAL NUMBER OF NOTES  =          21Example 2INPUT :  6043OUTPUT :SIX ZERO FOUR THREEDENOMINATION:1000      x            6        =            600020        x            2        =                402          x            1        =                  21          X           1        =                  1TOTAL                       =            6043TOTAL NUMBER OF NOTES                      =            10Example 3INPUT :       235001OUTPUT:INVALID AMOUNT

6) A positive whole number ‘n’ that has ‘d’ number of digits is squared and split into two pieces, a right-hand piece that has ‘d’ digits and a left-hand piece that has remaining ‘d’ or ‘d-1’ digits. If the sum of the two pieces is equal to the number, then ‘n’ is a Kaprekar number. The first few Kaprekar numbers are: 9, 45, 297 ……..

Example 1:992  = 81, right-hand piece of 81 = 1 and left hand piece of 81 = 8Sum = 1 + 8 = 9, i.e. equal to the number.Example 2:45452 = 2025, right-hand piece of 2025 = 25 and left hand piece of 2025 = 20Sum = 25 + 20 = 45, i.e. equal to the number.Example 3:2972972 = 88209, right-hand piece of 88209 = 209 and left hand piece of 88209 = 88Sum = 209 + 88 = 297, i.e. equal to the number.Given the two positive integers p and q, where p < q, write a program to determine how many Kaprekar numbers are there in the range between p and q (both inclusive) and output them.

Page 4: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

The input contains two positive integers p and q. Assume p < 5000 and q < 5000. You are to output the number of Kaprekar numbers in the specified range along with their values in the format specified below:SAMPLE DATA:INPUT:p = 1q = 1000OUTPUT:THE KAPREKAR NUMBERS ARE:-1, 9, 45, 55, 99, 297, 703, 999FREQUENCY OF KAPREKAR NUMBERS IS:   8

7) Input a paragraph containing ‘n’ number of sentences where (1 = < n < 4). The words are to be separated with a single blank space and are in UPPERCASE. A sentence may be terminated either with a full stop ‘.’ Or a question mark ‘?’ only. Any other character may be ignored. Perform the following operations:

(i) Accept the number of sentences. If the number of sentences exceeds the limit, an appropriate error message must be displayed.(ii)  Find the number of words in the whole paragraph(iii) Display the words in ascending order of their frequency. Words with same frequency may appear in any order.Example 1INPUT:    Enter number of sentences.1Enter sentences.TO BE OR NOT TO BE.OUTPUT:Total number of words: 6WORD                                               FREQUENCYOR                                                                1NOT                                                             1TO                                                                2BE                                                                2

Page 5: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

Example 2INPUT:  Enter number of sentences3Enter sentences.THIS IS A STRING PROGRAM.IS THIS EASY?YES,IT IS.

OUTPUT:Total number of words: 11WORD                                               FREQUENCYA                                                                     1STRING                                                         1PROGRAM                                                    1EASY                                                             1YES                                                                1IT                                                                    1THIS                                                               2IS                                                                    3Example 3

 INPUT :  Enter number of sentences 5OUTPUT:INVALID ENTRY

8) Encryption is a technique of coding messages to maintain their secrecy. A String array of size ‘n’ where ‘n’ is greater than 1 and less than 10, stores single sentences (each sentence ends with a full stop) in each row of the array.

Write a program to accept the size of the array. Display an appropriate message if the size is not satisfying the given condition. Define a string array of the inputted size and fill it with sentences row-wise. Change the sentence of the odd rows with an encryption of two characters ahead of the original character. Also change the sentence of the even rows by storing the sentence in reverse order. Display the encrypted sentences as per the sample data given below.Test your program on the sample data and some random data.Sample Data:Input: n=4IT IS CLOUDY.IT MAY RAIN.THE WEATHER IS FINE.IT IS COOL.Output:KV KU ENQWFA.RAIN MAY IT.VJG YGCVJGT KU HKPG.COOL IS IT.Input: n=13Output: INVALID ENTRY

9) Design a program which accepts your date of birth in dd mm yyyy format. Check whether the date entered is valid or not. If it is valid, display “VALID DATE”, also compute and display the day number of the year for the date of birth. If it is invalid, display “INVALID DATE” and then terminate the program.

Test your program  for the given sample data and some random data.Input:Enter your date of birth in dd mm yyyy format05012010Output:VALID DATE

Page 6: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

5Input:Enter your date of birth in dd mm yyyy format03042010Output:VALID DATE93Input:Enter your date of birth in dd mm yyyy format34062010Output:INVALID DATE

10)Write a program to input a natural number less than 1000 and display it in words.Test your program for the given sample data and some random data.Sample Data:Input: 29Output: TWENTY NINEInput: 17001Output: OUT OF RANGEInput: 119Output: ONE HUNDRED AND NINETEENInput:500Output: FIVE HUNDRED

11)The computer department of the Agency of International Espionage is trying to decode intercepted messages. The agency’s spies have determined that the enemy encodes messages by first converting all characters to their ASCII values and then reversing the string.

For example, consider A_z (the underscore is just to highlight the space). The ASCII values for A, , z are 65, 32, 122 respectively. Concatenate them to get 6532122, then reverse this to get 2212356 as the coded message.Write a program which reads a coded message and decodes it. The coded message will not exceed 200 characters. it will contain only alphabets (A……Z, and a-z) and spaces. ASCII values of A…..Z are 65……90 and those of a….z are 97 …… 122. test your program for the following data and some random data.SAMPLE DATA:INPUT:Encoded Message:2 3 1 2 1 7 9 8 6 2 3 1 0 1 9 9 5 0 1 8 7 2 3 7 9 2 3 1 0 1 8 1 1 7 9 2 7OUTPUT:THE DECODED MESSAGE:  Have a Nice Day INPUT:Encoded Message:2 3 5 1 1  0 1 1 5 0 1 7 8 2 3 5 1 1 1 2 1 7 9 9 1 1 8 0 1 5 6 2 3 4 0 1 6 1 1 7 1 1 4 1 1 4 8OUTPUT:THE DECODED MESSAGE: Truth Always Wins

Page 7: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

12) A  Smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 27, 58, 85, 94, 121 ………………..

Example 11.  666Prime factors are 2, 3, 3, and 37Sum of the digits are (6+6+6) = 18Sum of the digits of the factors (2+3+3+(3+7)) = 18 2.   4937775Prime factors are 3, 5, 5, 65837Sum of the digits are (4+9+3+7+7+7+5) = 42Sum of the digits of the factors (3+5+5+(6+5+8+3+7)) = 42Write a program to input a number and display whether the number is a Smith number or not.Sample data:             Input 94          Output             SMITH Number

Input 102        Output             NOT SMITH NumberInput 666        Output             SMITH NumberInput 999        Output             NOT SMITH Number

13)A sentence is terminated by either “.”, or “?” followed by a space. Input a piece of text consisting of sentences. Assume that there will be a maximum of 10 sentences in block letters.

Write a program to:(i)  Obtain the length of the sentence (measured in words) and the frequency of vowels in each sentence(ii) Generate the output as shown below using the given data Sample Data:INPUTHELLO! HOW ARE YOU? HOPE EVERYTHING IS FINE. BEST OF LUCK.OUTPUTSentence          No. of Vowels          No. of Words—————————————————————1                             2                                  12                             5                                  33                             8                                  44                             3                                  3

Page 8: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

 Sentence                      No. of words / vowels——————————————————1                                  VVVVVV                                     WWW2                                  VVVVVVVVVVVVVVV                                    WWWWWWWWW3                                  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVV                                    WWWWWWWWWWWWWWWW 4                                  VVVVVVVVVVV                                    WWWWWWWWWWW

14) Given a square matrix list [ ] [ ] of order ‘n’. The maximum value possible for ‘n’ is 20. Input the value for ‘n’ and the positive integers in the matrix and perform the following tasks:

  Display the original matrix1. Print the row and column position of the largest element of the matrix2. Print the row and column position of the second largest element of the matrix3. Sort the elements of the rows in the ascending order and display the new matrix

 Sample Data: INPUT: N=3LIST [ ] [ ]5          1          37          4          69          8          2OUTPUT5          1          37          4          69          8          2The largest element 9 is in row 3 and column 1The second largest element 8 is in row 3 and column 2Sorted list1          3          54          6          72          8          9

Page 9: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

15) A positive natural number, (for e.g.27) can be represented as follows:2+3+4+5+6+78+9+1013+14where every row represents a combination of consecutive natural numbers, which add up to 27.

Write a program which inputs a positive natural number N and prints the possible consecutive number combinations, which when added give N. Test your program for the following data and some random data.

SAMPLE DATAINPUT N=15OUTPUT 1 2 3 4 54 5 67 8

16) Write a program that inputs the names of people into two different arrays, A and B. Array A has N number of names while Array B has M number of names, with no duplicates in either of them. Merge array A and B into a single array C, such that the resulting array is sorted alphabetically.

Display all the three arrays, A, B and C, sorted alphabetically.Test your program for the given data and some random data.

SAMPLE DATA

INPUT Enter number of names in Array A, N=2 Enter number of names in Array B, M=3

First array:(A) Suman Anil

Second array:(B)UshaSachin John

OUTPUT Sorted Merged array:(C)AnilJohnSachinSumanUshaSorted first array:(A)AnilSuman

Sorted Second array:(B)JohnSachinUsha

17) A new advanced Operating System, incorporating the latest hi-tech features has been designed by Opera Computer Systems.The task of generating copy protection codes to prevent software piracy has been entrusted to the Security Department.

Page 10: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

The Security Department has decided to have codes containing a jumbled combination of alternate uppercase letters of the alphabet starting from A upto K (namely among A,C,E,G,I,K). The code may or not be in the consecutive series of alphabets.Each code should not exceed 6 characters and there should be no repetition of characters. If it exceeds 6 characters, display an appropriate error message.Write a program to input a code and its length. At the first instance of an error display "Invalid" stating the appropriate reason. In case of no error, display the message "Valid".

Test your program for the following data and some random data.

SAMPLE DATA

INPUT N=4 ABCEOUTPUT Invalid Only alternate letters permitted!

INPUT N=4 AcIKOUTPUT Invalid! Only upper case letters permitted!

INPUT N=4 AAKEOUTPUT Invalid! Repetition of characters not permitted!

INPUT N=7OUTPUT ERROR! Length of string should not exceed 6 characters!

INPUT N=4 AEGIKOUTPUT Invalid! String length not the same as specified!

INPUT N=3 ACEOUTPUT Valid!

INPUT N=5 GEAIKOUTPUT Valid!

18) The input in this problem will consist of a number of lines of English text consisting of the letters of the English alphabet, the punctuation marks (') apostrophe, (.) full stop, (,) comma, (;) semicolon, (:) colon and white space characters (blank, new line). Your task is to print the words of the text in reverse order without any punctuation marks other than blanks.

For example consider the following input text:This is a sample piece of text to illustrate this problem.

Page 11: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

If you are smart you will solve this right.

The corresponding output would read as:

right this solve will you smart are you If problem this illustrate to text of piece sample a is ThisThat is, the lines are printed in reverse order.Note: Individual words are not reversed.

INPUT FORMAT:The first line of input contains a single integer N (<=20), indicating the number of lines in the input. This is followed by N lines of input text. Each line should accept a maximum of 80 characters.

OUTPUT FORMAT:Output the text containing the input lines in reverse order without punctuations except blanks as illustrated above.

19) A unique-digit integer is a positive integer (without leading zeros) with no duplicate digits.For example 7, 135, 214 are all unique-digit integers whereas 33, 3121, 300 are not.Given two positive integers m and n, where m< n, write a program to determine how many unique-digit integers are there in the range between m and n (both inclusive) and output them.

The input contains two positive integers m and n. Assume m< 30000 and n< 30000.

You are to output the number of unique-digit integers in the specified range along with their values in the format specified below:

SAMPLE DATA:

INPUT: m = 100 n = 120 OUTPUT: THE UNIQUE- DIGIT INTEGERS ARE : 102, 103, 104, 105, 106, 107, 108, 109, 120.FREQUENCY OF UNIQUE-DIGIT INTEGERS IS: 9.

20) Read a single sentence which terminates with a full stop(.). The words are to be separated with a single blank space and are in lower case. Arrange the words contained in the sentence according to the length of the words in ascending order. If two words are of the same length then the word occurring first in the input sentence should come first. For both, input and output the sentence must begin in upper case.

Test your program for the following data and some random data.INPUT : The lines are printed in reverse order.

OUTPUT : In the are lines order printed reverse.

INPUT : Print the sentence in ascending order.OUTPUT : In the print order sentence ascending.

21) Write a program to declare a matrix A[ ][ ] of order (m*n) where 'm' is the number of rows and n is the number of columns such that both m and n must be greater than 2 and less than 20.Allow the user to input positive integers into this matrix. Perform the following tasks on the matrix:

(a) Sort the elements of the outer row and column elements in ascending order using any standard sorting technique.(b) Calculate the sum of the outer row and column elements.

Page 12: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

(c) Output the original matrix, rearranged matrix, and only the boundary elements of the rearranged array with their sum.

Test your program for the following data and some random data.

1. Example :  INPUT : M=3, N=3 1 7 4 8 2 5 6 3 9

OUTPUT : ORIGINAL MATRIX : 1 7 4 8 2 5 6 3 9 REARRANGED MATRIX : 1 3 4 9 2 5 8 7 6 BOUNDARY ELEMENTS : 1 3 4 9 5 8 7 6

SUM OF OUTER ROW AND OUTER COLUMN = 43

22) A prime palindrome integer is a positive integer (without leading zeros) which is prime as well as a palindrome. Given two positive integers m and n, where m < n, write a program to determine how many prime-palindrome integers are there in the range between m and n (both inclusive) and output them.The input contains two positive integers m and n where m < 3000 and n < 3000. Display the number of prime palindrome integers in the specified range along with their values in the format specified below:

Test your program with the sample data and some random data:

Example 1:INPUT: m=100N=1000

OUTPUT: The prime palindrome integers are:101,131,151,181,191,313,351,373,383,727,757,787,797,919,929Frequency of prime palindrome integers: 15

Example 2:INPUT:M=100N=5000

OUTPUT: Out of range

23) Write a program to accept a sentence as input. The words in the string are to be separated by a blank. Each word must be in upper case. The sentence is terminated by either '.','!' or '?'. Perform the following tasks:

Page 13: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

1. Obtain the length of the sentence (measured in words)2. Arrange the sentence in alphabetical order of the words.

Test your program with the sample data and some random data:

Example 1:INPUT: NECESSITY IS THE MOTHER OF INVENTION.OUTPUT:Length: 6Rearranged Sentence:

INVENTION IS MOTHER NECESSITY OF THE

Example 2:INPUT: BE GOOD TO OTHERS.

OUTPUT:Length: 4Rearranged Sentence: BE GOOD OTHERS TO

24) Write a program to declare a matrix A [][] of order (MXN) where 'M' is the number of rows and 'N' is the number of columns such that both M and N must be greater than 2 and less than 20. Allow the user to input integers into this matrix.Perform the following tasks on the matrix:

1. Display the input matrix

2. Find the maximum and minimum value in the matrix and display them along with their position.3. Sort the elements of the matrix in ascending order using any standard sorting technique and rearrange them in the matrix.

Output the rearranged matrix.

Sample input OutputINPUT:M=3N=4

Entered values: 8,7,9,3,-2,0,4,5,1,3,6,-4

Original matrix:

8 7 9 3-2 0 4 5 1 3 6 -4

Largest Number: 9Row: 0Column: 2Smallest Number: -4Row=2

Column=3

Page 14: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

Rearranged matrix:

-4 -2 0 1 3 3 4 5 6 7 8 9

25) In “Piglatin” a word such as  KING is replaced by INGKAY , while TROUBLE becomes OUBLETRAY and so on . The first vowel of the original word becomesthe start of the translation, any  preceding letters being shifted towards the end and followed by AY.  Words that begin with a vowel or which do not containany vowel are left unchanged. Design a class  Piglatin using the description of the data members and member functions given below:   [10]Class name                                                 :    PiglatinData members /instance variables   :        Txt                                                   :   to store a word       len                                                   :   to store the lengthMember functions :      Piglatin( )                                           :   constructor to initialize the data mrmbers     void readstring( )                               :   to  accept the word input in UPPER CASE     void convert ( )                                 :   converts  the word into its  piglatin form and displays the word  (changed or unchanged)     void  consonant( )                             :   counts and displays the number ofconsonants present in  the given word.Specify the class  Piglatin  giving the details of the constructor, void readstring( ), void convert( ) and void consonant( ).   Also define the main function to create anobject and call methods accordingly to enable the task.

26) A class Author contains details of the author and another class Book List contains details of the books written by him. The details of the two classes are given below:   [10]Class name :  AuthorData members    authorno  : stores the author’s number name  : stores the author’s nameMember functions   Author ( )  : default constructor Author ( … )  : parameterised  constructor to assign values to author number and name void show( ) : to display the author’s details

Class name :  BooklistData members/instance variables    bookno  : Long type variable to the store book numberbookname : stores the book nameprice : float variable to store the price edition  : integer type variable to store the edition number

Page 15: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

Member functions Booklist (…)  :  parameterized constructor to assign values to data members of both the classesvoid show( )  : to display all the detailsSpecify the class  Author giving details of the  constructors and member function  void show( ).  Using the concept of Inheritance, specify the class Booklist giving details of theconstructor and the member function  void show( ). Also define the main function to create an object and call methods accordingly to enable the task.

27) A perfect square is an integer which is the square of another integer.  For example, 4, 9, 16 .. are perfect squares. Design a Class Perfect with the following description:   Class name :  Perfect

Data members/instance variables    n : stores an integer number

Member functions :   Perfect( )  : default constructor Perfect(int)  : parameterized constructor to assign a value to ‘n’ void perfect_sq()  : to display the first 5 perfect squares larger than ‘n’ (if  n = 15, the next 3 perfect squares are 16, 25, 36) void sum_of()  : to display all combinations of consecutive integers whose sum is equal to n. ( the number n = 15 can be expressed as        1      2     3      4     5        4      5     6        7      8Specify  the  class  Perfect  giving details of the constructors, void perfect_sq( ) and void sum_of().  Also define the main function to create an object and call methodsaccordingly to enable the task.

28) A class RecFact defines a recursive function to find the factorial of a  number.  The details of the class are given below:  

Class name :  RecFact

Data members/instance variables    n  : stores the number whose factorial is required. r  : stores an integer

Member functions :  

 RecFact( ) : default constructor void readnum( ) : to enter values for ‘n’ and ‘r’ int factorial(int)  : returns the factorial of the  number using the Recursive Technique. Void factseries(  )   : to calculate and display the value of  n! /  r!*(n-r )!

Specify the class RecFact  giving the details of the  constructor and member functions void readnum( ), int factorial(int) and void factseries( ).  Also define the main functionto create an object and call methods accordingly to enable the task.

Page 16: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

29) A class Combine contains an array of integers which combines two arrays into a single array including the duplicate elements, if any, and sorts the combined array. Some of the members of the class are given below:

Class Name : Combine

Data members

com[ ] : integer array size : size of the array

Member functions/methods

Combine(int nn) : parameterized constructor to assign size = nn Void inputarray( ) : to accept the array elementsvoid sort() : sorts the elements of combined array in ascending

order using the selection sort technique. void mix(Combine A, Combine B) : combines the parameterized object arrays and stores the result in the current object array along with the duplicate elements , if any. void display( ) : displays the array elements.

Specify the class Combine giving details of the constructor(int ), void inputarray( ), void sort(), void mix(Combine, Combine) and void display( ). Also define the main function to create an object and call the methods accordingly to enable the task.

30) Design a class VowelWord to accept a sentence and calculate the frequency of words that begin with a vowel. The words in the input string are separated by a single blank space and terminated by a full stop. The description of the class is given below:

Class Name : VowelWord

Data members Str : to store a sentence freq : to store the frequency of words beginning with a vowel.

Member functions

VowelWord() : constructor to initialize data members to legal initial values. voidreadstr() : to accept a sentence. voidfreq_vowel( ) : counts the frequency of the words beginning with a vowel. void display() :display the original string and the frequency of the 6 words that begin with a vowel.

Specify the class VowelWord giving details of the constructor( ), void readstr(), void freq_vowel() and void display(). Also defing the main function to create an object and call the methods accordingly to enable the task.

Page 17: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

31) A happy number is a number in which the eventual sum of the square of the digits of the number is equal to 1.

Example : 28 = (2)2 + ( 8 )2 = 4 + 64 = 68 68 = (6)2 + ( 8)2 = 36 + 64 = 100 100 = ( 1 )2 + ( 0 )2 + ( 0 )2 = 1 + 0 + 0 = 1

Hence 28 is a happy number.

Example : 12 = (1)2 + (2)2 = 1 + 4 = 5

Hence 12 is not a happy number.

Design a class Happy to check if a given number is a happy number. Some of the members of the class are given below:

Class Name : Happy

Data Members n : stores the number

Member functions: Happy( ) : constructor to assign 0 to n voidgetnum(int nn) : to assign the parameter value to the number n = nn int sum_sq_digits(int x) : returns the sum of the square of the digits of the number x, using the recursive technique. Void ishappy() : checks if the given number is a happy by calling the function sum_sq_digits(int) and displays an appropriate message. Specify the class Happy giving details of the constructor( ), void getnum( int), intsum_sq_digits(int) and void ishappy(). Also define a main function to create an object and call the methods to check for a happynumber.

32) A super class Detail has been defined to store the details of a customer. Define a sub class Bill to compute the monthly telephone charge of the customer as per the chart given below:

NUMBER OF CALLS RATE

1- 100 Only rental charge

Page 18: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

101-200 60 paisa per call + rental charge201-300 80 paisa per call + rental chargeAbove 300 1 rupee per call + rental charge

The details of both the classes are given below:

Class Name : Detail

Data membersname : to store the name of the customer. address : to store the address of the customer. telno : to store the phone number of the customer. rent : to store the monthly rental charge

Member functions: Detail(..) : parameterized constructor to assign values to data members. void show() : to display the detail of the customer.

Class Name : Bill

Data membersn : to store the number of calls. amt : to store the amount to be paid by the customer.

Member functions: Bill(..) : parameterized constructor to assign values to data Members of both classes and to initialize amt = 0.0. voidcal() : calculates the monthly telephone charge as per the charge given above. void show() : to display the detail of the customer and amount to be paid.

Specify the class Detail giving details of the constructor( ) and void show(). Using the concept of inheritance, specify the class Bill giving details of the constructor( ), void cal() and void show().

THE MAIN FUNCTION AND ALGORITHM NEED NOT BE WRITTEN.

33) Input a sentence from the user and count the number of times, the words “an” and “and” are present in the sentence. Design a class Frequency using the description given below:

Class name : Frequency

Data Members text : stores the sentence countand : to store the frequency of the word and. countan : to store the frequency of the word an. len : stores the length of the string. 4

Page 19: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

Member functions Frequency() : constructor to initialize the data variables. void accept(String n) : to assign n to text where the value of the parameter should be in lowercase. void checkandfreq() : to count the frequency of and. void checkanfreq() : to count the frequency of an. void display() : to display the frequency of “an” and “and” with suitable messages.

Specify class Frequency giving details of the constructor(), void accept(String), void checkand freq() and void display(). Also define the main function to create an object and call methods accordingly to enable the task.

34) A class DeciOct has been defined to convert a decimal number into its equivalent octal number. Some of the members of the class are given below: Class name : DeciOct

Data members n : stores the decimal number oct : stores the equivalent octal number

Member functions : DeciOct() : constructor to initialize the data members to 0 void getnum(int nn) : assigns nn to n void deci_oct() : calculates the octal equivalent of n and stores it in oct using the recursive technique void show() : displays the decimal number n calls the function deci_oct() and displays its octal equivalent

a) Specify the class DeciOct, giving details of the constructor(), void getnum(int), void deci_oct() and void show(). Also define a main function to create an object and call the functions accordingly to enable the task. b) State any two disadvantages of using recursion.

35) You are given a sequence of n integers, which are called pseudo arithmetic sequences ( sequences that are in arithmetic progression). Sequence of n integers : 2, 5, 6, 8, 9, 12

We observe that 2 + 12 = 5 + 9 = 6 +8 = 14

The sum of the above sequence can be calculated as 14 x 3 = 42 For sequence containing an odd number of elements the rule is to double the middle element, for example 2, 5, 7, 9, 12 = 2 +12 = 5 +9 = 7 +7 = 14

14 x 3 = 42 [middle element = 7]

A class pseudoarithmetic determines whether a given sequence is pseudo-arithmetic sequence. The details of the class are given below:- 5

Class name : Pseudoarithmetic

Data members n : to store the size of the sequence

Page 20: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

a[ ] : integer array to store the sequence of numbers ans, flag : to store the status sum : to store the sum of sequence of numbers r : to store the sum of 2 numbers

Member functions : Pseudoarithmetic( ) : default constructor void accept(int nn ) : to assign nn to n and to create an integer array. Fill in the elements of the array. boolean check( ) : return true if the sequence is a pseudo-arithmetic sequence otherwise return false.

Specify the class Pseudoarithmetic, giving details of the constructor(), void accept(int) and Boolean check(). Also define the main function to create an object and call methods accordingly to enable the task.

36) Write a program to declare a square matrix A[][] of order MXM where M is an positive integer and represents row and column. M should be greater than 2 and less than 10.Accept the value of M from user. Display an appropriate message for invalid input.Perform the following task:a) Display the original matrixb) Check if the given matrix is symmetric or not. If the element of the ith row and jth column is same s element of the jth row and ith column,.c)Find the sum of the left and right diagonal of the matrix and display them

Example 1:INPUT:M=31 2 32 4 53 5 6

OUTPUT:Original matrix1 2 32 4 53 5 6

Page 21: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

The given matrix is symmetricSum of the left diagonal=11Sum of the right diagonal=10

Example 2:INPUT: M=4OUTPUT:Original matrix:

7  8  9  24  5  6  38  5  3  17  6  4  2The given matrix is not symmetricSum of the left diagonal=17Sum of the right diagonal=20

Example 3:INPUT: M=12OUTPUT:Matrix size is out of range

37) Write a program to accept a sentence which may be terminated by either ',', '?' or '!' only.Any other character may be ignored. The words may be separated by more than one blank space and are in upper case.

Perform the following tasks:a) Accept the sentence and reduce all extra blank spaces between two words to a single blank space.b) Accept a word from the user which is a part of the sentence along with its position number and delete the word and display the sentence

Example 1:INPUT: A MORNING WALK IS A IS BLESSING FOR THE WHOLE DAY.WORD TO BE DELETED: ISWORD POSITION IN THE SENTENCE: 6OUTPUT: A MORNING WALK IS A BLESSING FOR THE WHOLE DAY.

Example 2:INPUT: AS YOU  SOW, SO SO YOU REAPWORD TO BE DELETED: SOWORD POSITION IN THE SENTENCE: 4OUTPUT:AS YOU SOW, SO YOU REAP

Example 3:INPUT: STUDY WELL ##OUTPUT:INVALID INPUT

Page 22: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

38)  A composite Magic number is a positive integer which is composite as well as a magic number.Composite number: A composite number is a number which has more than two factors. For example:10Factors are: 1, 2, 5, 10Magic number: A Magic number is a number in which the eventual sum of the digit is equal to 1.For example: 28 = 2+8=10= 1+0=1Accept two positive integers m and n, where m is less than n as user input. Display the number of composite magic integers that are in the range between m and n (both inclusive) and output them along with frequency, in the format specified below:

Example:Input: m=10n=100OUTPUT:The composite magic numbers are 10,28,46,55,64,82,91,100Frequency of composite magic numbers: 8

Input: m=120n=90OUTPUT:Invalid input

Page 23: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program

39) A company manufactures packing cartons in four sizes, i.e. cartons to accommodate 6 boxes, 12 boxes, 24 boxes and 48 boxes. Design a program to accept the number of boxes to be packed (N) by the user (maximum up to 1000 boxes) and display the break-up of the cartons used in descending order of capacity (i.e. preference should be given to the highest capacity available, and if boxes left are less than 6, an extra carton of capacity 6 should be used.)

Test your program with the following data and some random data:

Example 1

INPUT: N = 726

OUTPUT:

Remaining boxes

Total number of boxes

Total number of cartons

48 X l5 = 7206 X 1 = 6

0= 726

16

Example 2INPUT: N = 140

OUTPUT:48 X2 96

24 X 1 = 24

12 X I = 12

6 X 1 = 6

Remaining boxes 2 X I = 2 Total

number of boxes 140

Total number of cartons 6

INPUT: N = 4296OUTPUT: INVALID INPUT

Page 24: TASHI NAMGYAL ACADEMYtashinamgyalacademy.com/theme/file_repository/d95803a24... · Web viewSum of the digits of the factors (3 + 5 + 5 + (6 + 5 + 8 + 3 + 7)) = 42 Write a program