COMPUTER PROJECT

CLASS XI A

ANKUSH SINGH ROLL NO. 21 2/21/2011

INDEX
3. PROGRAMS AND THEIR OUTPUTS . ............................................................................................ 1. ARR_INT 2. ASCII 3. CALL_BY_REFERENCE 4. PALINDROM 5. NUMBER OF PALINDROMS.. 6. NUMBER OF 3s B/W 1 AND 1000. 7. DIVISION UNTIL n PLACES 8. TRIANGLE 1.. 9. TRIANGLE 2 10. TRIANGLE 3 11. TRIANGLE 4 12. FLYING BALLONS.. 13. SHOOTING BALOONS 14. SOUND 15. STRCAT 16. TEXTCOLO 17. MODULUS 18. MIDMAT 19. FIBONACCI 20. GUESS ME .. .. .. .. .. .. . . .. .. .. .. .. .. .. .. . . . . . . .. .. .. .. .. .. .. . . . . .. .. . . .. .

[Type text] ANKUSH SINGH

Page 2

Program - Elements of an Array #include<iostream.h> #include<conio.h> #include<math.h> // STEPS TO TAKE // 1. COUNT THE NUMBER OF DIGITS IN NO // 2. SPLIT THE NUMBER INTO CONSTIUENT DIGITS // 3. PUT THE SPLIT DIGITS IN ARRAY BY RETURNING IN LOOP // FUNCTIONS TO MAKE // 1. COUNT // 2. SPLIT N' ASSSEMBLE int lnth(int); int split(int,int); void main() { clrscr(); int no,len=0,arr[10]; cout<<"Enter a number:"; cin>>no; endl; len=lnth(no); cout<<"The length of number is:"<<len<<endl; for(int i=0,j=len;i<len,j>0;i++,j--) arr[i]=split(no,j); cout<<"\n\nThe elements of the array are:\n"; for(i=0;i<len;i++) cout<<arr[i]<<endl; getch(); } int lnth(int no) [Type text] ANKUSH SINGH Page 3

