Top Banner
PROJECT [Type the abstract of the document here. The abstract is typically a short summary of the contents of the document. Type the abstract of the document here. The abstract is typically a short summary of the contents of the document.] C++ ADITYA SIR UTKARSH KUMAR
52

project - Magadh University

Dec 18, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: project - Magadh University

PROJECT

[Type the abstract of the document here. The abstract is typically a short

summary of the contents of the document. Type the abstract of the

document here. The abstract is typically a short summary of the contents

of the document.]

C++

ADITYA SIR

UTKARSH KUMAR

Page 2: project - Magadh University

S.NO. QUESTION PAGE NO.

1. Write a program to print your name? 2

2. Write a program to add two numbers? 3

3. Write a program to accept p r t and calculate simple interest? 4

4. Write a program to accept full marks and print the qualify marks? 5

5. Write a program to accept any number and print welcome if input number 1

6

6. Write a program to accept any two number and find the largest? 7

7. Write a program to accept any three number and find the largest? 8

8. Write a program to accept percentage of marks and print the division? 9

9. Write a program to accept day number and print the apparent day? 10

10. Write a program to accept percentage of marks and print the apparent division?

11

11. Write a program to print 1 to 100 counting ? 12

12. Write a program to print 1 to 10 using for loop? 13

13. Write a program to calculate factorial any number ? 14

14. Write a program to accept prime or not ? 15

15. Write a program to accept any number a,b,c find the total digit of number? 16

16. calculate the sum is digit. 17

17. print the reverse of that number. 18

18. 1+2+3+4……………………n term. 19

19. 5+10+15+………………….n term. 20

20. 12+32+52+72………………n term. 21

21. 12*23+22*53+32+83………….n term. 22

22. Write a program to print the Fibonacci series into sum n number? 23

23. Write a program to decleear an array of size 10.enter any 10 value then accept any value from the user and search it and the array and print the location that number?

24

24. Write a program to print out sum using funcation ? 25

25. Write a program to print out inside num and in num ? 26

26. Write a program to accept any number and check polidram or not ? 27

27. Write a program to accept p,r,t and find that si ? 28

28. Funcation overloading . 29

29. Pointer. 30

30. Class and object . 31

31. ***** ***** ***** ***** ***** *****

32

Page 3: project - Magadh University

32. All star series. 33

33. Wap to define a class teacher with data member name and salary. Create a function to accept the value of name and salary and calculate his total salary according to. TA,HRA and DA is 10%,5%,20% respectively ?

41

34. Write a program to find the call by value ? 43

35. Write a program to find the call by reference ? 44

Page 4: project - Magadh University

Q1. Write a program to print your name?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

char str [20];

cout<<”enter your name”;

cin>>str;

cout<<” hello,"<<str<<"sir ,you are software devploper "

getch();

}

cout<<"enter your name :";

Output:-enter your name……………….

Hello,………sir, you are software devploper.

Page 5: project - Magadh University

Q2. Write a program to accept p,r,t calculate s.t ?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long si,p,r,t;

cout<<"enter p,r,t,";

cin>>p>>r>>t;

si=(p*r*t)/100;

cout<<"sum="<<si;

getch();

}

Output:-

Enter p,r,t number 100

10

3

Simple interest=30

Page 6: project - Magadh University

Q3.write a program to add two numbers?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,s;

cout<<"enter any two no.";

cin>>a>>b;

s=a+b;

cout<<"sum="<<s;

getch();

}

Output:-

Enter any two number 12

2

Sum=14

Q3.write a program to accept two number and find the sum ?

Page 7: project - Magadh University

Q4. Write a program to accept full marks and print the qualify marks?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long fm,pm;

cout<<"enter the full marks=";

cin>>fm;

pm=fm*40/100;

cout<<"the pass marks ="<<pm;

getch();

}

Output:-

Enter the full marks =………

The pass marks=……..

Page 8: project - Magadh University

Q5.Write a program to accept any number and print welcome if input number is 1?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int num;

cout<<"enter the number";

cin>>num;

if(num==1)

cout<<"welcome";

else

cout<<"wrong input";

getch();

}

Output:-

