You are on page 1of 34

MANESH SIR

UTKARS
H AGARWAL

XI – A1

1
This project could not be
completed without thanking those who encouraged
us and put up with our revisions and updating of
the project with patience and tolerance and this
endeavor has prepared us to take more innovative
and challenging projects in future.
First of all our sincere thanks
goes to our principal Mrs. Grace Jose who provided
us this opportunity.
After that our sincere thanks
goes to our computer teacher Mr. Manesh Sir who
provided us his guidance by which we will able to
make this project .
Finally we thank to all the noticed and unnoticed
thanks hand behind the project.

2
This is to certify that Utkarsh agarwal of
class XI – A1 has submitted the computer project
on c++. He has taken proper care shown utmost
sincerity in completion of this project.
I certify that this project is up to my
expectation and as per the guidelines issued by
CBSE.
I am fully satisfied with the project report.

3
Mr. Manesh sir
Mrs. Grace jose
Computer teacher
Principal

SR.N PROGRAMS PAGE


O. NO.
1 TO DISPLAY THE GIVEN STRUCTURE 5
2 TO DISPLAY THE GIVEN STRUCTURE 7
3 TO DISPLAY THE GIVEN STRUCTURE 9
4 IN A LINE TOTAL SMALL,LARGE 10
ALPHABETS,SPECIAL CHARACTER,ETC
5 TOTAL WORDS IN A LINE 12
6 TO REVERSE THE GIVEN STRING WORD BY WORD 13
7 TO WRITE THE INITIALS OF NAME WITH FULL SIR 15
NAME
8 FIBONACCI SERIES OF TWO 16
9 FIBONACCI SERIES OF THREE 17
10 ARMSTRONG NO FROM 1 TO 200000 18
11 PRIME NO FROM 1 TO 1000 19
12 FACTORIAL USING RECURSIVE FUNCTION 20
13 TO FIND SUM OF DIGITS,PRODUCT OF 21
DIGITS,REVERSE OF NO
14 SUM OF EACH ROW & EACH COLUMN 22
15 TRANSPOSE THE GIVEN ARRAY 23
16 OVERLOADING A FUNCTION 25
17 PASSING SRUCTURE TO A FUNCTION 27
18 STRUCTURE & SORTING 29
19 SELECTION SORT 31
20 INSERTION SORT 33

4
Q1. DRAW THE FOLLOWING STRUCTURE:-

121

12321

1234321

123454321

A.# include<iostream.h>

# include<conio.h>

void main()

clrscr();

int i,j;

for(i=1;i<=5;i++)

cout<<endl;

for(j=1;j<=5-i;j++)

5
{

cout<<" ";

for(j=1;j<=i;j++)

cout<<j;

for(j=i-1;j>=1;j--)

cout<<j;

getch();

6
Q2. DRAW THE FOLLOWING STRUCTURE:-

AB

ABC

ABCD

ABCDE

A.# include<iostream.h>

# include<conio.h>

void main()

clrscr();

char i,j;

int p=4,k;

for(i='A';i<='E';i++)

cout<<endl;

for(k=1;k<=p;k++)

7
cout<<" ";

for(j='A';j<=i;j++)

cout<<j<<" ";

for(j=i-1;j>='A';j--)

cout<<j<<" ";

p--;

getch();

8
Q3. DRAW THE FOLLOWING STRUCTURE:-

$ $

$ $

$ $

$ $

$$$$$

A.# include<iostream.h>

# include<conio.h>

void main()

clrscr();

int i,j;

for(i=1;i<=5;i++)

cout<<endl;

for(j=1;j<=i;j++)

if (j==1||j==i||i==5)

cout<<"$"<<" ";

9
else

cout<<" ";

} getch(); }

Q4. WAP IN C++TO ACCEPT A LINE OF STRING FROM THE USER &
DISPLAY TOTAL CAPITAL ALPHABETS , TOTAL SMALL ALPHABETS ,
TOTAL DIGITS , TOTAL SPACES , TOTAL SPECIAL CHARACTERS FROM
THE GIVEN STRING .

A.# include<iostream.h>

# include<conio.h>

# include<stdio.h>

void main()

clrscr();

char str[100];

cout<<"\n enter a line";

gets(str);

int cl=0,sl=0,dg=0,sp=0,sch=0,i=0;

while(str[i]!='\0')

if(str[i]>=65 && str[i]<=90)

cl++;

else if(str[i]>='a' && str[i]<='z')

sl++;

else if(str[i]>='0' && str[i]<='9')

dg++;

10
else if(str[i]==' ')

sp++;

else

sch++;

i++;

cout<<cl<<" "<<sl<<" "<<dg<<" "<<sp<<" "<<sch;

getch();

11
Q5.WAP IN C++ TO ENTER A LINE FROM THE USER & DISPLAY TOTAL
WORDS IN THAT LINE.

A.# include<iostream.h>

# include<conio.h>

# include<stdio.h>

void main()

clrscr();

char ln[100];

cout<<"\n enter a line";

gets(ln);

int i=0,ct=0;

while(ln[i]!='\0')

if(ln[i]==' ')