v2. v2=pow10(i-1). return splt. if((no%v1)==no) break. v1=pow10(i).v1. } int split(int no. } Output of Program Elements of an Array Enter a number:1234 The length of number is:4 The elements of the array are: 1 2 3 4 [Type text] ANKUSH SINGH Page 4 . splt=((no%v1)-(no%v2))/v2.{ int pwr=0.splt. } return pwr.int i) { int v1. while(1) { v1=pow10(pwr). else pwr++.

cin. else cout<<"For "<<a[j]<<"="<<i<<"\n". cout<<"Enter a String:".100).h> #include<conio.j++) { i=a[j].h> void main() { clrscr(). if(a[j]==' ') cout<<"For (space)="<<i<<"\n". char a[100].a[len]!='###BOT_TEXT###'. int i.ASCII #include<iostream.getline(a. for(int len=0.Program . } OUTPUT Enter a String: shubham roy The ASCII for the above Character(s) are: For s=115 For h=104 For u=117 For b=98 For h=104 For a=97 [Type text] ANKUSH SINGH Page 5 . cout<<"The ASCII for the above Character(s) are:\n\n".len++).j<len. } getch(). for(int j=0.

a1=&a.*a1.For m=109 For (space)=32 For r=114 For o=111 For y=121 Program .*a2. getch(). cout<<a1<<" \n"<<a2<<"\n\n".h> void swap(int &. //Pointing of Variables a2=&b. temp=x. x=y. void main() { clrscr().*a2. y=temp. } [Type text] ANKUSH SINGH Page 6 . //Decleration of Variables //Declaration of Pointers a=3. //Initialization b=7. //Pointing address of Function Variables a2=&y.int &).b. int *a1. cout<<a1<<" \n"<<a2<<"\n\n". cout<<"aftr swap()\n a="<<a<<" b= "<<b. a1=&x. int a. int &y) { int temp.h> #include<conio. } void swap(int &x. cout<<"swapped values\n a="<<x<<" b= "<<y<<"\n\n".b).Call by Reference #include<iostream. cout<<"original values:"<<a<<" "<<b<<"\n\n". swap(a.

len.j>=0.h> #include<string. else break.getline(str. for(len=0.h> void main() { char str[20].j--) { if(str[i]==str[j]) flag++. cin.j.str[len]!='###BOT_TEXT###'.Output of Program Call by Reference original values:3 7 0x8f86fff4 0x8f86fff2 swapped values a=7 b= 3 0x8f86fff4 0x8f86fff2 aftr swap() a=7 b= 3 Program .i++.i.i<len.Palindrome #include<iostream.j=len-1. int flag.h> #include<stdio.h> #include<conio.20). for(i=0.len++) {} flag=0. } if(flag==len) [Type text] ANKUSH SINGH Page 7 . cout<<"\nEnter a string:".

} Output of Program Palindrome Enter a string:roy no palindrom till:0 Enter a string:naman yes Enter a string:123421 no palindrom till:2 Program .cout<<"yes". COUNT THE NUMBER OF DIGITS IN NO // 2. SPLIT THE NUMBER INTO CONSTIUENT DIGITS // 3.h> // STEPS TO TAKE // 1.h> #include<math.int). PUT A LOOP TO ENTER DIGITS ONE BY ONE AND CHECK FOR PALINDROME // FUNCTIONS TO MAKE // 1. else { cout<<"no"<<"\n\npalindrom till:"<<flag. int split(int. COUNT // 2. void main() [Type text] ANKUSH SINGH Page 8 . } getch(). PUT THE SPLIT DIGITS IN ARRAY BY RETURNING IN LOOP // 4.Number of Palindromes #include<iostream. CHECK PALINDROM (IN MAIN) int lnth(int).h> #include<conio. SPLIT N' ASSSEMBLE // 3.

j--) arr[i]=split(no. while(1) { v1=pow10(pwr).i++. v1=pow10(i). if((no%v1)==no) break. } cout<<"\nThe number of palindrom numbers between 1 and 30000 are:".j=len-1. int no.i++. for(no=10.count=0.j>0.j>=0. } if(flag==len) count++.v1.j=len. } int lnth(int no) { int pwr=0.v2. else pwr++. for(int i=0. else break.i<len.len=0. } int split(int no.i<len.no++) { flag=0. [Type text] ANKUSH SINGH Page 9 .splt. cout<<count. } return pwr. len=lnth(no).no<=30000.arr[10]. for(i=0.flag. getch().{ clrscr().j--) { if(arr[i]==arr[j]) flag++.j).int i) { int v1.

l_limt.h> // STEPS TO TAKE // 1.h> #include<conio. COUNT // 2. SPLIT THE NUMBER INTO CONSTIUENT DIGITS // 3.int). cin>>u_limt. cout<<"\n\n\nEnter the lower limit:". RUN THE CHECK IN EACH ARRAY FOR PRESENCE OF ANY NUMBER // FUNCTIONS TO MAKE // 1.arr[10].h> #include<math. SPLIT N' ASSSEMBLE // 3. PUT THE SPLIT DIGITS IN ARRAY BY RETURNING IN LOOP // 4. cout<<"\n\nEnter the upper limit:". return splt. int no.v2=pow10(i-1). cin>>n.len=0. cout<<"\nEnter the number whose count you want in a range:". splt=((no%v1)-(no%v2))/v2. RUN THE TEST FOR PRESENCE OF n IN EACH ARRAY(IN MAIN) int lnth(int). cin>>l_limt.n. void main() { clrscr(). [Type text] ANKUSH SINGH Page 10 . COUNT THE NUMBER OF DIGITS IN NO // 2.count=0.Number of 3s #include<iostream. int split(int.u_limt. } Output of Program Number of Palindromes The number of palindrom numbers between 1 and 30000 are:389 Program .

j--) arr[i]=split(no. } return pwr. for(int i=0.no<=u_limt. getch(). } int split(int no.splt. } Output of Program Number of 3s Enter the number whose count you want in a range:3 [Type text] ANKUSH SINGH Page 11 .i++) { if(arr[i]==n) count++. v1=pow10(i). else pwr++. v2=pow10(i-1).no++) { len=lnth(no).j>0.j=len.int i) { int v1. } int lnth(int no) { int pwr=0.for(no=l_limt. return splt. while(1) { v1=pow10(pwr).j).i<len.i++.v2. for(i=0.v1. } } cout<<"\n\n\nThe number of "<<3<<"s in the given range are:"<<count. if((no%v1)==no) break. splt=((no%v1)-(no%v2))/v2.i<len.

cin>>n2. int n1. cout<<"\n\n"<<n1<<" is perfectly divisible by "<<n2<<endl. r1=r1*10. cin>>n.h> #include<conio. cout<<"\n\n"<<"Enter number to be divided:". cout<<endl<<"Enter the number of places you want to divide:". int n. else [Type text] ANKUSH SINGH Page 12 . r1=n1%n2.n2. cin>>n1.h> #include<process. cout<<endl<<"Enter number by which it has to be divided:". int r5.Enter the lower limit:10 Enter the upper limit:100 The number of 3s in the given range are:19 Program Division upto n places #include<iostream. if(r1==0) { cout<<"\n\nThe division of "<<n1<<" with "<<n2<<" gives: "<<n1/n2. if(n==0) { int r1.h> void main() { clrscr(). } else { if((r1/n2)>=5) cout<<(n1/n2)+1.

} else { cout<<n1/n2<<". for(int i=0. else cout<<r/n2. if((r5/n2)>=5) cout<<(r/n2)+1. else cout<<i<<" places of decimal".cout<<n1/n2. if(i==1) cout<<i<<" place of decimal". if(r==0) { cout<<"\n\nThe division of "<<n1<<" with "<<n2<<" gives: \n"<<n1/n2. break. } else { r=r*10. int r=n1%n2.i<n. cout<<"\n\n"<<n1<<" is perfectly divisible with "<<n2<<endl. if(r==0) { cout<<"\n\n"<<n1<<" is divisible by "<<n2<<" till:\n". } } else { cout<<"\n\nThe division upto "<<n<<" places is:\n".".i++) { r=r%n2. } else cout<<r/n2. } } } } [Type text] ANKUSH SINGH Page 13 . if(i==(n-1)) { r5=(r%n2)*10.

j<=i.h> void main() { clrscr().i<=5. } Output of Program Division upto n places The division upto 10 places is: 3.j++) { cout<<"*".3333333 Enter number to be divided:61 Enter number by which it has to be divided:9 Enter the number of places you want to divide:6 The division upto 6 places is: 6.h> #include<conio.getch(). } [Type text] ANKUSH SINGH Page 14 .25 13 is divisible by 4 till: 2 places of decimal Enter number to be divided:61 Enter number by which it has to be divided:3 Enter the number of places you want to divide:7 The division upto 7 places is: 20. for(int i=1.i++) { for(int j=1.777778 Programmes .Triangles #include<iostream. int m=9.

*** ****..k++) { cout<<"....j>=n.l<=i..for(int k=1..***** *********** #include<iostream.. } Output of Program Triangle 1 *. int m=1...k++) { cout<<".i<=5. } cout<<"***********".h> void main() { clrscr().h> #include<conio.. int n=1.**** *****...** ***.j--) { cout<<"*". for(int i=1. m-=2.k<=m. } for(int k=1...l++) { cout<<"*"..i++) { for(int j=5.". } for(int l=1. } [Type text] ANKUSH SINGH Page 15 .".k<=m... cout<<"***********"<<"\n"..* **... getch(). } cout<<"\n".

} for(int m=1.. } Output of Program Triangle 2 *********** *****.i<=5...*** **..l--) { cout<<"*".***** ****.h> void main() { clrscr().j<=k. l+=2.j++) { cout<<" "..h> #include<conio..m++) { cout<<"*". int k=4.for(int l=5...**** ***. m+=2..l>=n.** *.l=1.. for(int i=1.m<=l.. } k--. cout<<"\n". } getch().i++) { for(int j=1.. } n++. } [Type text] ANKUSH SINGH Page 16 .. cout<<"\n"..* #include<iostream.......

h> #include<conio.j++) { cout<<" ". k-=2.h> void main() { clrscr(). } Output of Program Triangle 3 * *** ***** ******* ********* #include<iostream.i++) { for(int j=1.l>=1.l--) { cout<<"*". } cout<<"\n".getch(). } getch(). int k=9.j<=i-1.i<=5. for(int i=1. } for(int l=k. } Output of Program Triangle 4 ********* ******* ***** *** * [Type text] ANKUSH SINGH Page 17 .

h> #include<stdlib.h> #include<graphics. i. xradius.y>=50. "C:\TC\BGI"). setfillstyle(1. delay(30).h> void main() { /* request autodetection */ int gdriver = EGA. /* initialize graphics and local variables */ initgraph(&gdriver. midy = getmaxy() / 2. midy. int midx. y. } [Type text] ANKUSH SINGH Page 18 . } getch(). midx = getmaxx() / 2. gmode=EGAHI. closegraph(). setcolor(4). for(int y=midy.Flying balloons #include<dos. yradius).4).h> #include<stdio.Program .y--) { fillellipse(midx. int xradius = 30.h> #include<conio. yradius = 40. if(y!=50) cleardevice(). &gmode.

h> #include<graphics.endxinc++) { setcolor(4).gmode=EGAHI. setcolor(1). yradius).60).60.endxinc.h> #include<conio.midy. yradius = 40.h> #include<stdio. if(endxinc==midx-30) break. &gmode.stxinc<=(midx+60). "C:\TC\BGI").endxinc<=(midx+150).endxinc=100. int xradius = 30.y>=50. } cleardevice(). delay(30).stxinc++. setbkcolor(2). fillellipse(midx.h> void main() { /* request autodetection */ int gdriver=EGA. midx = getmaxx() / 2. char msg[50]. /* initialize graphics and local variables */ initgraph(&gdriver. setfillstyle(1. [Type text] ANKUSH SINGH Page 19 .4). for(int y=midy+75.Shooting #include<dos.h> #include<stdlib. line(stxinc. int midx.stxinc=10. midy = getmaxy() / 2.Program . y. xradius. cleardevice().y-.

h> #include<iostream. delay(30).60).h> int main(int argc.CENTER_TEXT).60. char *argv[]) { unsigned int frequency = 0. delay(1000). getch().60. } for(stxinc=stx_temp.msg)." << endl. sprintf(msg.edx_temp. cout << "This program makes pc speaker sound at entered frequency.midy.midx+90. } cleardevice().stxinc++) { cleardevice(). outtextxy(midx.stx_temp++. closegraph(). line(stxinc.edx _temp++) { cleardevice().stx_temp<=midx.60.60). } Program SOUND #include<dos. for(stx_temp=stxinc."The baloon is popped!!!"..endxinc. settextjustify(CENTER_TEXT.midx).stxinc<=midx+90. delay(30). [Type text] ANKUSH SINGH Page 20 . do { cout << endl << "Enter in frequency (0 to exit) : ".edx_temp.int stx_temp. line(stxinc.60).edx_temp=endxinc. line(stx_temp.edx_temp<=midx+90.

. cin >> firstname. cout << "Enter in Middle name : ".h> #include<iostream.cin >> frequency. nosound(). Enter in frequency (0 to exit) : 1000 SOUND GENERATED Enter in frequency (0 to exit) : 2000 SOUND GENERATED Enter in frequency (0 to exit) : 100 Enter in frequency (0 to exit) : 0 SOUND GENERATED PROGRAM CLOSED Program STRCAT #include<string. char *argv[]) { char firstname[40]. middlename[40].h> int main(int argc.. cout << "This program concatenates strings to form 1 string. cin >> middlename. return 0. char fullname[120+1+1]. if (frequency > 0) sound(frequency). // 1+1 for spaces in between first middle and middle last." << endl.. [Type text] ANKUSH SINGH Page 21 . } Output of Program SOUND This program makes pc speaker sound at entered frequency. cout << "Enter in First name : ". lastname[40]. } while (frequency != 0).

cprintf("Hello World!!\n\r"). strcat(fullname. strcat(fullname.h> int main(int argc. middlename).cout << "Enter in Last name : ". char *argv[]) { int colors = 0. [Type text] ANKUSH SINGH Page 22 .. return 0. colors++) { textattr(colors). " "). cin >> lastname. strcat(fullname. lastname). strcat(fullname. for (colors = 0. // Initialize variable. " "). colors < 256. strcpy(fullname. } return 0.. Enter in First name : Shubham Enter in Middle name : Roy Enter in Last name : Bhatnagar Full name is "Shubham Roy Bhatnagar" Program TEXTCOLO #include<conio. firstname). ""). strcat(fullname. cout << endl << "Full name is ###BOT_TEXT###quot;" << fullname << "###BOT_TEXT###quot;" << endl. } Output OF Program STRCAT This program concatenates strings to form 1 string.h> #include<iostream.

} Output of Program TEXTCOLO Graphical Output cannot be shown [Type text] ANKUSH SINGH Page 23 .

cin>>n. ar[100]. for (i = 0. 2:-3 Element no. "<<i+1<<" of the array now is:".i<n&&a[i]!='###BOT_TEXT###'. of elements:". cout << ar[i] << endl. for (i=0. i<n&&ar[i]!='###BOT_TEXT###'. int i. } Output of Program MODULUS Enter the no. } } } void main() { clrscr().t.int n) { /*Programme to switch negative elements of an array to positive*/ int i=0.Program MODULUS #include <iostream.n. cout << "Enter array elements : ". a[i]=a[i]-(2*t). swap(ar. } ar[i]='###BOT_TEXT###'.h> void swap(int a[]. 1:-1 Enter element no. "<<i+1<<":". i++) { cout<<"\n Element no. cin >> ar[i]. i < n. cout<<"\n Enter the no. } getch(). 1 of the array now is:1 Element no. of elements:2 Enter array elements : Enter element no.i++) { if(a[i]<0) { t=a[i]. 2 of the array now is:3 [Type text] ANKUSH SINGH Page 24 . cout << endl.h> #include <conio. for(i=0.n). i++) { cout<<"\n Enter element no.

const N = 10. int col = c / 2.CPP // Function to display the elements which lie on middle of row and column #include <stdio. j<c. j++) { cin >> Array[i][j]. cout << "Enter total no. of rows: ". cin >> r. i<r. cin >> c. j<c. int r.h> #include <conio. cout << endl.h> const M = 10. // Finding the middle row cout << "Middle Row : ". } void main() { clrscr(). getch(). // Finding the middle column cout << "Middle Column : ". for(i=0. for(j=0. of columns: ". for(int j=0. int row = r / 2. cout << "\n\Enter the element in the array\n". j<c. cout << "Enter total no. } } else [Type text] ANKUSH SINGH Page 25 .Program MIDMAT // Filename: \U2Chap09\ch09_217. int Array[M][N]. int i. j++) cout << Array[row][j] << " ". int r. void display_RowCol(int Array[M][N]. int c) { clrscr(). j++) cout << Array[j][col] << " ". c. j.h> #include <iostream. i++) for(j=0. // Array to be a square matrix with odd dimension if ((r == c) && ((r%2==1) && (c%2==1))) { cout << "Input steps".

of rows: 3 Enter total no. of columns: 3 Input steps Enter the element in the array 1 2 3 4 5 6 7 8 9 Middle Row : 4 5 6 Middle Column : 2 5 8 [Type text] ANKUSH SINGH Page 26 . } display_RowCol(Array. r. getch().{ cout << "Input row and column not valid". } Output of Program MIDMAT Enter total no. return. c).

CPP // Program to generate a series #include<iostream. cout << "\n" << c.h> class Fabonnaci { int a. i++. cout << "\n" << b. b. N = 20. }. fab. } } }.display(). i. a = b. void main() { Fabonnaci fab.Program FABONACI // Filename: \U1Chap05\ch05_403. b = c. c. } void display() { cout << "\n" << a. i = 2. while(i<N) { c = a+ b. b = 1. public: Fabonnaci() { a = 1. N. Output of Program FABONACI 1 1 2 3 5 8 [Type text] ANKUSH SINGH Page 27 .

char guesschar..h> #include<iostream. void GenerateChar(void) { randomize().13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 Program GUESSME #include<stdlib. [Type text] ANKUSH SINGH Page 28 . // from ascii code of 'a' to ascii code of 'z' as 26 chars are available from a to z. mychar = 'a' + random(26). } int GetAndCheckGuess(int guessno) { cout << endl << "Try #" << (guessno+1) << " : ". cin >> guesschar.h> class MyChar { private: char mychar.

void Start(int nturns) { GenerateChar(). return 0." << endl << endl. int main(int argc. break." << endl << "Anyway. } [Type text] ANKUSH SINGH Page 29 . i should have known that my choice is tough for kids.. return 0. i chose

" << mychar << "
".. guess1. char *argv[]) { MyChar guess1. } public: // nturns -> No.. i++) { if (GetAndCheckGuess(i) == 1) { cout << "Wah... else cout << "My char is slightly to right.Start(5). i < nturns.. if (((int)mychar .".. cout << "My character is from lower case alphabets.." << endl.if (guesschar == mychar) return 1. // 5 guesses allowed. } } if (i == nturns) cout << "Nevermind. your intutions are really strong. for (int i = 0.". of turns to give to user.(int)guesschar) < 0) cout << "My char is slightly to the left. } }.

. ********* ****** *** [Type text] ANKUSH SINGH Page 30 . Try #2 : u My char is slightly to right.Output of Program GUESSME Try #1 : s My char is slightly to right. Try #5 : x Wah. Try #4 : y My char is slightly to the left... your intutions are really strong. Try #3 : w My char is slightly to right....