Enter the number 1

welcome

Page 9: project - Magadh University

Q6.Write a program to accept any two number and find the largest?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b;

cout<<" enter a and b";

cin>>a>>b;

if(a>b)

cout<<" a is largest"<<a;

else

cout<<" b is largest"<<b;

getch();

}

Output:-

Enter a and b……

a/b is largest.

Page 10: project - Magadh University

Q7.Write a program to accept three number and print the largest number?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c;

cout<<" enter any two number a && b && c:-";

cin>>a>>b>>c;

if(a>b)

if(a>c)

cout<<" a is greater ";

else

cout<<" c is greater ";

if(b>c)

cout<<" b is greater ";

else

cout<<" c is greater ";

getch();

}

}

Output:-

Enter any two number a && b && c :------------

---------------- is greater.

Page 11: project - Magadh University

Q8. Write a program to accept percentage of marks and print the division?

#include<conio.h>

#include<iostream.h>

void main()

{

int m;

clrscr();

cout<<"enter p of marks:";

cin>>m;

if(m>=75)

cout<<"distirction";

else

if(m>=60)

cout<<"first division";

else

if(m>=45)

cout<<"second division";

else

if(m>=30)

cout<<"third division";

else

cout<<"fail";

getch();

}

Output:-

Enter p of marks:-

Districcation/first/second/third/fail

Page 12: project - Magadh University

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int m,c;

top:

cout<<" enter day number:-";

cin>>m;

switch(m)

{

case 1:

cout<<" sunday ";

break;

case 2:

cout<<" monday ";

break;

case 3:

cout<<" thuesday ";

break;

case 4:

cout<<" wed ";

break;

case 5:

cout<<" thr ";

break;

case 6:

cout<<" fri ";

break;

Q9.write a program to accept day number and print the appriant day?(switch).

Page 13: project - Magadh University

Output:-

Plz enter day number:-1

monday

cout<<" fri ";

break;

case 7:

cout<<" sat ";

break;

default:

cout<<" wrong choose ";

break;

}

cout<< "\n press 1 to receapt\n";

cin>>c;

if(c==1)

goto top;

getch();

}

Page 14: project - Magadh University

Q10. Write a program to accept percentage of marks and print the appriant division?

#include<iostream.h>

#include<conio.h>

void main()

{

int m;

clrscr();

cout<<"enter p of marks:";

cin>>m;

if(m>=75)

cout<<"distirction";

else

if(m>=60)

cout<<"first division";

else

if(m>=45)

cout<<"second division";

else

if(m>=30)

cout<<"third division";

else

cout<<"fail";

getch();

}

Output:-

Enter p of marks…………. Districation/first/second/third

Page 15: project - Magadh University

Q11. Write a program to print 1 to 100 counting?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

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

{

cout<<"\n"<<i;

}

getch();

}

Output:-

95

96

97

98

99

100

Page 16: project - Magadh University

Q12. Write a program to print 1 to 10 using for loop?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int num,i;

cout<<"enter a number:";

cin>>num;

cout<<"\ couting 10 times by ravi:\n";

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

{

num++;

cout<<num<<"\n";

}

getch();

}

Output:-

1

2

3

4

Page 17: project - Magadh University

Q13.write a program to calculate factorial any number?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n,c;

top:

int f=1;

cout<<"enter n";

cin>>n;

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

{

f=f*i;

}

cout<<f;

cout<<"\n press 1 to repeat";

cin>>c;

if(c==1)

goto top;

getch();

}

Output:-

Enter n ………..

Result …………

Page 18: project - Magadh University

Q14.write a program to accept prime or not?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n,f=0;

cout<<" enter n number";

cin>>n;

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

{

if(n%i==0)

f=1;

}

if(f==0)

cout<<" prime ";

else

cout<<" not prime";

getch();

}

Output:-

Enter n number……..

Prime/not prime

Page 19: project - Magadh University

Q15.write a program to accept any number a,b,c finf the total number of digit ?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n,c=0;

cout<<"enter any number:";

cin>>n;

while(n!=0)

{

n=n/10;

c++;

}

cout<<c;

getch();

}

Output:-