ct++;

i++;

cout<<"\n total words"<<ct+1;

getch();

12
Q6. WAP IN C++ TO ACCEPT A STRING FROM THE USER AND CHANGE
IT TO:-

INPUT:- I AM A GOOD BOY

OUTPUT:- BOY GOOD A AM I

A.# include<iostream.h>

# include<conio.h>

# include<stdio.h>

void main()

clrscr();

char str1[100],str2[20],t;

cout<<"\n enter a sentence"<<endl;

gets(str1);

int i,j,lst,k;

for(i=0;str1[i]!='\0';i++);

i--;

while(i>=0)

j=0;

while(str1[i]!=' ' && i>=0)

str2[j]=str1[i];

13
j++;

i--;

str2[j]='\0';

lst=j-1;

k=0;

while(k<j/2)

t=str2[k];

str2[k]=str2[lst];

str2[lst]=t;

k++;

lst--;

cout<<str2<<" ";

i--;

getch();

14
Q7. WAP TO WRITE THR INITIALS OF NAME WITH ITS FULL SIRNAME.

A.# include<iostream.h>

# include<conio.h>

# include<stdio.h>

void main()

clrscr();

char nm[30];

gets(nm);

for(int l=0;nm[l]!='\0';l++);

for(int p=l-1;nm[p]!=' ';p--);

cout<<nm[0]<<".";

for(int i=1;i<p;i++)

if(nm[i]==' ')

cout<<nm[i+1]<<".";

for(i=p+1;nm[i]!='\0';i++)

cout<<nm[i];

getch();

15
Q8. WAP IN C++ TO GENERATE THE FOLLOWING SERIES:-

0 1 1 2 3 5 8 ------------------100.

A.#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a=0,b=1,c;

cout<<a<<b;

c=a+b;

while(c<=100)

cout<<c;

a=b;

b=c;

c=a+b;

getch();

16
Q9. WAP IN C++ TO GENERATE THE FOLLOWING SERIES:-

0 1 1 2 4 7 13 ---------------100.

A.#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a=0,b=1,c=1,d;

cout<<a<<b<<c;

d=a+b+c;

while(d<=100)

cout<<d;

a=b;

b=c;

c=d;

d=a+b+c;

getch();

17
Q10. WAP TO DISPLAY ALL THE ARMSTRONG NO.S FROM 1 TO
200000.

A. # include<iostream.h>

# include<conio.h>

void main()

clrscr();

long int s,r,p,n;

for(n=1;n<=200000;n++)

p=n;

s=0;

while(p>0)

r=p%10;

s=s+r*r*r;

p=p/10;

if (s==n)

cout<<n<<endl;

getch();

18
Q11. WAP IN C++ TO DISPLAY ALL PRIME NO.S FROM 1 TO 1000.

A. # include<iostream.h>

# include<conio.h>

void main()

clrscr();

int n,i,ct;

for(i=1;i<=1000;i++)

ct=0;

for(n=1;n<=i/2;n++)

if (i%n==0)

ct++;

if (ct==1)

cout<<i<<" ";

getch();

19
Q12. A RECURSIVE FUNCTION FACT ACCEPTS A NO. AS PARAMETER
& RETURN ITS FACTORIAL. WAP IN C++ TO ACCEPT A NO. & DISPLAY
ITS FACTORIAL.

A.# include<iostream.h>

# include<conio.h>

int fact(int);

void main()

int n,s;

cout<<"\n enter a no.";

cin>>n;

s=fact(n);

cout<<"\n factorial is"<<s;

getch();

int fact(int x)

if(x>1)

return x*fact(x-1);

else

return 1;

20
Q13. WAP IN C++ TO ACCEPT A NO. & DISPLAY SUM OF
DIGITS,PRODUCT OF DIGITS & REVERSE OF NO.

A.#include<iostream.h>

#include<conio.h>

void main()

int n,r,s=0,x=0,y=1;

cout<<"\n enter a no.";

cin>>n;

while(n>0)

r=n%10;

s=s+r;

x=x*10 + r;

y=y*r;

n=n/10;

cout<<"\n sum is"<<s;

cout<<"\n reverse is"<<x;

cout<<"\n product of digits"<<y;

getch();

Q14. AN ARRAY OF 4 ROWS & 4 COLUMNS CONTAIN INTEGER VALUE.


WAP IN C++ TO DISPLAY SUM OF EACH ROW & EACH COLUMN.

21
A.# include<iostream.h>

# include<conio.h>

void main()

clrscr();

int a[4][4],i,j,sumr,sumc;

for(i=0;i<4;i++)

for(j=0;j<4;j++)

cin>>a[i][j];

for(i=0;i<4;i++)

sumc=sumr=0;

for(j=0;j<4;j++)

sumr=sumr+a[i][j];

sumc=sumc+a[j][i];

cout<<endl<<"sum of"<<i<<"row is"<<sumr;

cout<<endl<<"sum of"<<i<<"column is"<<sumc;

} getch(); }

Q15. AN ARRAY OF 4 ROWS & 4 COLUMNS CONTAIN NUMERIC


