0% found this document useful (0 votes)
216 views

Computer Programs Class 12 Computer Science 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
216 views

Computer Programs Class 12 Computer Science 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 58
and call 4,Yee ae Explanation: Input number : 14 The digits are 1 and 4 formed by 1 and 4 ate (i) 197 is a Keith Number Input Number » 19; The digits are 1, 9 and 7 Tribonacei series formed by 1, 9 and 7 1, 9, 7, 17, 33, 57, 107, 197, (ai) Input-Number % Output Nota Keith Number} Write a program in Java to enter a natural @ natural number, where Ni tere N>100 and N=1000, th pee * natural numb 8: Print all the combinations of di fumber including the number itself, Each a se “vad Nar a Prato ample Input: Enter a number: 465 sample Output: 456 465 546 564 65 ost Sample Input: Enter a number: -712 Sample Output: Invalid Number Sample Input: Enter a number: 960 Sample Output: Invalid Number A triangular number is formed by the addition of consecutive integers starting: must not contain 761 Y combination should ap ‘ with 1 For example, 14+2=3 14+2+3=6 14+2+3+4=10 1424+34+44+5=15 are triangular numbers. Java to display all the triangular numbers from 3 t0 n, taking the Thus, 3, 6, 10, 15, .. Write a program in value of n as an input. Prog. 7: A Smith number is a composite number, whose sum of the digits is equal to the sum of its prime factors. For example: 4,22, 27, 58, 85, 94, 121 Write a program in Java to enter or not. Sample Input: 666 Sum of the digits: 6 + 6 + 6 = 18 Prime factors are: 2, 3, 3, 37 @ Sum of the digits of the prime factors: geata+G+nee Thus, 666 is a Smith Number. are Smith numbers. ‘a number and check whether it is a ‘Smith number a oe Statements and Scope5408) B J a r he EXPT en programs based on sing), gle tat ac N Of the fot ste @ POBFAM tO INUE and store w ing, | POUbIe D} int each number with its freq? Bers (y Arora tency in two different columng ™°Y: The outpen 2 Sele subs al Arrays Sample Input: should conan Pte variable in number ana and pelle ‘sample Output: GET {ey ‘Number Frequency 12 4 14 3 16 2 18 2 20 3 2 Write a program to accept a set of n int Bites rer 1 crt» tof nage (hon > e ae array, next lower number in the Teen the let cel pits centre and so on... . The process will stop wh ‘number wll be set in its appropriate cell. Finally, display the arty clara, “Assume that the memory space is less. Hence, you anomie aes : need to create extra array "Example: ‘Pr0g: , ina single dimensional jest number appears in the f the centre, next lower in Sie un, cea: 4 lee 31 145 ie it 1d og. 3: A bank intends to design a program to display the denomination of an input amount, to 5 digits. The available denominations with the bank are of rupees 2000, 500, 200, 100, 50, 20, 10 and 1. ign a program to accept the amount from the user and display the break-up in ending order of denominations. (ie., preference should be given to the highest Nomination available) along with the total number of notes ate: Only the denomination used should be displayed]. Also print ds according to the digits. the amount in eeRriei2 *106 ining boxes= 2° T= 2 ematiymber of Boxes: 140 set Camber oF cartones mpl yon a square matrix M1 {of ,, # GN reept thre different charnaye Mer 10. Saput shown from the Id be les. TF the 9 ; gecond Ch sind Character “# ‘Output: 3 2H? pee? Soe prample 2 Enter Size: 5 nput: First Character ‘$" ‘Output: Size out of Range fap? The result of a quiz competition is to be prepared as follows The quiz has five questions with multiple choices (A, B, C, D) with each question samying 1 mark for the correct answer. Design a program to accept the number of Participants N such that N must be greater than 3 and less than 1. Create a double dimensional array of size (N x 5) to store the answers of each participant rowswise, ‘Galoulate the marks of each participant by matching the correct answer stored in. 2 single dimensional array of size 5. Display the score of each participant and the Participant(s) having the highest score. lsc 2016) Example: If the value of N = 4 then the array would be: Participants Participant? =| = A Participant 2eats Lower THangular 5 Program in Java to input et 6 Salar Matrix oF not aa! 2 Ratt: A SCALA mate is g iia. se Matis is Scalar sre matrix is the matrix in why, - ih numb Pek a matrix of order n’n is called a Squeet Of equa Foe a program in Java to create a double gry at MmMber of co MAF the numbers in a cicular fashion (anne OA : on (ant oa aay of ie $5 retaking nas an input. The fi mag ing of the elomarr for example, if n=4, then n? an tart from outer 6, then the array is fi he is filled as; st Asquare matrix i the matrix in which number of rows has a matrix of order n‘n is called a Square Mate. Write a program in Java to create a double dimensic ocr sional array of size nxn ma SS eeipeaniiemmme fom 1 to n®, taking n as an input. Input n should be an odd number and fi ling, the elements should start from the central cell. $ For example, if n=5, then n?=25, then the array is filled as: (121 3 | 20 fe 3 [9 | 10) hw 6 Lotty 2, ye ‘ 18 [L541 4 i ae zeros? ype A rouble dimensional array of size nxn ‘matrix form jion (anticlock- wise) ‘with natural numbers from: -quals the number of columns. ‘agit: Write a program in Java create a di ‘and fill the numbers in a circular fashi 1 to 1?, as illustrated below: example, if n=5, then n?=25, then the array is filled as:: i BETA (0 create ap eu, te, orresponding! ce te Powe co shy: Disp ns Sample Input PY the [ss [33 [26 | a [si] 86 | a1 | 10 tat e417) a2 ole {4 0 [22 [4 | 23 | a5 Dy proeram in Tava t0 store the Gente Uhimnatr form) Avand Boe "™Nt5 in yy preaye and store the result in mamiy cf order 4 "4° ilforent mat KC. Display the fit the le dimen luce tonal f both the x can be multiplied only if the numb Mere s of Patino number Of OWS of the second mains. °f MMS of the ‘tat ada Sample Input: Matrix 4 Samp Ple Input: Matri =] trix B 6 | 3 [23] a7 (@) Write a program to declare a square matrix A [ ] [] of order N (N=cosx >=0). a giving details of the constructor ouble cos(), double sec() only. You do not newta ase SoH the array Display a asa Collection ivin, ego) 4 Bens. Do no erie the ete ot Nas Been eine yi), ee Modity averwinstance variables perme Stores a st ven To store tony ctions/method. math giver funeti dO To ac od TD ACCePL the stein ord Manin, char) ea paint f Isplay the chan axeout(int) To reme pont We a chy and disy play thy To replace each For example, 88 distan ABCD” becom sciy the olass Modify giving details of the ny wel). The main) fuinetion need sony anspose of an array is obtained by interchang at a Ahan Transarray contains a two dimension aN Aije possible for both ‘m’ and ‘n’ is 20, Design a ca rear aa spiieiven matrix. The details of the members of maaeiree sans ees w class are given below ‘pata membersfinstant variables: arf I) Stores the matrix elements, Integer to store number of columns. ange oid AN ing the elements of r - Ale a ‘Member functions/methods: + Default constructor. Transarray() ronsarray(int mm, int nn): To initialize the size of the matrix, m=mm, n=nn To enter elements of the matrix. void fillarray() void transpose To find transpose of a given matrix. (lransarray A) ‘oid disparray() : Display the array in t Specify the class Transarray giving details of the Iranspose(Transarray) and void disparray(). You need not wie Il: A class SortWord has been defined with the following details: : SortWord the matrix form. constructors, void fillarray(), veil the main function, Class name Data members/instance variables: pt + Stores the word. en Stores the length of the word er functions/methods: per Word Default constructor : 1 vord in lower €28e: peal + To accept the word in id oa. 1 tr che word in alphabeial am of characters wing Bubble sort technique and display it User Defined ‘and Constructors Class asaiass FiboString to gency, Pee Sbon,, =. oct iscein, ie a piston variabeg, OF the en . ton bers ms BR: ; 10 store (ne BE string : ESS i tanetions/methoas mber of yt the previ wera) constr ey cae ane rictor to ree) #9 accept the magi X=" von erate) Catanete and pce frm ye M2 string. Ey eration) bona st “ Rec. iS fi got AT ta tS: The sun rte FOO Ml be ps NE a the ty Bi iy the class FibOString, giving dota th will be “mpeg the seperate). Define the main Pas the constructor, % cost gy f enable the task Yo create an gone YOid accep) : contains a two dime ind el the function : xalecames the last the second row hegyree nf shulfe the nae Maxims ‘jer of the cass are Bien belo the fist and so ony The: the fir mee Name : Shift he details of te bers/instance variables: pata mem! mat [Jl] Stores the array element {integer to store the number of roy : 2 ei + integer to store the nu ec. number of columns “a sain(int mm, int nn) ——_: parameterized constructor to in members m=mm and n=nn aoe ot void input ) + enters the elements of the array oid eyclic(Shift P) + enables the matrix of the object P to shift each "upwards in a eyclic manner and store the elont matrix in the current object. void display( ) displays the matrix elements Specify the class Shift giving details of the constructor(), void input( ), void cyclic (Shift). Define the main function to create an object and call the methods accordingly fo enable the task of shifting the array elements. {USC 2016) 42h Aclass consChange has been defined with the following, details: Class name : ConsChange Data Members/instance variables: : stores the word word 4 len + stores the length of the word _ Member functions/methods: - ConsChange( ) - default constructor 7 _Yeidreadivond ) : stores word = oid shiftcons( ) «chile al the consonants ofthe word att BERN ; ervels (eg Spoon becomes SPR) followed by the v‘ Void changeword{ +: changes the case of a C shifted word to uppercase SPNoo). 1 occurring consonants of the for eg. Spnoo becomes“eames BEN tn afar etter oF OLS sty, eye mverMbOrs OF the clay iohi Se ke Capital“ Sven Sins taefinstance variate. an 10 store « torent x tunstionsfmethods: queny m0 detaut a Bet euang wy eet CoM I RapAStNg 9): heck be ph Totten othe ty sasplay) aisplays the sen fala ne Words be, . esate es Cantal wing i aang) and Void digplay() scart tnetions accordingly to ty ‘Aitving with etine th able the phe 8 saclass Convert tofind anal the Tiday numberiso4 and theyre em aBivond DMarch @, aba *2020, then the sown of the members of the Rance rca me ane ‘y Convert rt) gmembers/Instance variables: integer to store th Ber to store the day mum integer to store the day enh" InteReE to ata BY OF te monday é integer to store the year ethods/Member function a : constructor to initial jalize the data me oa accept . ae en serg day. to-date converts the date number to ite oy ? particular year and stores the date ind eo Bak OE 8 gpaify the class Convert giving details of the constrctot eet ord day. to_date( ) and void display(). Define a mai erctort aatold. accept): ( d display( ). Define a main() funet wid call the function accordingly to enable the task ee ane s Bien belo be below t pata Ba intial values #5, Adass Mix has been defined to mix two words, character by character, the fl y characte, inthe following manner: The first character of the first word is followed by the first character of the second word and so on. If the words are of different length, the remaining characters of the word are put at the end. Example: If the First word is “JUMP” and the second word is "STROLL", then the required word will be “JSUTMRPOLL” ome of the members of the class are given below: Class name : Mix wrd + to store a word Jen the length of the word "Member function/methods: ix( ) void feedword( ) jd mix_word(Mix P.Mix Q) : to store ze the data embers with ult constructor to initial Tegal intial VOIUES oa cage ‘accept the word in ‘ure BR case fsa words of objec P and ane above a and stores the resultant wont in the cut ; n he id display( ) splays the word ify the class Mix giving te eal te 0 mix_word(MixyMix) and vole ON 0 0 and call the functions accor! + defaes =yg ener Absries( ) the cass Recursion «, 0) Pee sbseries( ) You ey myo. YOU Need Not rey, 2 BME Rincon, 2° toy, woney I into 4) (gus ReeFact defines @ recurs” fais of the €lA88 are given Keiyn® “Wnetion , apne Ww ss f + Reg pate members/instance variaire, Reckact n r syember functions/methods secFact() oid reacimum( ) int factorial(int) void factseries( ) Spealy the class RecFact givin, oid readnum(), int factorial(int) to create an object and call + integer as number n ti integer as number of terms of series. P + integer to store power of ‘x + integer to store factorial constructor to store appropriate values to data members. : to accept integer n (as number of terms) and x. : to find and return g raised to the power h u the Recursive Technique. + to find and return factorial of y using Technique. Y : to find and return sum of ab 3 recursive functions getpo y the class MySeries giving details of constructor and th nt h), int findFact (int y) and long findsum( ). ; for you. Do not write the main function. ct has been defined to find the “HF js used to find the LCM en below: aay 7? ig TU Ae el ealrember functinsmethode Constructor to init DeciOt with 0. Assigns nn to n. “ Caleutates the octal equivatens gy fot sity the recursive technige" isplays the decimal 1 voit show) deel oet() and displays aciOet, giving details of the constructor, voig H Oe 6 Sethe Saal fine a IND Fenton to any Vos ens? Sage taaonescon 10 he "i pra g he mem can piu isdvantages of ung ection, Fone ae Prog. TA eres fe equal 10 Bote pata Saw Example: 28 = 22+ 82-4 + 64 = 68 4 oa ibe 68 = 6 + 8 = 36 + 64 = 100 metho 1) 10-1 +04 02=14040=1 perfect Hence, 28 is a happy number: of facto Example: 12 = 12+ 2=144=5 int SUES Hence, 12 is not a happy number. g check) pesign a class Happy to check if a given number is a happy numbers, voi ambers of the class are given below: me of Class name Happy : Data members/instance variables: fy the A “4 Eee eter pe yoid. chet Member functions: accordingly iacsyb) + Constructor to assign 0 ton. 4: Design 2 os void getnum(int nn) 5 ig ae Parametric value to the ny some of the (n = nn). e Class nam« int sum_sq_digits(int x) + Retums the sum of the square of the digis of ‘Data memb number x, using the recursive technique. art{ } void ishappy() : Checks if the given number is a happy ny n by calling the function sum sq digit, Member £ displays an appropriate messages. } Binsearch( Specify the class Happy giving details of the constructor(), void getrumint) ins void fillar 5q_ digits(int) and void ishappy(). Also define a main() function to create an aj void sort and call the methods to check the happy number. Prog. 12: An emirp number is a number which is prime backwards and forwards. ¢: 3 int bins 31 are both prime numbers. Thus, 13 is an emirp number. Design a class Fnitp check if a given number is Emirp number or not. Some of the members o! the are given below: Define t Class name : Emirp and int Data members/instance variables: a n : stores the number rev : stores the reversed number f : stores the divisor Member functions: eep(nt an): : to assign n=nn, rev=0 and f-2 int asprime( int x) + checks if the number is prime using the technique and returns 1 if prime othere " we re ee resuh dass BMIP giving der . co he), Define the matty D Fa OF the “PPro, ste Emixp number, SP RHON tg OPStr icy, nN jggs Perfect to check os ° give

You might also like