Enter any number:-………….

Result…………

Page 20: project - Magadh University

Q16.calculate the sum is digit.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long i,p,n,sum=0;

cout<<"enter any number:";

cin>>n;

while(n!=0)

{

p=n%10;

sum+=p;

n=n/10;

}

cout<<"sum of digits is :"<<sum;

getch();

}

Output:-

Enter any number:-…………….

Sum of digits is:-………………..

Page 21: project - Magadh University

Q17.write a program print the reverse of that number ?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long n,c,rev=0,d;

top:

cout<<" enter any number :";

cin>>n;

while(n!=0)

{

d=n%10;

rev=(rev*10)+d;

n=n/10;

}

cout<<" the reversed number is :"<<rev;

cout<<"\n press 1 to repeat";

cin>>c;

if(c==1)

goto top;

getch();

}

Output:-

Enter any number:-987654321

The reversed number is 123456789

Page 22: project - Magadh University

Q18.1+2+3+4…………………..n term ?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n,t,s=0;

cout<<" enter number n term ";

cin>>n;

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

{

t=i;

s=s+t;

}

cout<<s;

getch();

}

Output:-

Enter number n term:-……..

Result………..

Page 23: project - Magadh University

Q19.5+10+15+…………………n term.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n,t,s=0;

cout<<" enter number n term ";

cin>>n;

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

{

t=i*5;

s=s+t;

}

cout<<s;

getch();

}

Output:-

Enter number n term:-………….

Result:-……………

Page 24: project - Magadh University

Q20. 12+32+52+72…………………………….. n term.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n,t,s=0,j=1;

cout<<" enter number n term ";

cin>>n;

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

{

t=j*j;

s=s+t;

j=j+2;

}

cout<<s;

getch();

}

Output:-

Enter number n term:-

Result:-

Page 25: project - Magadh University

Q21.12*23+22*53+32*53+………………………. N term.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n,t,s=0,j=1,k=2;

cout<<" enter number n term ";

cin>>n;

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

{

t=(j*j)*(k*k*k);

s=s+t;

j=j+1;

k=k+3;

}

Cout<<s;

Getch();

}

Output:-

Enter number n term…………….

Result:-………………………

Page 26: project - Magadh University

Q22.write a program print the Fibonacci seies into sum n number ?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

long n,first=0,second=1,third;

cout<<"how many number? ";

cin>>n;

cout<<"fibonacci series\n"<<first<<" "<<second;

for(int i=2;i<n;i++)

{

third=first+second;

cout<<" "<<third;

first=second;

second=third;

}

getch();

}

Output:-

How many number ? 2

Fibonacci series

0 1

Page 27: project - Magadh University

Enter 10 values……………………… , enter any value to search:-

Number find of location:-

Q23.write a program to declear an array of size 10 . enter any 10 value

from the usewr and search it and the array and print the location that

number ?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a[10],s,f=0;

cout<<" enter 10 values";

for(int i=0;i<=9;i++)

{

cin>>a[i];

}

cout<<" enter any value to search";

cin>>s;

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

{

if(s==a[i])

{

cout<<"number find of location:-" <<i;

f=1;

}

}

if(f==0)

cout<<" no not exist";

getch();

}

Page 28: project - Magadh University

Q24.write a program to print out sum using funcation ?

#include<iostream.h>

#include<conio.h>

void sum(int,int);

void main()

{

clrscr();

int a,b;

cout<<" enter two number ";

cin>>a>>b;

sum(a,b);

getch();

}

void sum(int x,int y)

{

int s;

s=x+y;

cout<<s;

}

Output:-

Enter two number 12

2

14

Page 29: project - Magadh University

Q25.write a program to print out inside num and in num ?

#include<iostream.h>

#include<conio.h>

void num(int);

void main()

{

clrscr();

int a;

cout<<" enter any number ";

cin>>a;

num(a);

cout<<" inside main"<<a;

getch();

}

void num(int a)

{

a=a+1;

cout<<" in num "<<a;

}

Output:-

Enter any number:-…………………

In num ………….. inside num………….

Page 30: project - Magadh University

Q26.write a program to accept any number and check that palidrom or not ?