ELEMENTS. WAP IN C++ TO TRANPOSED THE GIVEN ARRAY.

A.# include<iostream.h>

22
# include<conio.h>

void main()

clrscr();

int a[4][4],i,j,t;

for(i=0;i<4;i++)

for(j=0;j<4;j++)

cin>>a[i][j];

for(i=0;i<3;i++)

for(j=i+1;j<4;j++)

t=a[i][j];

a[i][j]=a[j][i];

a[j][i]=t;

cout<<"\n transposed array";

for(i=0;i<4;i++)

cout<<"\n";

for(j=0;j<4;j++)

23
cout<<a[i][j]<<" ";

getch();

Q16. A UDF MYFUNC WHEN PASSED A SINGLE INTEGER PARAMETER


RETURNS ITS CUBE. WHEN THE SAME FUNCTION IS PASSED TWO
PARAMETER WHICH ARE INTEGERS, RETURNS THEIR SUM. IF 3
INTEGER PARAMETERS ARE PASSED TO THE SAME FUNCTION THEN
IT RETURNS THEIR AVERAGE. WAP IN C++ TO INVOKE ALL THE 3
FORMS OF THE MTFUNC().

A.# include<iostream.h>

24
# include<conio.h>

int myfun(int x)

return(x*x*x);

int myfun(int x,int y)

return(x+y);

float myfun(float x,float y,float z)

return((x+y+z)/3);

void main()

clrscr();

int a,b;

float c;

a=myfun(4);

b=myfun(4,7);

c=myfun(4,5,11);

cout<<a<<" "<<b<<" "<<c;

getch();

25
Q17. A UDF ACCEPTS TWO SET OF DISTANCES IN FEET & INCHES
THROUGH OBJECT OF STRUCTURE DISTANCE IN FEET & INCHES AND
DISPLAY THE TOTAL DISTANCE IN FEET & INCHES. WAP TO SO.

A.#include<iostream.h>

#include<conio.h>

struct dist

26
int feet;

int inches;

};

void totdist(dist,dist);

void main()

clrscr();

dist a,b;

cin>>a.feet>>a.inches;

cin>>b.feet>>b.inches;

totdist(a,b);

getch();

void totdist(dist x, dist y)

dist z;

z.feet=x.feet + y.feet;

z.inches=x.inches + y.inches;

if(z.inches>=12)

z.feet=z.feet + z.feet/12;

z.inches=z.inches%12;

cout<<z.feet<<" "<<z.inches;

27
Q18. WAP IN C++ TO ACCEPT DETAILS OF ‘N’ STUDENTS FROM THE
USER USING ARRAY OF STRUCTURE SUCH AS ROOL NO. , NAME ,
TERM , %. SORT THE RECORDS TO REARRANGE THEM IN
DESCENDING ORDER OF % USING BUBBLE SORT TECHNIQUE.

A.#include<iostream.h>

#include<conio.h>

#include<stdio.h>

struct stud

28
int rn;

char nm[15];

char term[15];

float per;

};

void main()

stud s[50],t;

int n,i,j;

cout<<"\n enter no. of records to enter";

cin>>n;

for(i=0;i<n;i++)

cin>>s[i].rn;

gets(s[i].nm);

gets(s[i].term);

cin>>s[i].per;

for(i=0;i<n-1;i++)

for(j=n-1;j>i;j--)

if(s[j].per>s[j-1].per)

t=s[j];

29
s[j]=s[j-1];

s[j-1]=t;

cout<<"\n sorted";

for(i=0;i<n;i++)

cout<<"\n"<<s[i].rn<<" "<<s[i].nm<<" "<<s[i].term<<"


"<<s[i].per;

getch();

Q19. WAP IN C++ TO ACCEPT ‘N’ NO.S FROM THE USER IN AN


ARRAY. SORT THE ARRAY ELEMENTS IN DESCENDING ORDER USING
THE SELECTION SORT TECHNIQUE.

A.# include<iostream.h>

# include<conio.h>

void main()

clrscr();

int a[100],n,i,p,max,j,t;

30
cout<<"\n size";

cin>>n;

for(i=0;i<n;i++)

cin>>a[i];

for(i=0;i<n-1;i++)

max=a[i];

p=i;

for(j=i+1;j<n;j++)

if(a[j]>max)

max=a[j];

p=j;

t=a[i];

a[i]=a[p];

a[p]=t;

for(i=0;i<n;i++)

cout<<endl<<a[i];

getch();

31
Q20. WAP IN C++ TO ACCEPT THE SIZE OF ARRAY & SORT THEM
USING INSERTION SORT TECHNIQUE.

A.# include<iostream.h>

# include<conio.h>

void main()

clrscr();

int a[100],i,num,n;

cout<<"size";

cin>>n;

32
for(i=0;i<n;i++)

cin>>a[i];

for(i=1;i<n;i++)

num=a[i];

for(int j=i-1;j>=0;j--)

if(a[j]>num)

a[j+1]=a[j];

else

break;

a[j+1]=num;

for(i=0;i<n;i++)

cout<<endl<<a[i];

getch();

33
34

You might also like