#include<iostream.h>

#include<conio.h>

int pl(int);

void main()

{

clrscr();

int n,r,c;

top:

cout<<" enter any number ";

cin>>n;

r=pl(n);

if(r==n)

cout<<" polidrom ";

else

cout<<" not polidrom ";

cout<<" press 1 to receapt ";

cin>>c;

if(c==1)

goto top;

getch();

}

int pl(int n)

{

int r=0,a;

while(n!=0)

{

a=n%10;

r=r*10+a;

n=n/10;

Page 31: project - Magadh University

n=n/10;

}

return r;

}

Output:-

Enter n number :-……………

Polidrom/not polidrom

Page 32: project - Magadh University

Q27.write a program to accept p,r,t and find that si ?

#include<iostream.h>

#include<conio.h>

int si(int,int,int);

void main()

{

clrscr();

int p,r,t,i;

cout<<"enter p,r,t ";

cin>>p>>r>>t;

i=si(p,r,t);

cout<<" simple instrest :-"<<i;

getch();

}

int si(int p,int r,int t)

{

int s=(p*r*t)/100;

return s;

}

Output:-

Enter p,r,t 100

10

3

Simple interest :-30

Page 33: project - Magadh University

Q28.funcation overloading .

#include<iostream.h>

#include<conio.h>

void area(int);

void area(int,int);

void area(float);

void main()

{

area(5,7);

getch();

}

void area(int x)

{

cout<<x*x;

}

void area(int x,int y)

{

cout<<x*y;

}

void area(float x)

{

cout<<3.14*x;

}

Output:-

35

Page 34: project - Magadh University

Q29.write a program to define pointer ?

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a=10;

cout<<a;

cout<<"\n"<<&a;

getch();

}

Output:-

10

0x8f96fff4

Page 35: project - Magadh University

Q30.write a program to define a class stud with data member roll and name and member funcation get data (two

accept roll and name ) and member funcation display ( to display roll and name ).declear any two object of class

stud and coll the appriant funcatiion rreleated to it definition .

#include<iostream.h>

#include<conio.h>

class stud

{

int roll;

char name[20];

public:

void getdata()

{

cout<<" enter roll and name ";

cin>>roll>>name;

}

void display()

{

cout<<"\n roll="<<roll;

cout<<"\n name="<<name;

}

};

void main()

{

clrscr();

stud s1,s2;

s1.getdata();

s2.getdata();

s1.display();

s2.display();

getch();

}

Page 36: project - Magadh University

Output:-

Enter roll and name 12

Ravi

Enter roll and name 13

Utkarsh

Roll=12

Name=ravi

Roll=13

Name =utkarsh

Page 37: project - Magadh University

Q32. *****

*****

*****

*****

*****

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,j;

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

{

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

{

cout<< " * " ;

}

cout<<"\n";

}

getch();

}

Output:-

* * * * *

* * * * *

* * * * *

* * * * *

* * * * *

Page 38: project - Magadh University

Q32.

11 12 13 14 15

21 22 23 24 25

31 32 33 34 35

41 42 43 44 45

51 52 53 5 5 55

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,j;

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

{

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

{

cout<<i<<j<<" ";

}

cout<<"\n";

}

getch();

}

Output:-

11 12 13 14 15

21 22 23 24 25

31 32 33 34 35

41 42 43 44 45

51 52 53 54 55

Page 39: project - Magadh University

Q34.

*

* * *

* * * * *

* * *

*

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,j;

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

{

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

{

if(i+j<5||i+j>11||i-j>3||i-j<-3)

cout<<" ";

else

cout<<"*";

}

cout<<"\n";

}

getch();

}

Output:-

*

* * *

* * * * *

* * *

*

Page 40: project - Magadh University

Q35.

*

* *

* *

* *

* *

* *

*

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,j;

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

{

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

{

if(i+j==5||i+j==11||i-j==3||i-j==-3)

cout<<"*";

else

cout<<" ";

}

cout<<"\n";

}

getch();

}

*

* *

* *

* *

Page 41: project - Magadh University

Q36.

* *

* * *

* * *

* * *

* * *

* * *

* *

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,j;

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

{

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

{

if(i+j==8||i+j==7||i+j==9)

cout<<"*";

else

cout<<" ";

}

cout<<"\n";

}

Output:-

* *

* * *

* * *

* * *

* * *

* * *

* *

Page 42: project - Magadh University

Q37.

*

* *

* * *

* * * *

* * * * *

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,j;

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

{

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

{

cout<<"*";

}

cout<<" ";

cout<<"\n";

}

getch();

}

Output:-

*

* *

* * *

* * * *

* * * * *

Page 43: project - Magadh University

Q38.

*

* *

* * *

* * * *

* * *

* *

*

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,j;

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

{

if(i<=7)

{

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

{

cout<<"*";

}

}

else

{

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

{

cout<<"*";

}

}

cout<<"\n";

}

getch();

}

Page 44: project - Magadh University

Output:-

*

* *

* * *

* * * *

* * *

* *

*

Page 45: project - Magadh University

Q39.

*

* * *

* * * * *

* * * * * * *

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,j;

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

{

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

{

cout<<"*";

}

cout<<"\n";

}

getch();

}

Output:-

*

* * *

* * * * *

* * * * * * *

Page 46: project - Magadh University

Q40.wap to define a class teacher and with data member name and salary.creat a funcation to accept the value of

name and salary and calculate is total salary according to TA,HRA,DA . (TA=10%,HRA=5%,DA=20%)

#include<iostream.h>

#include<conio.h>

class teacher

{

char n[20];

long s,TS,TA,HRA,DA;

public:

void getdata()

{

cout<<"enter your name ";

cin>>n;

cout<<"\nenter your salary ";

cin>>s;

TA=(10*s)/100;

HRA=(5*s)/100;

DA=(20*s)/100;

TS=s+TA+HRA+DA;

}

void display()

{

cout<<"\n name of the teacher is "<<n;

cout<<"\n basic salary="<<s;

cout<<"\n total salary="<<TS;

}

};

void main()

{

clrscr();

teacher utkarsh;

Page 47: project - Magadh University

clrscr();

teacher utkarsh;

utkarsh.getdata();

utkarsh.display();

getch();

}

Output:-

Enter your name utkarsh

Enter your salary 2000

Name of the teacher is utkarsh

Basic salary=2000

Total salary=2700

Page 48: project - Magadh University

Q41wap to define a class stud with data member name and marks and funcation get data (two accept name and

marks) and member funcation display ( to display name and marks) declear any two object of class stud and call the

appriant funcation releated to it definition..

Page 49: project - Magadh University

void main()

{

clrscr();

stud s[6];

for(int i=0;i<=5;i++)

{

cout<<"object no="<<i;

s[i].getdata();

}

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

Output:-

Object no=0 enter name and marks utkarsh

600

Object no=1 enter name and marks ravi

595

Object no=2 enter name and marks babu

580

Object no=3 enter name and marks abhisek

585

Object no=4 enter name and marks amit

565

Object no=5 enter name and marks raj

577

Name=utkarsh

Marks=600

name=ravi

marks=595

name=babu

marks=580

name=abhisek

marks=585

name=amit

marks=565

name=raj

marks=577

Page 50: project - Magadh University

Q42.write a program to find the call by value ?

#include<iostream.h>

#include<conio.h>

void num(int);

void main()

{

clrscr();

int a;

cout<<"enter your number ";

cin>>a;

num(a);

cout<<"\ninside main"<<a;

getch();

}

void num(int a)

{

a=a+1;

cout<<"\ninside num"<<a;

}

Output:-

Enter your number 16

Inside num 17

Inside main 16

Page 51: project - Magadh University

Q43.write a program to find the call by reference ?

#include<iostream.h>

#include<conio.h>

void num(int*);

void main()

{

clrscr();

int a;

cout<<"enter your number ";

cin>>a;

num(&a);

cout<<"\ninside main"<<a;

getch();

}

void num(int *a)

{

*a=*a+1;

cout<<"\ninside num"<<*a;

}

Output:-

Enter your number 18

Inside num 19

Inside main 19

Page 52: project - Magadh University