C++ Assignment

185
C++ Assignment 2010 1 MASTER OF COMPUTER APPLICATION SESSION: 2010-11 ASSIGNMENT ON OBJECT ORIENTED PROGRAMMNG WITH C++ S.O.S IN COMPUTER SCIENCE GUIDED BY Prof. V.K.PATLE SUBMITTED BY Mr. PREMENDRA YADAW M.C.A. Ist Sem

description

this document was created as a college practical assignment work...

Transcript of C++ Assignment

Page 1: C++ Assignment

C++ Assignment 2010

1

MASTER OF COMPUTER APPLICATION

SESSION: 2010-11

ASSIGNMENT ON OBJECT ORIENTED

PROGRAMMNG WITH C++

S.O.S IN COMPUTER SCIENCE

GUIDED BY

Prof. V.K.PATLE

SUBMITTED BY

Mr. PREMENDRA YADAW

M.C.A. Ist Sem

MC

Page 2: C++ Assignment

C++ Assignment 2010

2

INDEX

S. NO. TITLE PAGE NO.

1. Write a program to print the values of given variable using

refrence variable

2. Write a program to print the values of given variable using

assignment operater variable

3. Write a program to using enum data type 4. Write a program to convert tempreture farenhight to calcious

and calcious to farenheight .

5. Write a program to print vlaue of globle variable using Scope

esolution operator.

6. Write a program to print series upto 1 t0 n using for loop. 7. Write a program to print value of variable using arithmetic

operator.

8. Write a program to print value of large variable using if

Statement

9. Write a program to find value of largest variable using else

if..else Statement.

10. Write a program to print name and age value using else

if..else Statement

11. Write a program using goto and continue statement 12. Write a program to find out the given year is leap

year or not.?

13. Write a program to understand scope of local variable

using user define function?.

14. Write a program to understand scope of globle variable

using user define function.

15. Write a program to understand use of static variable

using user define function.

16. Write a program to print today date and exam study

date using structure.

17. Write a program to student rollno,name,subject,marks and

date using nested structure .

18. Write a program to print students rollno,name,marks and

percent using array of structure.

Page 3: C++ Assignment

C++ Assignment 2010

3

19. Write a program to print students rollno,name,marks and

percent using function & structure.

20. Write a program to print revers any number and sum

of those number.

21. Write a program to find the area of rectangle,circle

and triangle using operator ovaerloading.

22. Write a program to find minimum value amoung two

number using return by refrence.

23. Write a program to convert lowercase string into uppercase

string using the concept of function with array.

24. Write a program to find given string is Palindrome

or not.

25. Write a program to find factorial of given number using

Return statement.

26. Write a program to find Name and Rollnumber student

using class & object.

27. Write a program to print date using class and object.

28. Write a program to print distance as feet-inch format

Using the concept passing object as pass by value.

29. Write a program of transfer amount from one account

to another account using concept of pass object as pass

by refrence.

30. Write a program find the root of quadratic equation.?

31. Write a program to reverse the given no. and check

the no. is palindrome or not. ?

32. Write a program to print two mathematical series:-

a) 1+(1+2)+(1+2+3)+…..+n=

b) 1+1/9+1/25+….+n=

33. Write a program to find out the biggest no. and smallest no.

three?

34. Write a program to print Fibonacci series and sum of series.?

35. Write a program to count the vowel ,consonants ,digits,

Tab,space and special character in a string.

Page 4: C++ Assignment

C++ Assignment 2010

4

36. wtite a program using all operator and conditional statement

in a single program?

37. Write a program to define a structure with name,standard

&rollno input data for 10 student then print it?

38. write a program to input 20 record of employee includeing

name,basic salary,age,sex.find the no of man women and avg

of basic salary and the no of emp above 50 year.

39. write a function with take two variable of structure type

employee.the fun should return true if age of 1st emp greater

then other wise it should return false declare true and false int

constant using the enum data type.

40. Write a program to addition of two complex class object

contain 2 attribute real & imaginary addition of complex class

object means addition of real & imaginary separately and

display the addition this complex number.

41. imagine publishing companies take market both book & audio

cassettes version of its work create a class publication that

store the title & price of a publication. From this class drive

two class: book which add the page count and tape, which

adds a playing time in minute each of these 3 class should

have get data() function to get its data from the user and a put

data() function to display its data.

42. Write a program to create a class distance having data

member feet and inch.it contain member function for taking

input in data member and member function for display value

od data member.

43. Write a program to Explain Overloading

44. Write a class having name calculate that user static

overloaded function and calculate area of circle,area of

rectangle and area of triangle.

45. Write a swapping program to demonstrate call by value and

Call by reference and call by address in single program..

Page 5: C++ Assignment

C++ Assignment 2010

5

46. Print this output…

* * * * *

* * * *

* * *

* *

*

* *

* * *

* * * *

* * * * *

47. Write a program to generate following pattern :

a) b)

ABCDEFG *

ABC EFG * *

AB FG * * *

A G

c) d)

1 1

1 2 1 2 1

1 2 3 1 3 3 1

1 2 3 4 1 4 6 4 1

48. Create a program to perform following tasks without using

library function.

a. To reverse the string accepted as argument.

b. To count the no. of characters in string passed as

argument in form of character array.

c. To copy the one string to other string passed as

argument in form of source character array and destination

character array without using function.

d. To count no. of vowels consonants in each word of a

sentens as argument in form of character array

Page 6: C++ Assignment

C++ Assignment 2010

6

Author Name:- Premendra Yadaw

Path:- D:\Angel\reference.CPP

Unit:- II

Date:- 13/11/2010

Que 1:- Write a program to print the values of given variable using

refrence variable.

Algorithm:- [To Print the values of variable] Here a,b,c is

an Integer data types which is store the given number and &z is

Refrence variable]

Step1: [Assign value in the variable] a=1,b=2,c=3

Step2: [Assign value of a in &z] &z=a

Step3:Print value of veriable a,b,c, &z

Step4: [Assign value of b in z] z=b

Step5:Print value of veriable a,b,c, &z

Step6: [Assign value of a in &z] z=c

Step3:Print value of veriable a,b,c, &z

Step7:Exit.

Page 7: C++ Assignment

C++ Assignment 2010

7

Program:-

/*print value of variable using refrence variable*/

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

//declration & assignment of variable

int a=1,b=2,c=3;

//assign value in refrence variable

int &z=a;

cout<<"a= "<<a <<" b= "<<b <<" c= "<<c<<” z=”<<&z<<endl;

z=b;

cout<<"a= "<<a <<" b= "<<b <<" c= "<<c<<” z=”<<&z<<endl;

z=c;

cout<<"a= "<<a <<" b= "<<b <<" c= "<<c<<” z=”<<&z<<endl;

getch( );

}

Output:-

Page 8: C++ Assignment

C++ Assignment 2010

8

Flowchart:-

z=c

z=b

STOP

Int a=1,b=2,c=3

Int &z=a

Print a,b,c

,z

Print a,b,c,z

,z

Print a,b,c,z

,z

START

Page 9: C++ Assignment

C++ Assignment 2010

9

Author Name:- Premendra Yadaw Path:- D:\Angel\polar.CPP

Unit:- II

Date:- 13/11/2010

Que 2:- Write a program to print the values of given variable using

assignment operater variable.

Algorithm:- [To Print the values of variable] Here a,b,c is

an Integer data types which is store the given number and ‟polar‟

is float data type]

Step1: [Assign value in the variable using assignment operator]

c=100

b=c+100

polar=55*9

Step2: Print the value oe a,b,c and polar

Step3:Exit.

Page 10: C++ Assignment

C++ Assignment 2010

10

Program:-

/*print value of variable using assignment opertor*/

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

//declare variable & initialize

int a,b;

int c=100;

float polar;

a=c;

b=c+100,polar=55.9;

cout<<"a="<<a<<endl;

cout<<"b="<<b<<endl;

cout<<"c="<<c<<endl;

cout<<"polar="<<polar<<endl;

getch();

}

Output:-

Page 11: C++ Assignment

C++ Assignment 2010

11

Flowchart:-

STOP

Int a,b,c=10

Float distance

Print

a,b,c,disance

,distance,,z

START

a=c

b=c+1

distance=55.9

Float distance

Page 12: C++ Assignment

C++ Assignment 2010

12

Author Name:- Premendra Yadaw

Path:- D:\Angel\enum.CPP

Unit:- II

Date:- 13/11/2010

Que 3:- Write a program to using enum data type.

Algorithm:- [To Print the values of variable using enum datatype] Here code

an Integer data types and circle,rectangle, triangle value of enum

data type.

Step1: [Assign value in the enum datatype]

enum{circle,rectangle,triangle}

Step2: [Input code] Read : code

Step3: switch(code)

Step4: [Assign value of b in z] z=b

Step5:Print value of veriable a,b,c, &z

Step6: [Assign value of a in &z] z=c

Step3:Print value of veriable a,b,c, &z

Step7:Exit.

Page 13: C++ Assignment

C++ Assignment 2010

13

Program:-

/*print shape using enum variable*/

#include<iostream.h>

#include<conio.h>

enum{circle,rectangle,triangle};

void main()

{

int code;

clrscr();

cout<<" Enter shape code:- ";

cin>>code;

switch(code)

{

case circle:

cout<<"Circle";

break;

case rectangle:

cout<<" Rectangle";

break;

case triangle:

cout<<"Triangle";

break;

default:

cout<<"Invalid Entry";

}

getch();

}

Page 14: C++ Assignment

C++ Assignment 2010

14

Output:-

Page 15: C++ Assignment

C++ Assignment 2010

15

Author Name:- Premendra Yadaw

Path:- D:\ Angel/convert_temp.CPP

Unit:- II

Date:- 13/11/2010

Que 4:- Write a program to convert temperature farenhight to

calcious and calcious to farenheight .

Algorithm:- [To convert temperature farenhight to calcious ancalcious to ]

Here c,f float data types that stores temperature in calcious

farenhight

Step1: [Input temperature in calcious] Read : c

Step2: f=1.8*c+32

Step3: [print temperature in farenhight] Write : f

Step4: [Input temperature in farenhight] Read : f

Step5:c=(f-32)/1.8

Step6: [print temperature in calcious] Write : c

Step7:Exit

Page 16: C++ Assignment

C++ Assignment 2010

16

Program:-

/*find temperature in cacious & farenhight*/

#include<iostream.h>

#include<conio.h>

void main()

{

float c,f;

clrscr();

cout<<"Enter the value of temperature in calcious :- ";

cin>>c;

f= 1.8*c+32;

cout<<"Temperature in farenhight = "<<f<<endl;

cout<<"Enter the value of temperature in farenhight :- ";

cin>>c;

c= (f-32)/1.8;

cout<<"Temperature in calcious = "<<f<<endl;

getch();

}

Output:-

Page 17: C++ Assignment

C++ Assignment 2010

17

Flochart:-

f=1.8*c+32

STOP

Float c,f

INPUT : c

a,b,c ,z

PRINT: f

a,b,c,,z

INPUT: f

START

c=f-32/1.8

Page 18: C++ Assignment

C++ Assignment 2010

18

Author Name:- Premendra Yadaw

Path:- D:\ Angel/global_var.CPP

Unit:- II

Date:- 13/11/2010

Que 5:- Write a program to print vlaue of global variable using

scoperesolution operator.

Algorithm:-[To print value of global variable] Here p is integer type global variable Step1: [Declare global variable] int p := 100

Step2 : [main function start]

{

Step3 : [Intilise p] int p=200

{

Step4: int l=p

Step4: int p=300

Step5: Write : “ l =”, l

Step6: Write : “ p =”, p

Step7: Write : “::p =” , ::p

}

Step9: Write : “p = “ , p

Step8: Write : “::p =” , ::p

}[End of main funtion]

Step9: Exit

Page 19: C++ Assignment

C++ Assignment 2010

19

Program:-

/*find the value of global variable*/

#include<iostream.h>

#include<conio.h>

int p=100; //declare global variable

void main()

{

int p=200;

clrscr();

{

int l=p;

int p=300;

cout<<"l= "<<l<<endl;

cout<<"p= "<<p<<endl;

cout<<"::p= "<<::p<<endl;

}

cout<<"p= "<<p<<endl;

cout<<"::p= "<<::p<<endl;

getch() ;

}

Output:-

Page 20: C++ Assignment

C++ Assignment 2010

20

Flowchart:-

p=300

STOP

int p

PRINT “l =”, l

START

int l=p

PRINT “p=”, p

PRINT “::p=”,::p

PRINT “p=”, p

PRINT “::p=”,::p

Page 21: C++ Assignment

C++ Assignment 2010

21

Author Name:- Premendra Yadaw

Path:- D:\Angel\series.CPP

Unit:- II

Date:- 13/11/2010

Que 6:- Write a program to print series upto 1 t0 n using for loop.

Algorithm:- [To print series upto 1 to n ]

Here i,j,n integer type data types that stores given value

Step1: [Input number] Read : n

Step2: reapeat step3,4,5for i= 1to n

Step3: j=2*i

Step4: [print value of j] Write : j

Step5:[Increase counter] i=i+1

[End of for loop}

Step6: Exit

Page 22: C++ Assignment

C++ Assignment 2010

22

Program:-

/*print series upto 1 to n*/

#include<iostream.h>

#include<conio.h>

void main()

{

int i,n,j;

j=0;

clrscr();

cout<<"enter the number to want the series";

cin>>n;

cout<<" \n series is";

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

{

j=2*i;

cout<<j<<"\t";

j=2*i-1;

cout<< j<<"\t";

}

getch();

}

Output:-

Page 23: C++ Assignment

C++ Assignment 2010

23

Flowchart:-

False

True

int n

START

INPUT: n

i=i+2

i< n

PRINT: i+2

int i=0

STOP

Page 24: C++ Assignment

C++ Assignment 2010

24

Author Name:- Premendra Yadaw

Path:- D:\Angel\arithmat.CPP

Unit:- II

Date:- 13/11/2010

Que 7:- Write a program to print value of variable using

arithmetic operator.

Algorithm:- [To print value of variable using arithmetic operator ]

Here i,s, ss integer data types that stores given value.

Step1: [Assign value to variable] s=0,ss=0

Step2: reapeat step3,4 ,5,6 for i= 2 to 9

Step3: s+=i

Step4: ss+=i*i

Step5[Print value of variable]

Write : s

Write : ss

Step5: [Increase counter] i+=2

[End of for loop}

Step6: Exit

Page 25: C++ Assignment

C++ Assignment 2010

25

Program:-

/*print value of variable using arithmetic opertor*/

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int s=0,ss=0,i;

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

{

s+=i;

ss+=i*i;

cout<<s;

cout<<"\t"<<ss<<endl;

}

getch();

}

Output:-

Page 26: C++ Assignment

C++ Assignment 2010

26

Flowchart:-

False

True

START

int s=0,ss=0,i

i=2

i<=15

s+=i

ss+=i*i

PRINT: s , ss

START

ss+=i*i

Page 27: C++ Assignment

C++ Assignment 2010

27

Author Name:- Premendra Yadaw

Path:- D:\Angel\if.CPP

Unit:- II

Date:- 13/11/2010

Que 8:- Write a program to print value of large variable using if

statement

Algorithm:- [To print value of large variable]

Here a,b,c,d integer data types that stores given value.

Step1: [Input value to vaeiable] Read : a,b,c

Step2: [Assign value to variable d] d=a

Step3: [find large value] if(b>d) then

Goto step 4

Step4: d=b

Step5: [find large value] if(C>d) then

Goto step 6

Step6: b=c

Step7[Print value of variable] Write : d

Step8 Exit

Page 28: C++ Assignment

C++ Assignment 2010

28

Program:-

/*find biggest value*/

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,c,d;

cout<<"enter the value of a,b,c"<<endl ;

cin>>a>>b>>c;

d=a;

if(b>d)

{

d=b;

}

if(c>d)

{

d=c;

}

cout<<endl<<"Value od d = "<<d;

getch();

}

Output:-

Page 29: C++ Assignment

C++ Assignment 2010

29

Flowchart:-

START

int a,b,c

INPUT: a,b,c

d = a

if(d=a)

if (c>d)

d = b

d = c

PRINT :d

STOP

Page 30: C++ Assignment

C++ Assignment 2010

30

Author Name:- Premendra Yadaw

Path:- D:\Angel\largest.CPP

Unit:- II

Date:- 13/11/2010

Que 9:- Write a program to find value of largest variable using else

if..else Statement.

Algorithm:- [To find value of largest variable]

Here a,b,c, integer data types that stores given value.

Step1: [Input value to vaeiable] Read : a,b,c

Step2: [find largest value]

If a>b and a>c then

Goto step 3

Else if b>a and b>c then

Goto step 4

Else

Goto step 5

Step3: Write : „a is largest‟

Step4: Write : „b is largest‟

Step5: Write : „c is largest‟

Step6: Exit

Page 31: C++ Assignment

C++ Assignment 2010

31

Program:-

/*find largest value among three value*/

#include<iostream.h>

#include<conio.h>

void main()

{

//variable decleration

int a,b,c;

cout<<"enter three number";

cin>>a>>b>>c;

if(a>b && a>c)

cout<<"the largest number is a";

else if(b>c && b>a)

cout<<"the largest number is b";

else

cout<<"the largest number is c";

getch();

}

Output:-

Page 32: C++ Assignment

C++ Assignment 2010

32

Flowchart:-

False False

True

int a,b,c

INPUT: a,b,c

if(a>b &&

a>c)

PRINT:”a is

big”

else if(b<a

&& b>c)

PRINT:”b is

big”

PRINT:”c is

big”

STOP

START

Page 33: C++ Assignment

C++ Assignment 2010

33

Author Name:- Premendra Yadaw

Path:- D:\Angel\age.CPP

Unit:- II

Date:- 13/11/2010

Que 10:- Write a program to print name and age value

using else if..else Statement.

Algorithm:- [To find value of largest variable]

Here age is integer data types and name is character data type that

. stores given value

Step1: [Input name & age to variable] Read: name

Read: age

Step 2 :If age<21 then

Goto step 3

Else if age <40 then

Goto step 4

Else if age<60 then

Goto step 5

Else if age<80 then

Goto step 5

Else

Goto step 6

[End of else if ..else statement]

Step 3: Write : name

Write : age

Step 4: Write : name

Write : age

Step 5: Write : name

Write : age

Step 6: Write : name

Write : age

Step 7: Exit

Page 34: C++ Assignment

C++ Assignment 2010

34

Program:-

/*find name age*/

#include<conio.h>

#include<iostream.h>

void main()

{

clrscr();

//variable decleration

char name[20];

int age;

cout<<"Enter your name:- ";

cin>>name;

cout<<endl<<"enter your age:-" ;

if(age<21)

{

cout<<"Age -"<<age<<" Name -"<<name;

}

else if(age<40)

{

cout<<"Age -"<<age<<" Name -"<<name;

}

else if(age<60)

{

cout<<"Age -"<<age<<" Name -"<<name;

}

else if(age<80)

{

cout<<"Age -"<<age<<" Name -"<<name;

}

else

{

cout<<"Age -"<<age<<" Name -"<<name;

}

getch();

}

Page 35: C++ Assignment

C++ Assignment 2010

35

Output:-

Page 36: C++ Assignment

C++ Assignment 2010

36

Flowchart:-

False False False

True True True True

False

START

char name[20]

int age

INPUT: name

INPUT:age

if(age<

21)

if(age<

40)

if(age<

60)

if(age<

80)

PRINT

name,age

PRINT

name,age

PRINT

name,age

PRINT

name,age

PRINT

name,age

STOP

Page 37: C++ Assignment

C++ Assignment 2010

37

Author Name:- Premendra Yadaw

Path:- D:\Angel\goto.CPP

Unit:- II

Date:- 13/11/2010

Que 11:- Write a program using goto and continue statement.

Algorithm:- [Program using goto & continue statement] Here n,d is integer data types that stores given value.

Step1: [Input value of n] Read : n

Step 2:[assign value to variable] d=0

Step 3:[ do.. while statement used]

Do{

[input value of n ] Read : n

If n=0 then

Write: „End\n‟

Goto end [goto step 6]

If n<0 then

Write: „Skip thip no.‟

Continue

Step 4: [ Increase counter variable d] d=d+1

Step 5: repeat step 3 & 4 while(1)

Step 6: end :[print value of d] Write: d

Step 7:exit

Page 38: C++ Assignment

C++ Assignment 2010

38

Program:-

/*use of goto statement*/

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n,d=0;

do{

cout<<"Enter any number";

cin>>n;

if (n==0)

{

cout<<"End"<<endl;

goto end;

}

if(n<0)

{

cout<<"Skip this no.";

continue;

}

d=d+n;

}while(1)

end:cout<<"Value of n is 0";

getch();}

Output:-

Page 39: C++ Assignment

C++ Assignment 2010

39

Flowchart:-

do

False

True

False

True

False

START

int n,d=0

INPUT: n

If(n= =0)

PRINT: ”END”

continue

if(n<0)

PRINT:”Skip No.”

d = d + 1

end:”Enterned number is

0”

While(1)

STOP

goto end

Page 40: C++ Assignment

C++ Assignment 2010

40

Author Name:- Premendra Yadaw

Path:-d:\ Angel \leapyear.CPP

Unit:- II

Date:- 13/11/2010

Que 12:- Write a program to find out the given year is leap

year or not.? Algorithm:-[Find the given year is leap year or not]

YEAR is an integer data type. YEAR store the

year given by the user

Step1:- [Input a year] Read: YEAR

Step2:- if ((YEAR/4 = 0) AND (YEAR/100! =0) OR

(YEAR/400 = 0)) Then

Write: „this year is leap year‟

Step3:- Else

Write: „this is not a leap year‟

[End of if structure]

Step4:- Exit.

Page 41: C++ Assignment

C++ Assignment 2010

41

Program:-

/*find the given year is leap year or not*/

#include<iostream.h>

#include<conio.h>

Void main ()

{

int yr;

Cout<<”Enter a year”<<endl;

Cin>>yr;

If(((yr%4= = 0)&&(yr %100!= 0 ))||(yr%400 = =0))

Cout<<”This year is leap year”;

Else

Cout<<”this year is not leap year”;

Getch();

}

Output:-

Page 42: C++ Assignment

C++ Assignment 2010

42

Flow-chart:-

START

yr

If (((yr/4=0) AND

(yr/100!=0)) OR

(yr/400)) then

then

It is not leap year

It is leap year

STOP

Page 43: C++ Assignment

C++ Assignment 2010

43

Author Name:- Premendra Yadaw

Path:- D:\Angel\local_var.CPP

Unit:- II

Date:- 13/11/2010

Que 13:- Write a program to understand scope of local variable

using user define function.

Algorithm:- [To understand scope of local veriable]

Here x is integer type verible

Step1: [Initialize x] int x = 2222

Step2: [Declare function] void funb()

Step3: [Call function] void funb()

Step4: Write : “x =” ,x

Step5: Exit

[Subalgorithm of funb()]

Step1: [Initialize x] int x = 222

Step2: [Declare function] void funa()

Step3: [Call function] void funa()

Step4: Write : “x =” ,x

Step5: Exit

[Subalgorithm of funa()]

Step1: [Initialize x] int x = 22

Step4: Write : “x =” ,x

Step5: Exit

Page 44: C++ Assignment

C++ Assignment 2010

44

Program:-

/* find value of variable using local variable */

#include<iostream.h>

#include<conio.h>

void main()

{

int x=2222;

clrscr();

void funb();

funb();

cout<<"x="<<x<<endl;

getch();

}

void funb()

{

int x=222;

void funa();

funa();

cout<<"x="<<x<<endl;

}

void funa()

{

int x=22;

cout<<"x="<<x<<endl;

}

Output:-

Page 45: C++ Assignment

C++ Assignment 2010

45

Flowchart:-

// Flow Of Funtionb()

// Flow Of Funtiona()

START

STOP

int x= 2222

Call functionb()

Print:x

START

int x= 222

Print:x

STOP

Call functiona()

START

STOP

int x= 2222

Print:x

Page 46: C++ Assignment

C++ Assignment 2010

46

Author Name:- Premendra Yadaw

Path:- D:\Angel\global_var.CPP

Unit:- II

Date:- 13/11/2010

Que 14:- Write a program to understand scope of global variable

using define function.

Algorithm:- [To understand scope of global variable]

Here a is global integer type verible

Step1: [Declare function] void funA()

Step2: [Declare function] void funB()

Step3: [Declare function] void funC()

Step1: [Declare veriable] int a = 5

Step5: Exit

[Subalgorithm of void main()]

Step1: [Initialize a] int a = 5

Step2: [Declare function] void funa()

Step3: Write : “a = “ , a

Step4: [call function] funA()

Step5: [call function] funB()

Step6: [call function] funC()

Step7: Exit

[Subalgorithm of int funA()]

Step1: [Initialize a] a = a+4

Step4: return a

Step5: Exit

[Subalgorithm of int funB()]

Step1: [Initialize a] int a = 1

Step4: return a

Step5: Exit

[Subalgorithm of int funC()]

Step1: [Initialize a] a = a+4

Step4: return a

Step5: Exit

Page 47: C++ Assignment

C++ Assignment 2010

47

Program:-

/*print value of global variable*/

#include<iostream.h>

#include<conio.h>

int funA();

int funB();

int funC();

int a=5;

void main()

{

int a=5;

clrscr();

cout<<"a= "<<a;

cout<<endl<<"FuntionA "<<funA();

cout<<endl<<"FuntionB "<<funB();

cout<<endl<<"FuntionC "<<funC();

getch();

}

int funA()

{

a=a+4;

return a;

}

int funB()

{

int a;

a=1;

return(a);

}

int funC()

{

a=a+4;

return a;

}

Page 48: C++ Assignment

C++ Assignment 2010

48

Output:-

Page 49: C++ Assignment

C++ Assignment 2010

49

Flowchart:-

//global variable

STOP

START

PRINT:”funtionA()”

int a

int a=5

PRINT:”funtionB”

Call funtionA()

Call funtionB()

Page 50: C++ Assignment

C++ Assignment 2010

50

// Flow of funtionA()

// Flow of funtionA()

START

STOP

a=a+4

return a

START

return (a)

int a=1

STOP

Page 51: C++ Assignment

C++ Assignment 2010

51

Author Name:- Premendra Yadaw

Path:- D:\Angel\stat.CPP

Unit:- II

Date:- 13/11/2010

Que 15:- Write a program to understand use of static variable

using user define function.

Algorithm:- [To understand use of static variable]

Here x is integer type verible

Step1: [Declare variable] int x

Step2: Repeat step 3 & 4 for x=1 to x<4

Step3: [Call function] state()

Step4: Exit

[Subalgorithm of void state()]

Here a is integer type static variable

Step1: [Initialize a] static int a = 0

Step2: a=a+2

Step3: Write : “a = “ , a

Step4: Exit

Page 52: C++ Assignment

C++ Assignment 2010

52

Program:-

/*print vaue of static varible*/

#include<iostream.h>

#include<conio.h>

void state();

void main()

{

int x;

clrscr();

for(x=1;x<4;x++)

{

state();

}

getch();

}

void state()

{

static int a=0;

a=a+2;

cout<<"a="<<a<<endl;

}

Output:-

Page 53: C++ Assignment

C++ Assignment 2010

53

Flowchart:-

// Flow of function state()

START

int x

x = 1

x < 4

Call funtion state()

x = x+1

STOP

int a=0

START

a = a+2

PRINT: a

STOP

Page 54: C++ Assignment

C++ Assignment 2010

54

Author Name:- Premendra Yadaw

Path:- D:\Angel\structure.CPP

Unit:- III

Date:- 13/11/2010

Que 16:- Write a program to print today date and exam study

date using structure.

Algorithm:- [To print today date & exam study date]

Here d1,d2 is veriable of structure date

Step1: [Declare & Initialize structure variable]

date d1={29,9,2010};

date d2={14,12,2010};

Step2: Write : " Today Date ";

Step3: Write : d1.day "-" d1.month "-" d1.year

Step4: Write : "Exam Study date"

Step5: Write : d2.day "-" d2.month "-"d2.year

Step6: Exit

[Subalgorithm of structure defination]

Here a is day,month & year integer type variable

Step1: [Declare Structure] struct date

{

Step2: [Declare variable] int day

Step3: [Declare variable] int month

Step4: [Declare variable] int year

Step5: Exit

Page 55: C++ Assignment

C++ Assignment 2010

55

Program:-

/*print date using struture*/

#include<iostream.h>

#include<conio.h>

struct date

{

int day;

int month;

int year;

};

void main()

{ clrscr();

date d1={29,9,2010};

date d2={14,12,2010};

cout<<" Today Date ";

cout<<d1.day<<"-"<<d1.month<<"-"<<d1.year;

cout<<"\nExam Study date";

cout<<d2.day<<"-"<<d2.month<<"-"<<d2.year;

getch();

}

Output:-

Page 56: C++ Assignment

C++ Assignment 2010

56

Flowchart:- // Structure Declaretion

Flow Of main() funtion

//Structure variable intilised

START

struct date

STOP

START

Date d1={29,9,2010}

Date d2={14,12,2010}

PRINT: “Today Date”,

d1.day,d1.month,d1.year

PRINT: “Exam Date”,

d2.day,d2.month,d2.year

STOP

int day

int month

int year

Page 57: C++ Assignment

C++ Assignment 2010

57

Author Name:- Premendra Yadaw

Path:- D:\Angel\neststruct.CPP

Unit:- III

Date:- 13/11/2010

Que 17:- Write a program to student rollno,name,subject,marks &

date using nested structure .

Algorithm:- [To print rollno,name,subject,marks & date]

Here d1,d2 is veriable of structure student

Step1: [Declarestructure variable] student s1;

Step2: Write : "Enter Rollno "

Step3: Read : s1.rollno;

Step4: Write : "Enter Name ";

Step5: Read : s1.name;

Step6: Write : "Enter Subject ";

Step7: Read : s1.subject;

Step8: "Enter Date ";

Step9: Read : s1.today.day;

Step10: Write:"Enter Month ";

Step11: Read : s1.today.month;

Step12: Write : "Enter Year ";

Step13: Read : s1.today.year;

Step14: Write : "Student Record"

Step15: Write : "Rollno= " , s1.rollno

Step16: Write : "Name= ", s1.name

Step17: Write : "subject= ",s1.subject

Step18: Write : "Date= ",s1.today.day,"_",s1.today.month,"-

",s1.today.year

Step19: Exit

[Subalgorithm of nested structure date defination]

Here a is day,month & year integer type variable

Step1: [Declare Structure] struct date

{

Step2: [Declare variable] int day

Page 58: C++ Assignment

C++ Assignment 2010

58

Step3: [Declare variable] int month

Step4: [Declare variable] int year

Step5: Exit

[Subalgorithm of structure student defination]

Here a is day,month & year integer type variable

Step1: [Declare Structure] struct date

{

Step2: [Declare variable] int rollno

Step3: [Declare variable] char name[20]

Step4: [Declare variable] char subject[10]

Step5: [Declare variable] int marks

Step6: [Declare date structure variable] struct date today

Step5: Exit

Page 59: C++ Assignment

C++ Assignment 2010

59

Program:-

/*print date student information using struture*/

#include<iostream.h>

#include<conio.h>

struct date

{

int day;

int month;

int year;

};

struct student

{

int rollno;

char name[20];

struct date today;

char subject[10];

int marks;

};

void main()

{

student s1;

clrscr();

cout<<"Enter Rollno ";

cin>>s1.rollno;

cout<<endl<<"Enter Name ";

cin>>s1.name;

cout<<endl<<"Enter Subject ";

cin>>s1.subject;

cout<<endl<<"Enter Date ";

cin>>s1.today.day;

cout<<endl<<"Enter Month ";

cin>>s1.today.month;

cout<<endl<<"Enter Year ";

cin>>s1.today.year;

cout<<"Student Record"<<endl;

cout<<"Rollno= "<<s1.rollno<<endl;

cout<<"Name= "<<s1.name<<endl;

Page 60: C++ Assignment

C++ Assignment 2010

60

cout<<"subject= "<<s1.subject<<endl;

cout<<"Date= "<<s1.today.day<<"_"<<s1.today.month<<"-"<<s1.today.year;

getch() }

Output:-

Page 61: C++ Assignment

C++ Assignment 2010

61

Flowchart:-

// Struture date decleration

//structure student declare

START

Struct date

int day

int month

int year

STOP

int rollno

int marks

char name[10]

char subject[10]

char marks

date today

START

struct student

STOP

Page 62: C++ Assignment

C++ Assignment 2010

62

Flowchart_of_main():-

START

student s1

PRINT:”Today Date”

PRINT:”Name”

s1.name

PRINT:”Marks”

s1.marks

PRINT:s1.today.day

,S1,today.month

S2,today.year

PRINT:”Rollno.”

s1.rollno

STOP

Page 63: C++ Assignment

C++ Assignment 2010

63

Author Name:- Premendra Yadaw

Path:- D: \Angel \array_struct.CPP

Unit:- II

Date:- 13/11/2010

Que 18:- Write a program to print students rollno,name,marks and percent using array of structure.

Algorithm:- [To print rollno,name,subject,marks & percent]

Here s1[10] is array variable of structure student type

Step1: [Declare structure variable] student s1[10];

Step2: int n , i=0

Step3: Write : “Enter any number”

Step4: Read : n

Step5: Reapeat step 6 to 12 for i=1 to n

Step6: Write : "Enter Rollno "

Step7: Read : s1[i].rollno

Step8: Write : "Enter Name "

Step5: Read : s1[i].name

Step6: Write : "Enter Subject "

Step7: Read : s1[i].subject

Step8: Write : "Enter Marks"

Step9: Read : s1[i].marks

Step10: Write:"Enter Percent"

Step11: Read : s1[i].percent

Step12: i=i+1

Step13: Write : "Student Record

Step14: Reapeat step 15 to 20 for i = 1 to n

Step15: Write : "Rollno= " , s1[i].rollno

Step16: Write : "Name= ", s1[i].name

Step17: Write : "subject= ",s1[i].subject

Step18: Write : “Marks=” , s1[i].marks

Step19: Write : “Percent=” , s1[i].percent

Step20: Exit

[Subalgorithm of structure student defination]

Here a is rollno,name,subject,marks & percent integer type

variable.

Step1: [Declare Structure] struct date

Page 64: C++ Assignment

C++ Assignment 2010

64

{

Step2: [Declare variable] int rollno

Step3: [Declare variable] char name[10]

Step4: [Declare variable] char subject[10]

Step4: [Declare variable] int marks

Step4: [Declare variable] int percent

}[End of struture definition]

Step5: Exit

Program:-

/*print student imformation using array of strcuture*/

#include<iostream.h>

#include<conio.h>

struct student

{

int rollno;

char name[10];

char subject[20];

int marks;

float per;

};

void main()

{

clrscr();

student s[10];

int n;

cout<<"Enter any number:-";

cin>>n;

int i=0;

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

{

cout<<"Enter imfomation of student "<<i;

cout<<endl<<"Enter Rollno ";

cin>>s[i].rollno;

cout<<endl<<"Enter Name:-";

Page 65: C++ Assignment

C++ Assignment 2010

65

cin>>s[i].name;

cout<<endl<<"Enter Subject:- ";

cin>>s[i].subject;

cout<<endl<<"Enter Marks:- ";

cin>>s[i].marks;

cout<<endl<<"Enter Percent:- ";

cin>>s[i].per;

}

cout<<endl<<"Student Record";

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

{

cout<<endl<<"Rcord of student "<<i;

cout<<endl<<"Rollno ";

cout<<s[i].rollno;

cout<<endl<<"Name ";

cout<<s[i].name;

cout<<endl<<"Subject ";

cout<<s[i].subject;

cout<<endl<<"Marks ";

cout<<s[i].marks;

cout<<endl<<"Percent ";

cin<<s[i].per;

}

getch();

}

Page 66: C++ Assignment

C++ Assignment 2010

66

Output :-

Page 67: C++ Assignment

C++ Assignment 2010

67

Flowchart:-

//structure student delclear

Flowchart of main():-

START

struct student

STOP

STOP

student s1[10]

int n,i=0

i=0

INPUT: n

int rollno

int marks

char name[10]

char subject[10]

char marks

cahr per

Page 68: C++ Assignment

C++ Assignment 2010

68

False

True

False

True

for(i<n)

INPUT:

s[i].name

INPUT:

s[i].rollno

INPUT:

s[i].sub

INPUT:s[i].

per

INPUT:

s[i].marks

i=i+1

for(i<n)

i=i=0

PRINT:

s[i].name

PRINT:

s[i].rollno

PRINT:

s[i].sub

PRINT:

s[i].marks

PRINT:

s[i].per

i=i+1

START

Page 69: C++ Assignment

C++ Assignment 2010

69

Author Name:- Premendra Yadaw

Path:- D:\Angel \arrayofstruct.CPP

Unit:- II

Date:- 13/11/2010

Que 19:- Write a program to print students rollno,name,marks and percent using function & structure.

Algorithm:- [To print rollno,name,subject,marks & percent]

Here s[10] is array variable of structure student type

Step1: [Declare structure variable] student s[10];

Step2: int n , i=0

Step3: Write : “How many structure you want to creat”

Step4: Read : n

Step5: Write: “Enter Student imformation”

Step6: Reapeat step 7 ,8 for i=1 to n

Step7: s[i] =read()

Step8: i=i+1

Step9: Write: “Student Record”

Step10: Reapeat step 11 ,12 for i=1 to n

Step11: s[i] .display()

Step12: i=i+1

Step13: Exit

[Subalgorithm of function read() defination]

Step1: [Declare structure variable] student s1;

Step2: Write : "Enter Rollno "

Step3: Read : s1[i].rollno

Step4: Write : "Enter Name "

Step5: Read : s1[i].name

Step6: Write : "Enter Subject "

Step7: Read : s1[i].subject

Step8: Write : "Enter Marks"

Step9: Read : s1[i].marks

Step10: Write:"Enter Percent"

Step11: Read : s1[i].percent

Step12: Return s1

Step13: Exit

Page 70: C++ Assignment

C++ Assignment 2010

70

[Subalgorithm of function diplay(student s2) defination]

Step1: Write : "Student Record

Step2: Reapeat step 15 to 20 for i = 1 to n

Step3: Write : "Rollno= " , s1[i].rollno

Step4: Write : "Name= ", s1[i].name

Step5: Write : "subject= ",s1[i].subject

Step6: Write : “Marks=” , s1[i].marks

Step7: Write : “Percent=” , s1[i].percent

Step9: Exit

[Subalgorithm of structure student defination]

Here a is rollno,name,subject,marks & percent integer type

variable.

Step1: [Declare Structure] struct date

{

Step2: [Declare variable] int rollno

Step3: [Declare variable] char name[10]

Step4: [Declare variable] char subject[10]

Step5: [Declare variable] int marks

Step6: [Declare variable] int percent

}[End of struture definition]

Step7: Exit

Page 71: C++ Assignment

C++ Assignment 2010

71

Program:- /*print student imformation using function&structure*/

#include<iostream>

#include<conio.h>

struct student

{

int rollno;

char name[10];

char subject[20];

int marks;

float per;

};

student read()

{

student s1;

cout<<endl<<"Enter Rollno ";

cin>>s1.rollno;

cout<<endl<<"Enter Name:-";

cin>>s1.name;

cout<<endl<<"Enter Subject:- ";

cin>>s1.subject;

cout<<endl<<"Enter Marks:- ";

cin>>s1.marks;

cout<<endl<<"Enter Percent:- ";

cin>>s1.per;

return s1;

}

void display(student s2)

{

cout<<endl<<"Rollno ";

cout<<s2.rollno;

cout<<endl<<"Name ";

cout<<s2.name;

cout<<endl<<"Subject ";

cout<<s2.subject;

cout<<endl<<"Marks ";

cout<<s2.marks;

cout<<endl<<"Percent ";

cout<<s2.per;

Page 72: C++ Assignment

C++ Assignment 2010

72

}

void main()

{

clrscr();

student s[10];

int n;

cout<<"How many structure you want to creat:- ";

cin>>n;

int i=0;

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

{

cout<<"Enter imfomation of student "<<i;

s[i]=read();

}

cout<<endl<<"Student Record";

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

{

cout<<endl<<"Rcord of student "<<i;

display(s[i]);

}

getch();

}

Page 73: C++ Assignment

C++ Assignment 2010

73

Output:-

Flowchart:-

START

struct student

int rollno

char name[10]

char marks

float per

STOP

Page 74: C++ Assignment

C++ Assignment 2010

74

Flowchart of main()

False

True

//call function read()

False

True

//call function display()

START

student s1

int n

INPUT:n

int i=0

For(i<n)

PRINT:”Enter

student record”

s[i] = read()

i=i+1

i = 0

For(i<n

PRINT:”Stu-

dent Record”

display(s[i])

i = i +1

STOP

Page 75: C++ Assignment

C++ Assignment 2010

75

Flowchart of read()

Flowchart ofdisplay(student s2)

START

student s1

INPUT s1.rollno

s1.name

s1.marks

s1.per

STOP

START

PRINT s1.rollno

s1.name

s1.marks

s1.per

return s1

STOP

Page 76: C++ Assignment

C++ Assignment 2010

76

Author Name:- Premendra Yadaw

Path:- D:\ Angel \reverse.CPP

Unit:- II

Date:- 13/11/2010

Que 20:- Write a program to print revers any number and sum of those number.

Algorithm:- [To print revers any nubber & sum of number]

Here num,sum,m integer type veriable.

Step1: [Intilise variable] m=0, sum=0

Step3: Write : “Enter any number”

Step4: Read : num

Step5: Write: “Revers of enterned number is ”

Step6: Reapeat step 7 ,8 while (num>0)

Step7: m=num%10

Step8: Write : m

Step9: sum = sum + m

Step10: num=num/10

[End of while..loop]

Step11: Write : sum

Step12: Exit

Page 77: C++ Assignment

C++ Assignment 2010

77

Program:-

/*find revers of number & their sum*/

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int num,m=0,sum=0;

cout<<"Enter the number:- ";

cin>>num;

cout<<" ";

cout<<"Revers of enterned number is ";

while(num>0)

{

m=num%10;

cout<<m;

sum=sum+m;

num=num/10;

}

cout<<endl<<"sum"<<sum;

getch();

}

Output:-

Page 78: C++ Assignment

C++ Assignment 2010

78

Flowchart:- START

Int num,sum=0,i=0

INPUT : num

PRINT:”Revers”

num>10

m=num%10

sum=sum+m

PRINT: m

num=num/10

PRINT: sum

STOP

Page 79: C++ Assignment

C++ Assignment 2010

79

Author Name:- Premendra Yadaw

Path:- D:\Angel \func_over.CPP

Unit:- II

Date:- 13/11/2010

Que 21:- Write a program to find the area of rectangle,circle

and triangle using operator ovaerloading.

Algorithm:-[To find area of triangle,circle & rectangle]

Here a,b,c folat data type and s1,s2,s3 integer data type

Step1: [do..while statement ]

Do{

do

{

Write : “area main menu"

Write : "1.rectangl"

Write : "2.triangle"

Write : "3.cirle"

Write : "4.exit"

Write : "enter your choice"

[switch..case statement]

switch(choice)

{

case 1:

Write : "enter hight & weight"

[Input value of s1 and s2]

Read : s1,s2

[call function area(s1,s2)]

ar=area(s1,s2);

Write : "area is",ar

break

case 2:

Write : "enter 3 side ";

Read : s1,s2,s3;

[call function area(s1,s2,s3)]

ar=area(s1,s2,s3);

Write : "area is”

break;

case 3:

Page 80: C++ Assignment

C++ Assignment 2010

80

Write : "enter radios";

[Input value of s1]

Read : s1

[call function area(s1)]

ar=area(s1);

Write : "area is=",ar

break;

default:

Write : "wrong choice\n"

}

[End of Switch..case statement]

}While(choice>0 && choice<4)

[End of Do..while statement]

Step2: Exit

[Sub algorithm of function area(float a, float b)] Here a,b integer datatype

Step1: float area(float a,float b)

{

return a*b;

}

Step2: Exit

[Sub algorithm of function area(float a, float b,float c)] Here a,b integer datatype,and s,ar float datatype

Step1: float area(float a,float b,float c)

{

float s,ar;

s=(a+b+c)/2;

ar=sqrt(s*(s-a)*(s-b)*(s-c));

return ar;

}

Step2: Exit

[Sub algorithm of function area(float a)] Here a integer datatype

Step1: float area(float a)

return 3.1423*a*a;

Step2: Exit

Page 81: C++ Assignment

C++ Assignment 2010

81

Program:-

/*find area of rectangle,circle&triangle*/

#include<iostream.h>

#include<conio.h>

#include<math.h>

float area(float a,float b)

{

return a*b;

}

float area(float a,float b,float c)

{

float s,ar;

s=(a+b+c)/2;

ar=sqrt(s*(s-a)*(s-b)*(s-c));

return ar;

}

float area(float a)

{

return 3.1423*a*a;

}

int main()

{

clrscr();

int choice;float s1,s2,s3;

float ar;

do

{

cout<<"\n area main menu";

cout<<"1.rectangl"<<"\n";

cout<<"2.triangle" <<"\n";

cout<<"3.cirle" <<"\n";

cout<<"4.exit" <<"\n";

cout<<"enter your choice" ;

switch(choice)

{

case 1:

Page 82: C++ Assignment

C++ Assignment 2010

82

cout<<"enter hight & weight";

cin>>s1>>s2;

ar=area(s1,s2);

cout<<"area is"<<ar<<endl;

break;

case 2:

cout<<"enter 3 side ";

cin>>s1>>s2>>s3;

ar=area(s1,s2,s3);

cout<<"area is"<<ar<<endl;

break;

case 3:

cout<<"enter radios";

cin>>s1;

ar=area(s1);

cout<<"area is="<<ar<<endl;

break;

default:

cout<<"wrong choice\n";

}}

while(choice>0 && choice<4);

return 0;

getch();

}

Page 83: C++ Assignment

C++ Assignment 2010

83

Output :-

Page 84: C++ Assignment

C++ Assignment 2010

84

Author Name:- Premendra Yadaw

Path:- D:\Angel \returnbyrefer.CPP

Unit:- II

Date:- 13/11/2010

Que 22:- Write a program to find minimum value amoung two

number using return by refrence.

Algorithm:-[To find minimum value amoung two number ]

Here a,b,c folat data type and s1,s2,s3 integer data type

Step1: Write : “enter the value of x,y "

Step2: [Input value of x and y] Read : x , y

Step3: [Call the function] min(x,y)=200;

Step4: Write : "x=",x

Step5: Exit

[Sub algorithm of function & min(int &n1, int &n2 )] Here &n1,&n2 integer type refrence variables

Step1: int & min(int &n1 , int &n2)

{

if(n1<n2) then

return n1;

else

return n2

[End of if..else statement]

}

Step2: Exit

Page 85: C++ Assignment

C++ Assignment 2010

85

Program:-

/*print value big variable using return by refrence*/

#include<iostream.h>

#include<conio.h>

int &min(int &n1,int &n2);

void main()

{

int x,y;

cout<<"enter the value of x,y";

cin>>x>>y;

min(x,y)=200;

cout<<"x="<<x<<endl;

cout<<"y="<<y<<endl;

getch();

}

int & min(int &n1 , int &n2)

{

if(n1<n2)

return n1;

else

return n2

}

Output:-

Page 86: C++ Assignment

C++ Assignment 2010

86

Flowchart:-

//call function min(x,y)

Flowchart of min(int n1,int n2)

Else

True

START

INPUT : x,y

int x,y

min(x,y) = 200

PRINT : x,y

STOP

START

return n1

If(n1<n2

return n2

STOP

Page 87: C++ Assignment

C++ Assignment 2010

87

Author Name:- Premendra Yadaw

Path:- D:\Angel\letter_case.CPP

Unit:- II

Date:- 13/11/2010

Que 23:- Write a program to convert lowercase string into

uppercase string using the concept of function with

array.

Algorithm:-[To convert lowercase string into uppercase string ]

Here s character data type that contain of character value.

Step1: [Declare character array] char s[80]

Step2: Write : “Enter any string “

Step3: [Input string] Read : s

Step4: [call the function] printl(s)

Step5: Exit

[Sub algorithm of function printl(char *str)] Here *str is character type pointer variable that stores address of

string s.

Step1: int printl (int &n1 , int &n2)

{

Step2: [Declare integer type variable] int t

Step3: Reapet step 4,5 For t = 0 to str[t]!=‟\0‟

Step4: str[i] = toupper(str[t])

Step5: [Increament counter] t=t+1

[End of for loop statement]

}[End of function definition]

Step6: Exit

Page 88: C++ Assignment

C++ Assignment 2010

88

Program:-

/*convert lowercase string into uppercase */

#include<iostream.h>

#include<conio.h>

#include<ctype.h>

void print_1(char *str) ;

int main()

{

char s[50];

cout<<"enter the string"<<endl;

cin.getline(s,80);

print_1(s);

cout<<s;

return 0;

}

void print_1(char *str)

{

int t;

for(t=0;str[t]!='\0';t++)

{

str[t]=toupper(str[t]);

}

}

Output:-

Page 89: C++ Assignment

C++ Assignment 2010

89

Flowchart:-

//call function printl()

Flowchart of printl(char * str)

False

True

START

char s[80]

INPUT: s

Printl(s)

PRINT: s

STOP

START

int i = 0

If(str[i]!

= „/0‟

Str[i] =toupper(str[t])

int i = i+1

STOP

Page 90: C++ Assignment

C++ Assignment 2010

90

Author Name:- Premendra Yadaw

Path:- D:\Angel \palindrome.CPP

Unit:- II

Date:- 13/11/2010

Que 24:- Write a program to find given string is Palindrome

or not.

Algorithm:-[To find string is palindrome or not ]

Here string is character array that contain combination of

characters and i,j,l ,flag integer datatype.

Step1: Write : “Enter any string ( max 79 characters )”

Step2: [Input string] Read : string

Step3: Repeat step 4 For l= 0 to str[l]!=‟\0‟

Step4: flag=1

[End of For loop]

Step5: Repeat step 6 ,7for i=1 to i<l\2 and j=l-1

Step6: If (string[i] != string[j]) Then

Flag=0

Break

Step7:[Increase counter] i=i+1

[Decrease counter] j=j-1

[End of If statement]

[End of For Loop statement]

Step8: If (flag) Then

Write: “String is Palindrone”

Else

Write “Sring is not Palindrome”

[End of If ..Else statement]

Step9: Exit

Page 91: C++ Assignment

C++ Assignment 2010

91

Program:-

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int i,j,l,flag;

char string[80];

cout<<"enter string";

cin.getline(string,80);

for(l=0;string[l] !='\o';l++)

flag=1;

for( i=0,j=l-1;i<l/2;i++,j--)

{

if(string[i]!=string[j])

{

flag=1;

break;

}

}

if(flag)

cout<<"it is palindrom" ;

else

cout<<"it is not palindrom";

getch();}

Output:-

Page 92: C++ Assignment

C++ Assignment 2010

92

Flowchart:-

False

True

False

True

False

True

True

Else

START

int i, j, flag

char string[80]

INPUT: string

for(i<l/2)

l = 0

l = l+1

int i=0, j=l-1

for(i<l/2)

If(string[i]

!string[j]

Flag=0;break

if(flag)

STOP

i=i+1

PRINT:”not

Palindrome PRINT:”Palindrome

Page 93: C++ Assignment

C++ Assignment 2010

93

Author Name:- Premendra Yadaw

Path:- D:\Angel \factorial.CPP

Unit:- II

Date:- 13/11/2010

Que 25:- Write a program to find factorial of given number using

Return statement.

Algorithm:-[To find factorial of given number ]

Here n is integer data type that contain integer value.

Step1: Write : “Enter any Number”

Step2: [Input string] Read : n

Step3: [call function fect(n) ]

Write : “The Factorial of given number is “, fact(n)

Step4: Exit

[Sub algorithm of function fact( int i)]

Here result is long datatype and j is counter variable.

Step1: long fact (int i)

{

Step2: [Declare long type variable result ] int result

Step3: If (n==0) Then

result =1

Else

result = 1 and goto step 4

Step4: Repeat step 5,6 for j=2 to n

Step5: result = result*j

Step6: [Increament counter] j=j+1

[End of For loop statement]

[End of function definition]

Step7: Exit

Page 94: C++ Assignment

C++ Assignment 2010

94

Program:-

/*find factorial of given number*/

#include<iostream.h>

#include<conio.h>

long fact(int n)

{

long result;

if(n==0)

result=1;

else

{

result=1;

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

result=result*i;

}

return result;

}

void main()

{

clrscr();

int n;

cout<<"enter the number";

cin>>n;

cout<<"factorial is: " <<fact(n)<<endl;

getch();

}

Output:-

Page 95: C++ Assignment

C++ Assignment 2010

95

Flowchart:-

//Call function fact()

Flowchartof fact(int i)

True Else

False True

START

int n

INPUT: n

PRINT:”Factorial”

fact(n)

STOP

START

long result

If

(n==0)

result =1 result =2

For(i<=

2) Result=result*i

int i

i=i+1

return result

STOP

Page 96: C++ Assignment

C++ Assignment 2010

96

Author Name:- Premendra Yadaw

Path:- D:\Angel \classstudent.CPP

Unit:- IV

Date:- 13/11/2010

Que 26:- Write a program to find Name and Rollnumber student

using class & object.

Algorithm:-[To find Name and Rollnumber ]

Here s1,s2 is object of sudent class.

Step1: [Create object of student class] student s1,s2

Step2: [Call member function of student class]

s1.setdata(1,”Mohanlal”)

s2.setdata(10,”sohanlal”)

Step3: Write : “Student Details”

Step4: [Call member function of student class]

s1.showdata()

s2.showdata()

Step5: Exit

[Sub algorithm of definition of class student] Step1: class student

{

Step2: [Declare private data member of class student ]

private : int rollno

char name[10]

Step3: [Declare public member function of class student ]

public :

void setdata(int rollnoin,char namein)

{ rollno=rollnoin

strcpy(name,namein)

}[End of function definition]

void showdata()

{Write : “Rollno”,rollno

Write : “Name”,name

} [End of funtion definition]

}[End of class definition]

Step4: Exit

Page 97: C++ Assignment

C++ Assignment 2010

97

Program:-

/*print students imformation*/

#include<conio.h>

#include<string.h>

#include<stdio.h>

class student

{

private:

int rollno;

char name[10];

public:

void setdata(int rollno_in,char name_in[10])

{

rollno=rollno_in;

strcpy(name,name_in);

}

void showdata()

{

cout<<"RollNo "<<rollno<<"\t";

cout<<" Name "<<name<<endl;

}

};

void main()

{

clrscr();

student s1;

student s2;

s1.setdata(1,"Mohanlal");

s2.setdata(10,"Sohanlal");

cout<<" Student Deatails "<<endl;

s1.showdata();

s2.showdata();

getch();

}

Page 98: C++ Assignment

C++ Assignment 2010

98

Output:-

Page 99: C++ Assignment

C++ Assignment 2010

99

Author Name:- Premendra Yadaw

Path:- D:\Angel \classdate.CPP

Unit:- IV

Date:- 13/11/2010

Que 27:- Write a program to print date using class and object.

Algorithm:-[To Print date]

Here d1,d2,d3 is object of date class.

Step1: [Create object of date class] date d1,d2,d3

Step2: [Call member function of date class]

d1.setdate(25,10,2010)

d2.setdate(15,8,2010)

d3.setdate(07,12,2010)

Step3: Write : “Independence day date”

Step4: [Call member function of date class]

d2.show()

Step5: Write : “Today date”

Step6: [Call member function of date class] d1.show()

Step7: Write : “Exam date”

Step8: [Call member function of date class] d3.show()

Step9: Exit

[Sub algorithm of definition of class date] Step1: class date

Step2: [Declare private data member of class date ]

private : int day,month,year

Step3: [Declare public member function of class date]

public : void setdate(int dayin,int monthin,int year)

{day=dayin

month=monthin

year=yearin

}[End of function definition]

void show()

{Write : day,”-“,month,”-“,year

}[End of funtion definition]

}[End of class definition]

Step4: Exit

Page 100: C++ Assignment

C++ Assignment 2010

100

Program:-

/*prit day,month year*/

#include<iostream.h>

#include<conio.h>

class date

{

int day,month,year;

public:

void setdate(int dayin,int monthin,int yearin);

void show();

};

void date::setdate(int dayin,int monthin,int yearin)

{

day=dayin;

month=monthin;

year=yearin;

}

void date::show()

{

cout<<day<<"-"<<month<<"-"<<year<<endl;

}

void main()

{

clrscr();

date d1,d2,d3;

d1.setdate(25,10,2010);

d2.setdate(15,8,2010);

d3.setdate(7,12,2010);

cout<<" Independance day date "<<"\t";

d2.show();

cout<<" Today date "<<"\t";

d1.show();

cout<<" Exam date "<<"\t";

d3.show();

getch();

}

Page 101: C++ Assignment

C++ Assignment 2010

101

Output:-

Page 102: C++ Assignment

C++ Assignment 2010

102

Author Name:- Premendra Yadaw

Path:- D:\Angel \classpassval.CPP

Unit:- IV

Date:- 13/11/2010

Que 28:- Write a program to print polar as feet-inch format

Using the concept passing object as pass by value.

Algorithm:-[To Print Polar as feet-inch]

Here d1,d2,d3 is object of polar class.

Step1: [Create object of polar class] date d1,d2,d3

Step2: [Call member function of date class]

d2.init(11.0,6.25)

d1.read()

Step3 : Write : “d1 = “

Step4 : [Call member function of polar class]

d1.show()

Step5 : Write : “d2 = ”

Step6 : [Call member function of polar class]

d2.show()

Step7 : [Call member function of polar class]

D3.add()

Step8 : Write : “d1+d2”

Step9 : d3.show()

Step10 : Exit

[Sub algorithm of definition of class polar]

Step1: class polar

{

Step2: [Declare private data member of class polar]

private :

float feet

float inches

Step3: [Declare public member function of class date]

public :

void init(float fit,float inch)

{

feet = fit

Page 103: C++ Assignment

C++ Assignment 2010

103

inches = inch

} [End of function definition]

void read()

{

Write : “Enter feet “

Read : feet

Write : “Enter inches”

Read : inches

} [End of funtion definition]

void show()

{

Write : feet, ”-“ ,inches

} [End of funtion definition]

void add(polar d1,polar d2)

{

feet=d1.feet + d2.polar

inches=d1.inches + d2.inches

while(inhes >= 12.0)

{

feet = feet + 1.0

inches = inhes – 12.0

} [End of while loop statement]

} [End of funtion definition]

}[End of class definition]

Step4: Exit

Page 104: C++ Assignment

C++ Assignment 2010

104

Program:- /*find polar inch &feet*/

#include<iostream.h>

#include<conio.h>

class polar

{

private:

float feet;

float inches;

public:

void init(float fit,float inch)

{

feet=fit;

inches=inch;

}

void read()

{

cout<<" Enter Feet:- ";

cin>>feet;

cout<<endl<<" Enter Inches:- ";

cin>>inches;

cout<<endl;

}

void show()

{

cout<<feet<<"-"<<inches<<"\n";

}

void add(polar d1,polar d2)

{

feet=d1.feet+d2.feet;

inches=d1.inches+d2.inches;

while(inches>=12.0)

{

feet=feet+1.0;

inches=inches-12.0;

}

}

};

void main()

Page 105: C++ Assignment

C++ Assignment 2010

105

{

clrscr();

polar d1,d2,d3;

d1.init(11.0,6.25);

d2.read();

cout<<" d1 = "<<"\t";

d1.show();

cout<<" d2 = "<<"\t";

d2.show();

d3.add(d1,d2);

cout<<" d1+d2 = ";

d3.show();

getch();

}

Output:-

Page 106: C++ Assignment

C++ Assignment 2010

106

Author Name:- Premendra Yadaw

Path:- D:\Angel \classpassref.CPP

Unit:- IV

Date:- 13/11/2010

Que 29:- Write a program of transfer amount from one account

to another account using concept of pass object as pass

by refrence.

Algorithm:-[To transfer amount from one account to anoth account]

Here cc1,cc2,cc3 is object of account class.

Step1 : [Create object of class account] account cc1,cc2,cc3

Step2 : [Declare variable] int transmoney

Step3 : [Call member function of date class]

cc1.getdata()

cc2.setdata(10)

cc3.setdata(20,750.75)

Step4 : Write : “Account Imformation“

Step5 : [Call member function of account class]

cc1.display()

cc2.display()

cc3.display()

Step6 : Write : “How many to amount transfer from cc3 to cc1 ”

Step7 : Read : transmoney

Step8 : [Call member function of account class]

Cc3.money(cc1,transmoney)

Step9 : Write: “Update Account after transformation”

Step10 : [Call member function account class]

cc1.display()

cc2.display()

cc3.display ()

Step11 : Exit

[Sub algorithm of definition of class account] Step1: class account

{

Page 107: C++ Assignment

C++ Assignment 2010

107

Step2: [Declare private data member of class polar]

private :

int accno

float balance

Step3: [Declare public member function of class date]

public :

void getdata()

{

Write : “Enter Account number”

Read : accno

Write : “Enter the balance”

Read : balaance

} [End of function definition]

void setdata(int accin)

{

accno=accin

balance=0

} [End of funtion definition]

void display()

{

Write : “Account Number“ , accno

Write :“Balance” , balance

} [End of funtion definition]

void money(account &cc, float amount)

{

balance=balance-amount

cc.balance = cc.balance + amount

} [End of funtion definition]

}[End of class definition]

Step4: Exit

Page 108: C++ Assignment

C++ Assignment 2010

108

Program:-

/*print account balance account number*/

#include<iostream.h>

#include<conio.h>

class account

{

private:

int accno;

float balance;

public:

void getdata()

{

cout<<"Enter the account number:- ";

cin>>accno;

cout<<endl<<"Enter the balance:- ";

cin>>balance;

cout<<endl;

}

void setdata(int accin)

{

accno=accin;

balance=0;

}

void setdata(int accin,float balancein)

{

accno=accin;

balance=balancein;

}

void display()

{

cout<<"Account number "<<accno<<endl;

cout<<"Balance "<<balance<<endl;

}

void money(account &cc,float amount);

};

void account::money(account &cc,float amount)

{

Page 109: C++ Assignment

C++ Assignment 2010

109

balance=balance-amount;

cc.balance=cc.balance+amount;

}

void main()

{

clrscr();

int transmoney;

account cc1,cc2,cc3;

cc1.getdata();

cc2.setdata(10);

cc3.setdata(20,750.75);

cout<<"Account Imformation"<<endl;

cout<<endl;

cc1.display();

cc2.display();

cc3.display();

cout<<endl;

cout<<"\n"<<"How Many to transfer from cc3 to cc1 :- ";

cin>>transmoney;

cout<<endl;

cc3.money(cc1,transmoney);

cout<<"Update account after transfer"<<endl;

cout<<endl;

cc1.display();

cc2.display();

cc3.display();

getch();

}

Page 110: C++ Assignment

C++ Assignment 2010

110

Output:-

Page 111: C++ Assignment

C++ Assignment 2010

111

Author Name:- Premendra Yadaw

Path:- D:\Angel \classpaspointer.CPP

Unit:- IV

Date:- 13/11/2010

Que 30:- Write a program of transfer amount from one account

to another account using concept of pass object as pass

by pointer.

Algorithm:-[To transfer amount from one account to anoth account]

Here cc1,cc2,cc3 is object of account class.

Step1 : [Create object of class account] account cc1,cc2,cc3

Step2 : [Declare variable] int transmoney

Step3 : [Call member function of date class]

cc1.getdata()

cc2.setdata(10)

cc3.setdata(20,750.75)

Step4 : Write : “Account Imformation“

Step5 : [Call member function of account class]

cc1.display()

cc2.display()

cc3.display()

Step6 : Write : “How many to amount transfer from cc3 to cc1 ”

Step7 : Read : transmoney

Step8 : [Call member function of account class]

Cc3->money(cc1,transmoney)

Step9 : Write: “Update Account after transformation”

Step10 : [Call member function account class]

cc1.display()

cc2.display()

cc3.display ()

Step11 : Exit

[Sub algorithm of definition of class account] Step1: class account

{

Page 112: C++ Assignment

C++ Assignment 2010

112

Step2: [Declare private data member of class polar]

private :

int accno

float balance

Step3: [Declare public member function of class date]

public :

void getdata()

{

Write : “Enter Account number”

Read : accno

Write : “Enter the balance”

Read : balaance

} [End of function definition]

void setdata(int accin)

{

accno=accin

balance=0

} [End of funtion definition]

void display()

{

Write : “Account Number“ , accno

Write :“Balance” , balance

} [End of funtion definition]

void money(account &cc, float amount)

{

balance=balance-amount

cc->balance = cc->balance + amount

} [End of funtion definition]

}[End of class definition]

Step4: Exit

Page 113: C++ Assignment

C++ Assignment 2010

113

Program:-

#include<iostream.h>

#include<conio.h>

class account

{

private:

int accno;

float balance;

public:

void getdata()

{

cout<<"Enter the account number:- ";

cin>>accno;

cout<<endl<<"Enter the balance:- ";

cin>>balance;

cout<<endl;

}

void setdata(int accin)

{

accno=accin;

balance=0;

}

void setdata(int accin,float balancein)

{

accno=accin;

balance=balancein;

}

void display()

{

cout<<"Account number "<<accno<<endl;

cout<<"Balance "<<balance<<endl;

}

void money(account *cc,float amount);

};

void account::money(account *cc,float amount)

{

balance=balance-amount;

cc->balance=cc->balance+amount;

Page 114: C++ Assignment

C++ Assignment 2010

114

}

void main()

{

clrscr();

int transmoney;

account cc1,cc2,cc3;

cc1.getdata();

cc2.setdata(10);

cc3.setdata(20,750.75);

cout<<"Account Imformation"<<endl;

cout<<endl;

cc1.display();

cc2.display();

cc3.display();

cout<<endl;

cout<<"\n"<<"How Many to transfer from cc3 to cc1 :- ";

cin>>transmoney;

cout<<endl;

cc3->money(cc1,transmoney);

cout<<"Update account after transfer"<<endl;

cout<<endl;

cc1.display();

cc2.display();

cc3.display();

getch();

}

Page 115: C++ Assignment

C++ Assignment 2010

115

Output:-

Page 116: C++ Assignment

C++ Assignment 2010

116

Author Name:- Premendra Yadaw Path:- D:\Angel \quardic.CPP

Unit:- II

Date:- 13/11/2010

Que 31:- Write a program find the root of quadratic equation.?

Algorithm:- [ to find the root of quadratic equation] a,b,c ,x and x1 are a

simple float data type. There is find two value, positive and negative.

Step1:[for user input]Read: a,b,c

Step2:[calculation part] Set x:= b+√( b2- 4*a*c)/2*a

Step3: Set x1:= b-√( b2- 4*a*c)/2*a

Step4: Write: x , x1.

Step5:Exit.

/*A program to find the root of quadratic equation*/

Program:-

#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

{

int a,b,c;

float temp,x;

clrscr();

cout<<"Enter a:-";

cin>>a;

cout<<"Enter b:-";

cin>>b;

cout<<"Enter c:-";

cin>>c;

x=(b+sqrt(((b*b)-(4*a*c))))/2*a;

temp=(b-sqrt(((b*b)-(4*a*c))))/2*a;

cout<<"positive quadratic value"<<x<<endl;

Page 117: C++ Assignment

C++ Assignment 2010

117

cout<<"negative quadratic value"<<temp;

getch();

}

Output:-

Flow-chart:-

START

a,b,c,x,x1

a,b,c

x= b+√( b2- 4*a*c)/2*a

x1= b-√( b2- 4*a*c)/2*a

x,x1

STOP

Page 118: C++ Assignment

C++ Assignment 2010

118

Author Name:- Premendra Yadaw Path:- D:\ Angel \reverse.CPP

Unit:- II

Date:- 25/10/2010

Que 32:- Write a program to reverse the given no. and check

the no. is palindrome or not. ?

Algorithm:-[To reverse the given no. and check the is palindrome] Number,

Save and Result are integer data type. This algorithm Make For reverse the given

no. Number and store the result in Result.

Step1:-[Initialize] Set temp,Save, Number, Result: =0

Step2:- [Input the value] Read: Number

Step3:- Set Save:= Number

Step4:- Set temp: = Number/10,

Result=Result*10 + temp,

Number: = Number/10

Step5:- Repeat step 4 and 5 while Number! =0

[End of looping structure]

Step6:- write: Result

Step7:- if Save = Result then

Write: „no. is palindrome‟

Else

Write: „no. is not palindrome‟

[End of if structure]

Step8:- Exit.

Page 119: C++ Assignment

C++ Assignment 2010

119

Program:-

/* To reverse the given no. and check the is palindrome */

#include<iostream.h>

#include<conio.h>

void main ()

{

Int t,s,n,sum=0;

clrscr();

cout<<”Enter any number.”;

cin>>n;

s = n;

do

{

t=n%10;

sum=sum*10+t;

n=n/10;

}while(n!=0);

cout<<”Revers of Number “<<sum;

if(s== sum)

cout<<endl<<”Number is palindrome”;

else

cout<<endl<<”Number is not palindrome”;

getch();

}

Output:-

Page 120: C++ Assignment

C++ Assignment 2010

120

Flowchart:-

s,n,sum=0,t

START

s = n

While(n!= 0)

sum

If(s=sum) No. is palindrome

No. is not palindrome

STOP

t = n%10,

sum =sum*10+t,n=n/10

Page 121: C++ Assignment

C++ Assignment 2010

121

Author Name:- Premendra Yadaw Path:- D:\ Angel \series1.CPP

Unit:- II

Date:- 27/10/2008

Que 33:- Write a program to print two mathematical series:-

a) 1+(1+2)+(1+2+3)+…..+n=

b) 1+1/9+1/25+….+n= a)

Algorithm:- [to calculate the specific mathematical series] sum1,sum2,i and

j are simple integer variable.

Step1: [initialize] sum1=0,sum2=0,term,i=1,j=1.

Step2:[For user input]Read: term.

Step3: Repeat Step 4 to 8 while (i<=term)

Step4: Repeat Step 5 to 6 while (j<=i)

Step5: Set sum1:=sum1+j.

Step6:[Increment counter] Set j:=j+1

[End of inner looping structure]

Step7: Set sum2:=sum2+sum1 and sum1=0

Step8:[Increment counter] Set i:=i+1.

[End of outer loop structure]

Step9: Write: sum2

Step10:Exit.

Page 122: C++ Assignment

C++ Assignment 2010

122

Flow-chart:-

If(j<=i)

s1=s1+j

j=j+1

s2=s2+s1

i=i+1

STOP

sum2

if(i<=t)

then

START

s1=0,s2=0,i=1,j=1

t

Page 123: C++ Assignment

C++ Assignment 2010

123

/*To print the mathematical series*/

Pogram:-

#include<iostream.h>

#include<conio.h>

void main()

{

int i,j,sum1=0,sum2=0,n;

clrscr();

cout<<"enter any no.";

cin>>n;

cout<<"1+(1+2)+(1+2+3)+___+n= ";

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

{

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

{

sum1=sum1+j;

}

sum2=sum2+sum1;

sum1=0;

}

cout<<sum2;

getch();

}

Output:-

Page 124: C++ Assignment

C++ Assignment 2010

124

b) Author Name:- Premendra Yadaw

Path:- D:\ Angel \series2.CPP

Unit:- II

Date:- 27/10/2008

Algorithm:-[to calculate specific mathematical series]sum ,i,n

are simple float type data.

Step1:[Initialze] sum=0,i=1,n

Step2:[for user input] Read:n.

Step3: Repeat Step 4 to 5 While (i<=n)

Step4: Set sum:=sum+1/(i*i).

Step5:[Incremental counter] i=i+1.

[End of looping structure]

Step6: Write: sum

Step7: Exit.

Flow-chart:-

START

sum=0,i=1

n

if(i<=n)

sum=sum+1/(i*i)

i=i+1

sum

STOP

Page 125: C++ Assignment

C++ Assignment 2010

125

/*To print the mathematical series*/ #include<iostream.h>

#include<conio.h>

void main()

{

float i,j,sum=0,n;

clrscr();

cout<<"Enter any no.";

cin>>n;

cout<<"1+1/9+1/25+1/49+____+n =";

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

{

sum=sum+1/(i*i);

i++;

}

cout<<sum;

getch();

}

Output:-

Page 126: C++ Assignment

C++ Assignment 2010

126

Author Name:- Premendra Yadaw

Path:- J:\ Angel \bigsmall.CPP

Unit:- II

Date:- 26/10/2008

Que 34:- Write a program to find out the biggest no. and smallest

no. from the given three no.?

Algorithm:- [find the smallest and biggest no.from the given three no.]

Frt,sec and trd are simple integer data type.This variables

are use for store the user input.This algorithm find the smallest

and biggest no. in the user input.

Step1:- [for user input] Read: frt,sec,trd.

Step2:-[1st condition for find biggest no.]if (frt>sec) then

Step3:- if (frt>trd ) then

Write: „1st no. is biggest no.‟

Else

Write: „3rd

no. is biggest no.‟

[end of inner if structure]

[end of if stucture]

Step4:- if (sec>trd) then

Write: „2nd

no. is biggest no.‟

Else

Write: „3rd

no. is biggest no.‟

[end of if stucture]

Step5:-[2nd

condition for find smallest no.] if (frt<sec) then

Step6:- if (frt<trd ) then

Write: „1st no. is smallest no.‟

Else

Write: „3rd

no. is smallest no.‟

[end of inner if structure]

[end of if stucture]

Step7:- if (sec<trd) then

Write: „2nd

no. is smallest no.‟

Else

Write: „3rd

no. is smallest no.‟

[end of if stucture]

Step8:- Exit.

Page 127: C++ Assignment

C++ Assignment 2010

127

Flow-Chart:-

If(a>c)

b is big

a is big

c is big

If(b>c)

START

a,b,c

If(a>b)

If(a<c) If(a<b) If(b<c)

c is big

a is small

c is small

b is small

c is small

STOP

Page 128: C++ Assignment

C++ Assignment 2010

128

/*Find the smallest and biggest no. from the given three no.*/

#include<iostream.h>

#include<conio.h>

void main()

{

int frs,snd,trd;

clrscr();

cout<<"Enter 3 no."<<endl;

cin>>frs>>snd>>trd;

/*condition for greatest no.*/

if(frs>snd)

{

if(frs>trd)

{

cout<<"\nfirst no. is greater";

}

else

{cout<<"\nthird no. is greater";}

}

else if(snd>trd)

{

cout<<"\nsecond no. is greater";

}

else

{

cout<<"\nthird no. is greater";

}

/*condition for smallest no.*/

if(frs<snd)

{

if(frs<trd)

{

cout<<"\nfirst no. is smallest";

}

else

{cout<<"\nthird no.is smallest";}

}

Page 129: C++ Assignment

C++ Assignment 2010

129

else if(snd<trd)

{

cout<<"\nsecond no. is smallest";

}

else

{

cout<<"\nthird no. is smallest";

}

getch();

}

Output:-

Page 130: C++ Assignment

C++ Assignment 2010

130

Author Name:- Premendra Yadaw

Path:- D:\ Angel \empage.CPP

Unit:- IV

Date:- 26/10/2008

Que.35 Write a function with take two variable of structure type employee.

Function should Return true if 1’st employee greater then other wise

it should return flash declareTrue anf false int constant using enum

data type.

Algorithm:- Employee(object e2,e1)

This algorithm writes for comparing between two objects value.

Step1: create 2 objects of procedure1 e1,e2.

Step2: Scanning all detail of employee in both objects.

a) Read: e1.name, e1.salary, e1.age, e1.sex.

b) Read: e2.name, e2.salary, e2.age, e2.sex.

Step3: [Procedure2 calling] CALL: Set k:=agecheak(e1,e2)

Step4: Print: “1st employee oldest then 2nd

employee”

Step5: if (k==0) then

Step6: Print: “true”

Step7: else if (k==1) then

Step8: Print: “false”

[End of if structure]

Step9: Exit.

Procedure1:- STRUCTURE(name, salary, age, sex)

These procedures write for binding different data type in one block.

Step1:[initialize] name, salary, age, sex.

Step2: Exit.

Procedure2:- agecheak(object e1,object e2)

These procedures accept object type value. This algorithm wrires for

cheak the age of employee who is oldest?

Step1: [initialize] true:=0, false:=1.

Step1: if (e1.age>e2.age) then

Step2: return true.

Step3: else then return false.

Page 131: C++ Assignment

C++ Assignment 2010

131

Step4: Exit.

#include<iostream.h>

#include<conio.h>

struct emp

{

char name[30],add[30];

int age,sal;

char sex;

};

enum{true,false};

void main()

{

int check(emp e1,emp e2);

emp e,ee;

int temp;

clrscr();

cout<<"\n********1st Object*********";

cout<<"\nEnter the name of employe:";

cin.getline(e.name,30);

cout<<"\nEnter the age:";

cin>>e.age;

cout<<"\nEnter the sex:";

cin>>e.sex;

cout<<"\nEnter the salary:";

cin>>e.sal;

cout<<"\nEnter the address:";

cin.getline(e.add,30);

cout<<"\n********2nd Object*********";

cout<<"\nEnter the name of employe:";

cin.getline(ee.name,30);

cout<<"\nEnter the age:";

cin>>ee.age;

cout<<"\nEnter the sex:";

cin>>ee.sex;

cout<<"\nEnter the salary:";

cin>>ee.sal;

cout<<"\nEnter the address:";

cin.getline(ee.add,30);

Page 132: C++ Assignment

C++ Assignment 2010

132

temp=check(e,ee);

if(temp==0)

cout<<"\n1st employe oldest then 2nd employe";

else

cout<<"\n2nd employe oldest then 1st employe";

getch();

}

//function defination

int check(emp e1,emp e2)

{

if(e1.age>e2.age)

return(true);

else

return(false);

}

OUTPUT:-

Page 133: C++ Assignment

C++ Assignment 2010

133

Author Name:- Premendra Yadaw

Path:- D:\ Angel \Fibon.CPP

Unit:- II

Date:- 13/11/2010

Que 35:- Write a program to print Fibonacci series and sum of

series?

Algorithm:- [To print Fibonacci series and sum of series]

TERM , SUM ,a ,b ,c ,i are an integer data type.TERM is use

For term of the series and SUM is use for addition of all these

Series.

Step1: [Initialize]a := 0, b:=1,c:=0,Sum:=0,i=3.

Step2: Read: TERM.

Step3: Write: a,b.

Step4: Set SUM:=a+b

Step5: Repeat step 6 to 7 while i<=TERM

Step6: Set c:=a+b and SUM=SUM+c.

Step7: [Incremental counter]i=i+1

[End of looping structure]

Step8: Write: SUM

Step9: Exit.

Page 134: C++ Assignment

C++ Assignment 2010

134

Flow-Chart:-

While(i<=n)

c=a+b

sum=sum+c

sum=a+b

a,b

Term,a=0,b=1,c=0,

Sum=0,i=3

c

STOP

a=b, b=c,

i=i+1

sum

START

Page 135: C++ Assignment

C++ Assignment 2010

135

/*Program to print Fibonacci series with sum of these series*/

#include<iostream.h>

#include<conio.h>

void main()

{

int n,a=0,b=1,c=0,i,sum;

clrscr();

cout<<"Enter any number\n";

cin>>n;

cout<<"Fibonaccies series\n";

cout<<a<<endl<<b<<endl;

sum=a+b;

i=3;

while(i<=n)

{

c=a+b;

sum=sum+c;

cout<<c<<endl;

a=b;

b=c;

i++;

}

cout<<"\nsum="<<sum;

getch();

}

Output:-

Page 136: C++ Assignment

C++ Assignment 2010

136

Author Name:- Premendra Yadaw

Path:- D:\ Angel \vowel.CPP

Unit:- II

Date:- 13/11/2010

Que 36:- Write a program to count the vowel ,consonants ,digits, Tab,space and special character in a string.

Algorithm:- [To count the vowel,consonanats,digits,tabspace,space,special

Character in string]

Here str[20] is character datatype.

Step1: [Declare & Initialize variable]

int vowel=0 ,tspace=0,st=0

space = 0, con=0,num=0

Step2: Write : “Enter any string”.

Step3: Read : str

Step4: Set SUM:=a+b

Step5: Repeat step 6 to 12 for i=0 to str[i]!=‟\0‟

Step6: if(str[i]=='a'||str[i]=='i'||str[i]=='e'||str[i]=='u'||str[i]=='o'

str[i]=='A'||str[i]=='I'||str[i]=='E'||str[i]=='U'||str[i]=='O‟) Then

vowel++

Step7: if(str[i]==' ') Then

space++

Step8: if(str[i]==' ') Then

tspace++

Step9: if(str[i]=='0'||str[i]=='1'||str[i]=='2'||str[i]=='3'||str[i]=='4'

||str[i]=='5'||str[i]=='6'||str[i]=='7'||str[i]=='8'||str[i]=='9') Then

num++;

Step 10: if(str[i]=='b'||str[i]=='c'||str[i]=='d'||str[i]=='f'||str[i]=='g'

||str[i]=='h'||str[i]=='l'||str[i]=='j'||str[i]=='k'||str[i]=='m'

||str[i]=='n'||str[i]=='p'||str[i]=='q'||str[i]=='r'||str[i]=='s'

||str[i]=='t'||str[i]=='v'||str[i]=='w'||str[i]=='x'||str[i]=='y'

||str[i]=='z'||

str[i]=='B'||str[i]=='C'||str[i]=='D'||str[i]=='F'||str[i]=='G'

||str[i]=='H'||str[i]=='J'||str[i]=='K'||str[i]=='L'||str[i]=='M'

||str[i]=='N'||str[i]=='P'||str[i]=='Q'||str[i]=='R'||str[i]=='S'

||str[i]=='T'||str[i]=='V'||str[i]=='W'||str[i]=='X'||str[i]=='Y'

||str[i]=='Z') Then

con++;

Page 137: C++ Assignment

C++ Assignment 2010

137

Step11: if(str[i]=='b'||str[i]=='c'||str[i]=='d'||str[i]=='f'||str[i]=='g'

||str[i]=='h'||str[i]=='l'||str[i]=='j'||str[i]=='k'||str[i]=='m'

||str[i]=='n'||str[i]=='p'||str[i]=='q'||str[i]=='r'||str[i]=='s'

||str[i]=='t'||str[i]=='v'||str[i]=='w'||str[i]=='x'||str[i]=='y'

||str[i]=='z'||

str[i]=='B'||str[i]=='C'||str[i]=='D'||str[i]=='F'||str[i]=='G'

||str[i]=='H'||str[i]=='J'||str[i]=='K'||str[i]=='L'||str[i]=='M'

||str[i]=='N'||str[i]=='P'||str[i]=='Q'||str[i]=='R'||str[i]=='S'

||str[i]=='T'||str[i]=='V'||str[i]=='W'||str[i]=='X'||str[i]=='Y'

||str[i]=='Z') Then

Write : “\t”

Else :

st++;

Step12: [Incremental counter]i=i+1

[End of looping structure]

Step13: Exit.

Page 138: C++ Assignment

C++ Assignment 2010

138

Program:- /*find number of vowel,conso,tspace,space,specialchar*/

#include<conio.h>

#include<iostream.h>

void main()

{

clrscr();

char str[20];

int i,vowel=0,space=0,tspace=0,st=0,con=0,num=0;

cout<<"Enter any sring ";

cin.getline(str,20);

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

{

if(str[i]=='a'||str[i]=='i'||str[i]=='e'||str[i]=='u'||str[i]=='o')

{

vowel++;

}

if(str[i]==' ')

{

space++;

}

if(str[i]==' ')

{

tspace++;

}

if(str[i]=='0'||str[i]=='1'||str[i]=='2'||str[i]=='3'||str[i]=='4'

||str[i]=='5'||str[i]=='6'||str[i]=='7'||str[i]=='8'||str[i]=='9')

{

num++;

}

if(str[i]=='b'||str[i]=='c'||str[i]=='d'||str[i]=='f'||str[i]=='g'

||str[i]=='h'||str[i]=='l'||str[i]=='j'||str[i]=='k'||str[i]=='m'

||str[i]=='n'||str[i]=='p'||str[i]=='q'||str[i]=='r'||str[i]=='s'

||str[i]=='t'||str[i]=='v'||str[i]=='w'||str[i]=='x'||str[i]=='y'

||str[i]=='z')

{

con++;

}

if(str[i]=='b'||str[i]=='c'||str[i]=='d'||str[i]=='f'||str[i]=='g'

Page 139: C++ Assignment

C++ Assignment 2010

139

||str[i]=='h'||str[i]=='l'||str[i]=='j'||str[i]=='k'||str[i]=='m'

||str[i]=='n'||str[i]=='p'||str[i]=='q'||str[i]=='r'||str[i]=='s'

||str[i]=='t'||str[i]=='v'||str[i]=='w'||str[i]=='x'||str[i]=='y'

||str[i]=='z'||str[i]=='a'||str[i]=='i'||str[i]=='e'||str[i]=='u'||str[i]=='o'

||str[i]=='0'||str[i]=='1'||str[i]=='2'||str[i]=='3'||str[i]=='4'

||str[i]=='5'||str[i]=='6'||str[i]=='7'||str[i]=='8'||str[i]=='9'

||str[i]==' '||str[i]==' ')

{

cout<<endl;

}

else

{

st++;

}

}

cout<<endl<<"No. of Vowel "<<vowel;

cout<<endl<<"No of Consonanats "<<con;

cout<<endl<<"No. of Tabspace "<<tspace;

cout<<endl<<"No. of Blankspace "<<space;

cout<<endl<<"No. of Specialchar "<<st;

cout<<endl<<"No. of Number "<<num;

getch();

}

Output:-

Page 140: C++ Assignment

C++ Assignment 2010

140

Author Name:- Premendra Yadaw

Path:- D:\ Angel \FABO.CPP

Unit:- II

Date:- 24/10/2010

Que 37:- Write a program to using all operator and conditional .

Statement in a single program

Algorithm:- [To using all operator and condinal statement]

Here x,y,w & t are an integer data type.

Step1: Write : “Enter the value of x & y ”

Step2: Read: x,y

Step3: z :=++x-y

Step4: Write: “x=”,x,”y=”,y,”z=”,z

Step5: t=y+++x

Step6: Write: “x=”,x,”y=”,y,”t=”,t

Step7: Write: (z>t) ? 1:0

Step8: Write : (z<t) ? 1:0

Step9: Write : (((x>y)&&(t>z)) ? 10:9)

Step10: ((((x<y)||(t<z)) ? 40:39))

Step11:(((x<y)!=(t<z)) ? 100:101)

Step12: Write : (x<<1)

Step13: Write : (x>>2)

Step14: Exit

Page 141: C++ Assignment

C++ Assignment 2010

141

Program:-

/*write program to using all opertors*/

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int x,y,z,t,a;

cout<<"Enter the value of x,y " <<endl;

cin>>x>>y;

z= ++x-y;

cout<<"x = "<<x<<" y = "<<y<<" z = "<<z<<endl;

t=y+++x;

cout<<"x = "<<x<<" y = "<<y<<" t = "<<z<<endl;

cout<<endl<<" "<<(z>t) ? 1:0;

cout<<endl<<" "<<(z<t) ? 1:0;

cout<<endl<<" "<<(((x>y)&&(t>z)) ? 10:9);

cout<<endl<<" "<<((((x<y)||(t<z)) ? 40:39));

cout<<endl<<" "<<(((x<y)!=(t<z)) ? 100:101);

a=x<<1;

cout<<endl<<" "<<a;

a=x>>2;

cout<<endl<<" "<<a;

getch();}

Page 142: C++ Assignment

C++ Assignment 2010

142

Output:-

Page 143: C++ Assignment

C++ Assignment 2010

143

Author Name:- Premendra Yadaw

Path:- D:\ Angel \student.CPP

Unit:- II

Date:- 13/11/2010

Que 38:- Write a program to define a structure with name,standard

& rollno. Tnput data for 10 Student then print It.

Algorithm:- [To print rollno,name & standerd]

Here s1[10] is veriable of structure student type

Step1: [Declare structure array of structure] student s1[10]

Step2: int i

Step3: Reapeat step4 to 8 for i = 1 t0 10

Step4: Write : "Enter Rollno "

Step3: Read : s1[i].rollno

Step4: Write : "Enter Name ";

Step5: Read : s1[i].name

Step6: Write : "Enter Standerd "

Step7: Read : s1[i].stand;

Step8: i=i+1

Step9: Write : "Student Record"

Step10: Reapeat step 11 to 14 for i = 1 t0 10

Step11: Write : "Rollno= " , s1[i].rollno

Step12: Write : "Name= ", s1[i].name

Step13: Write : "Standerd= ",s1[i].stand

Step14: i=i+1

Step15: Exit

[Subalgorithm of structure student defination] Here a is day,month & year integer type variable

Step1: [Declare Structure] struct student

{

Step2: [Declare variable] int rollno

Step3: [Declare variable] char name[20]

Step4: [Declare variable] char stand[10]

Step5: Exit

Page 144: C++ Assignment

C++ Assignment 2010

144

Program:- /*print student imfomation using structure*/

#include<iostream.h>

#include<conio.h>

struct student

{

int rollno;

char name[20];

char stand[10];

};

void main()

{

student s1[10];

int i;

clrscr();

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

{

cout<<endl<<"Enter Rollno ";

cin>>s1[i].rollno;

cout<<endl<<"Enter Name ";

cin>>s1[i].name;

cout<<endl<<"Enter Standard ";

cin>>s1[i].stand;

}

cout<<endl<<endl<<" Student Record "<<endl<<endl;

cout<<"Rollno."<<" "<<" Name "<<" "<<" Stand ";

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

{

cout<<endl<<" "<<s1[i].rollno<<" "<<s1[i].name<<" "<<s1[i].stand;

}

getch();

}

Page 145: C++ Assignment

C++ Assignment 2010

145

Output:-

Page 146: C++ Assignment

C++ Assignment 2010

146

Author Name:- Premendra Yadaw Path:- D:\ Angel \emp.CPP

Unit:- II

Date:- 13/11/2010

Que 39:- Write a program to input 20 record of employee including

Name,basic salary,age,sex. Find the no of man & women and average salary and no of emp above 50 year.

Algorithm:- [To print name,basic sal ,age &sex]

Here e1[20] is veriable of structure emp type

Step1: [Declare array of structure] emp e1[20]

Step2: int i

Step3: int total = 0, sal=0,avg

Step4: Reapeat step for i = 1 t0 20

Step4: Write : "Enter emp name "

Step3: Read : e1[i].name

Step4: Write : "Enter basic salary "

Step5: Read : e1[i].bsal

Step6: Write : "Enter age”

Step7: Read : e1[i].age

Step8: Write : “Enter sex”

Step9: Read : e1[i].sex

Step8: Write : "Employee Record"

Step9: Reapeat step 10 to 13 for i = 1 t0 10

Step10: Write : "Name= " , e1[i].name

Step11: Write : "Basic salary= ", e1[i].bsal

Step12: Write : "sex= ", e1[i].sex

Step13: Write : “age=”, e1[i].age

Step14: i=i+1

Step15: Exit

[Subalgorithm of structure emp defination] Here name & sex is character type variable and age and bsal

Are integer type variable.

Step1: [Declare Structure] struct emp

Step2: [Declare variable] int age

Step3: [Declare variable] char name[20]

Step4: [Declare variable] char sex[10]

Step5: [Declare variable] int bsal

Step5: Exit

Page 147: C++ Assignment

C++ Assignment 2010

147

Program:- /*print employee imformation using structure*/

#include<conio.h>

#include<iostream.h>

struct emp

{

char name[10];

int bsal;

int age;

char sex[6];

};

void main()

{

clrscr();

int total=0,sal=0,avg;

emp e1[20];

int i;

cout<<endl<<"Enter Employee Info ";

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

{

cout<<endl<<"Enter emp name ";

cin>>e1[i].name;

cout<<endl<<"Enter emp age ";

cin>>e1[i].age;

cout<<endl<<"Enter emp Basic salary ";

cin>>e1[i].bsal;

cout<<endl<<"Enter emp sex ";

cin>>e1[i].sex;

}

//cout<<endl<<endl<<"Employee Record";

//for(i=1;i<=20;i++)

//{

//cout<<endl<<"Enter emp name ";

//cin>>e1[i].name;

//cout<<endl<<"Enter emp age ";

//cin>>e1[i].age;

//cout<<endl<<"Enter emp Basic salary ";

//cin>>e1[i].bsal;

Page 148: C++ Assignment

C++ Assignment 2010

148

//cout<<end<<"Enter emp sex ";

//cin>>e1[i].sex;

// }

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

{

if(e1[i].age>50)

{

total++;

sal=sal+e1[i].bsal;

}

}

avg=sal/total;

cout<<endl<<"No. of women & men whose age is above 50 is "<<total;

cout<<endl<<"Avgrage Basic sal of employee whose age is above 50 is "<<avg;

getch();}

Page 149: C++ Assignment

C++ Assignment 2010

149

Author Name:- Premendra Yadaw

Path:- D:\ Angel \publica.CPP

Unit:- II

Date:- 13/11/2010

Que 40:- Imagine pulishing companies take markets both book &

audio cassettes versions od it’s works. Creat a class Public

-ation that store the title & prices of a publication. From

this class derive two class:book whitch add the page count

Tape,which adds a playing time.Each of these 3 class

should

Have getdata() function to get .Its data from the user and

A Putdata() function to display ir’s data.

Algorithm:- [To store price,title of book]

Here p is object class page and t is a object of class tap

Step1: [Declare object] page p

tap t

Step2: [call datamember of base class publication]

p.getdata();

p.putdata();

t.getdata();

t.putdata();

Step3: Exit

[Subalgorithm of definition of base class publication]

Step1: class publicatio

{

Step2: [Declare protected datamember]

protected : char title[30];

int price;

Step3: [Declare & define public member funtion]

public:

Step4: void getdata()

{

Step5: Write : “Enter the title of book:";

Read : title

Page 150: C++ Assignment

C++ Assignment 2010

150

Step6: Write : “Enter the price of book:";

Step7: Read : price;

}[End of function definition]

Step8: void putdata()

{

Step9: Write : “Title:"

Step10: Write : price;

}[End of function definition]

}; [End base class defination]

Step11: Exit

[Subalgorithm of definition of derive class page]

Step1: [Declare derive class]

class page:public publication //1st derived class

{

Step2: [ Declare protected datamemeber]

protected : int pageno;

Step3: [Declare public member function]

public :

Step4: [Define member function] void getdata()

{

Step5: publication::getdata(); //function overriding

Step6: Write : “Enter the page no of book:";

Step7: Read : pageno;

}[End of function definition]

Step8: [Define member function] void putdata()

{

Step9: publication::putdata();

Step10: Write : "Page no:",pageno;

}[End of function definition]

};[Enf of derive class definition]

Step11: Exit

[Subalgorithm of definition of derive class tap]

Step: [Declare derive class tap]

class tap::public publication //2nd derived class

{

Page 151: C++ Assignment

C++ Assignment 2010

151

Step2: [Declare protecteddata member]

protected : int length;

Step3: [Declare public member function]

public:

Step4: [Define member function]

void getdata()

{

Step5: publication :: getdata();

Step6: Write : ”Enter the length of tap"

Step7: Read : length

} [End of function definition]

Step8: [Define member fubtion]

void putdata()

{

Step9: publication::putdata();

Step10; Write : “Tap length",lenth

} [End of funtin definition]

};[Ent derive class definition}

Step11: Exit

Page 152: C++ Assignment

C++ Assignment 2010

152

Program:-

/*find lenth of tape&count total number of page inbook*/

#include<iostream.h> #include<conio.h>

class publication //base class

{

protected:

char title[30];

int price;

public:

void getdata()

{

cout<<"\nEnter the title of book:";

cin.getline(title,30);

cout<<"\nEnter the price of book:";

cin>>price;

}

void putdata()

{

cout<<"\nTitle:"<<title;

cout<<"\nPrice:"<<price;

}

};

class page:public publication //1st derived class

{

protected:

int pageno;

public:

void getdata()

{

publication::getdata(); //function overriding

cout<<"\nEnter the page no of book:";

cin>>pageno;

}

void putdata()

{

publication::putdata();

Page 153: C++ Assignment

C++ Assignment 2010

153

cout<<"\nPage no:"<<pageno;

}};

class tap:public publication //2nd derived class

{protected:

int length;

public:

void getdata()

{publication :: getdata();

cout<<"\nEnter the length of tap";

cin>>length;}

void putdata()

{publication::putdata();

cout<<"\nTap length"<<length;

}};

void main()

{page p;

tap t;

clrscr();

p.getdata();

p.putdata();

t.getdata();

t.putdata();getch();}

Output:-

Page 154: C++ Assignment

C++ Assignment 2010

154

Author Name:- Premendra Yadaw

Path:- D:\ Angel \complex.CPP

Unit:- II

Date:- 13/11/2010

Que 41:- Write a program to addition of two complex class contain 2

attribute real & Image.Addion of complex class object

means addition real&image separately and display the

the addition this complex no.

Algorithm:- [To addition of tuo complex number]

Here a,b,c complex type integer

Step1: [Declare complex variable]complex a,b,c;

Step2: [Call member function]

a.getdata();

b.getdata();

c=a.sum(b);

a.show();

b.show();

c.show();

Step3: Exit

Funtion Defination:- GETDATA( ) This procedure made for input data in

variable.

Step1: [initialize] Set x, y, real, imag.

Step2: scanning value in x, y.

Read: x,y.

Step3: Set real:=x and imag:=y.

Step4: Exit.

Funtion Defination:- SHOW( ) this procedure made for print value of real and

imag

variable .

Step1: Print:real,”+i”,imag.

Step2: Exit.

Funtion Defination:- SUM(object c2)

This procedure made for sum the value of data member of

Page 155: C++ Assignment

C++ Assignment 2010

155

Object. Object is a object of complex type procedure.

Step1: create another object c3 of procedure1.

Step2: Set c3.real:= real + c2.real.

Step3: Set c3.real:= real + c2.real.

Step4: return (c3).

Step5: Exit.

Funtion Defination:- Complex(real,imag) This procedure made for binding some

different data type and procedure.

Step1: [initialize] Set real, imag.

Step2: define procedure m1, m2,m3.

Step3: Exit.

Page 156: C++ Assignment

C++ Assignment 2010

156

Program:-

/*print value in real & imagnary*/

#include<iostream.h>

#include<conio.h>

class complex

{

float real,imag;

public:

void getdata()

{

float x,y;

cout<<"\nEnter real no.";

cin>>x;

cout<<"\nEnter imagnary no.";

cin>>y;

real=x;

imag=y;

}

void show()

{

cout<<"\n"<<real<<"+i"<<imag;

}

complex sum(complex c);

};

complex complex :: sum(complex c)

{

complex c1;

c1.real=real+c.real;

c1.imag=imag+c.imag;

return(c1) ;

}

void main()

{

complex a,b,c;

clrscr();.

a.getdata();

b.getdata();

c=a.sum(b);

Page 157: C++ Assignment

C++ Assignment 2010

157

a.show();

b.show();

c.show();

getch();

}

Output:-

Page 158: C++ Assignment

C++ Assignment 2010

158

Author Name:- Premendra Yadaw

Path:- D:\ Angel\ overload.CPP

Unit:- II

Date:- 13/11/2010

Que 42:- Write a program to Explain Overloading.

Algorithm:- [swapping ising funtion overloading]

Here ch1,ch,2 are char type,a,b are integer type and c,d are

float are float type variable.

Step1: char ch1,ch2;

Step2: Write : "Enter two characters "

Step3: Read ch1,ch2

Step4: [Call function] swap(ch1,ch2);

Step5: Write : "On swapping <ch1,ch2>: ",ch1,ch2

Step6: int a,b;

Step7: Write : "Enter two integers "

Step8: Read : a,b;

Step9: [Call function] swap(a,b);

Step10: Write : "On swaping <a,b>: ",a," ",b

Step11: float c,d;

Step12: Write : "Enter two floats “

Step13: Read : c ,d;

Step14: [Cal function] swap(c,d);

Step15: Write : swapping <c,d>: ,",c," ",d;

Step16: Exit

[subalgorithm funtion void swap(char &x,char &y) defination]

Step1: void swap(char &x,char &y)

{

Step2: char t; //temporily uused in swapping

Step3: t=x;

Step4: x=y;

Step5: y=t;

}[End of function definition]

Step6: Exit

Page 159: C++ Assignment

C++ Assignment 2010

159

[subalgorithm funtion void swap(int &x,int &y) defination]

Step1: void swap(int &x, int &y)

{

Step2: int t; //temporily uused in swapping

Step3: t=x;

Step4: x=y;

Step5: y=t;

}[End of function definition]

Step6: Exit

[subalgorithm funtion void swap(char &x,char &y) defination]

Step1: void swap(float &x,float &y)

{

Step2: float t; //temporily used in swapping

Step3: t=x;

Step4: x=y;

Step5: y=t;

}[End of function definition]

Step6: Exit

Page 160: C++ Assignment

C++ Assignment 2010

160

Program:- /*swap value of one variable to another*/

#include<iostream.h>

#include<conio.h>

void swap(char &x,char &y)

{

char t; //temporily uused in swapping

t=x;

x=y;

y=t;

}

void swap(int &x,int &y)

{

int t; //temporily uused in swapping

t=x;

x=y;

y=t;

}

void swap(float &x,float &y)

{

float t; //temporily uused in swapping

t=x;

x=y;

y=t;

}

void main()

{

char ch1,ch2;

clrscr();

cout<<"Enter two characters "<<endl;

cin>>ch1>>ch2;

swap(ch1,ch2);

cout<<"On swapping <ch1,ch2>: "<<ch1<<" "<<ch2<<endl;

int a,b;

cout<<endl<<"Enter two integers "<<endl;

cin>>a>>b;

swap(a,b);

cout<<endl<<"On swaping <a,b>: "<<a<<" "<<b<<endl;

float c,d;

Page 161: C++ Assignment

C++ Assignment 2010

161

cout<<endl<<"Enter two floats "<<endl;

cin>>c>>d;

swap(c,d);

cout<<"On swapping <c,d>: "<<c<<" "<<d;

getch();

}

Output:-

Page 162: C++ Assignment

C++ Assignment 2010

162

Author Name:- Premendra Yadaw

Path:- D:\ Angel \sal.CPP

Unit:- II

Date:- 13/11/2010

Que 43:- Write a swapping program to demonstrate call by value

andCall by reference and call by address in single

Algorithm:- [To swapping using callby value,call by address,call by

reference ]

Here a,b are integer type variable.

Step1: [Declare variable] int a,b

Step2: Write : "Enter value of a,b "

Step3: Read : a,b;

Step4: "Value of a&b before swapping"

Step5: Write : " a = " , a

Step6: Write : " b = " ,b

Step7: Write : "Call By value"

Step8: [Call fuuntion] swapval(a,b);

Step9: Write : "Value of a&b after swapping"

Step10: Write : " a = " , a

Step11: Write : " b = " , b

Step12: Write : "Call By address"

Step13: [Call function] swapadd(&a,&b);

Step14:"Value of a&b after swapping"

Step15: " a = "a

Setp16: " b = " , b

Step17: Write : "Call By Refrence"

Step18: [Call function] swapref(a,b);

Step19: Write : "Value of a&b after swapping"

Step20: Write : " a = " , a

Step21 Write : " b = ", b

Step22: Exit

[subalgorithm funtion void swapval(int x, int y) defination]

Step1: void swapval(int x, int y)

{

Step2: int t; //temporily uused in swapping

Step3: t=x;

Page 163: C++ Assignment

C++ Assignment 2010

163

Step4: x=y;

Step5: y=t;

}[End of function definition]

Step6: Exit

[subalgorithm funtion void swapadd(int *x,int *y) defination]

Step1: void swapadd(int &x, int &y)

{

Step2: int t; //temporily uused in swapping

Step3: t=x;

Step4: x=y;

Step5: y=t;

}[End of function definition]

Step6: Exit

[subalgorithm funtion void swapref(int &x, int &y) defination]

Step1: void swapref(float &x,float &y)

{

Step2: float t; //temporily uused in swapping

Step3: t=x;

Step4: x=y;

Step5: y=t;

} [End of function definition]

Step6: Exit

Page 164: C++ Assignment

C++ Assignment 2010

164

Program:- /*swapping using call by value,address & refrence*/

#include<iostream.h>

#include<conio.h>

void swapval(int x,int y)

{

int t;

t=x;

x=y;

y=t;

}

void swapadd(int *x,int *y)

{

int t;

t=*x;

*x=*y;

*y=t;

}

void swapref(int &x,int &y)

{

int t;

t=x;

x=y;

y=t;

}

void main()

{

int a,b;

clrscr();

cout<<"Enter value of a,b ";

cin>>a>>b;

cout<<"Value of a&b before swapping"<<endl;

cout<<" a = "<<a<<endl;

cout<<" b = "<<b<<endl;

cout<<endl<<endl<<"Call By value"<<endl;

cout<<"Value of a&b after swapping"<<endl;

swapval(a,b);

cout<<" a = "<<a<<endl;

cout<<" b = "<<b<<endl;

Page 165: C++ Assignment

C++ Assignment 2010

165

cout<<endl<<endl<<"Call By address"<<endl;

swapadd(&a,&b);

cout<<"Value of a&b after swapping"<<endl;

cout<<" a = "<<a<<endl;

cout<<" b = "<<b<<endl;

cout<<endl<<endl<<"Call By Refrence"<<endl;

swapref(a,b);

cout<<"Value of a&b after swapping"<<endl;

cout<<" a = "<<a<<endl;

cout<<" b = "<<b<<endl;

getch();

}

Output:-

Page 166: C++ Assignment

C++ Assignment 2010

166

Author Name:- Premendra Yadaw

Path:- D:\ Angel \allpass.CPP

Unit:- II

Date:- 13/11/2010

Que 44:- Write a program to creat a class employee having data

member to store name of employee id,salary. Provide

member function for data input output.Use pointer to

object to simulate array of object top store information

of three employee of three employee and test the program

in main function.

Algorithm:- [To print eml id,salary ,name ]

Here *ptr[3] is pointer to object of array type of emp class and

sum[3]

object of class emp array type.

Step1: [Declare pointer to object ] emp *ptr[3]

Step2: [Declare oject of class emp] emp sum[3];

Step3: [Assign address of sum to ptr] ptr[3]=&sum[3];

Step4: int i

Step5: Write : " Enter Employee Information "

Step6: Reapeat step7,8 for i =3 to i<6

Step7: [Access member function of emp class] ptr[i]->input();

Step8: i=i+1

Step9: Write : "Employee Record"

Step10: Write : "Empname ","EmpId ","Empsal "

Step11: Reapeat step for i =3 to i<6

Step12: [Access member funtuonptr[i]->output();

Step13: Exit

[subalgorithm of class emp defination defination]

Step1: [dclear class]class emp

{

Step2: [Declare datamember] char name[10]

int empid

int sal

Step3: [Dclear public member function]

public:

Page 167: C++ Assignment

C++ Assignment 2010

167

Step4: void input()

{

Step5: Write : "Enter emp name "

Step6: Read : name;

Step7: Write : "Enter emp Id”

Step8: empid;

Step9: Write : "Enter emp salary”

Step10: Read : sal;

}[End of function definition]

Step11: void output()

{

Step12: Write : name," ",empid," ",sal

}[End of function definition]

} [End of class definition]

Step2: int t; //temporily uused in swapping

Step3: t=x;

Step4: x=y;

Step5: y=t;

}[End of function definition]

Step6: Exit

[subalgorithm funtion void swapadd(int *x,int *y) defination]

Step1: void swapadd(int &x, int &y)

{

Step2: int t; //temporily uused in swapping

Step3: t=x;

Step4: x=y;

Step5: y=t;

}[End of function definition]

Step6: Exit

Page 168: C++ Assignment

C++ Assignment 2010

168

Program:-

#include<iostream.h>

#include<conio.h>

class emp

{

char name[10];

int empid;

int sal;

public:

void input()

{

cout<<endl<<"Enter emp name ";

cin>>name;

cout<<endl<<"Enter emp Id ";

cin>>empid;

cout<<endl<<"Enter emp salary ";

cin>>sal;

}

void output()

{

cout<<name<<" "<<empid<<" "<<sal<<endl;

}

};

void main()

{

clrscr();

emp *ptr[3];

emp sum[3];

ptr[3]=&sum[3];

int i;

cout<<" Enter Employee Information"<<endl;

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

{

ptr[i]->input();

}

cout<<endl<<endl<<" Employee Record"<<endl;

Page 169: C++ Assignment

C++ Assignment 2010

169

cout<<"Empname "<<"EmpId "<<"Empsal "<<endl;

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

{

ptr[i]->output();

}

getch();

}

Output:-

Page 170: C++ Assignment

C++ Assignment 2010

170

Author Name:- Premendra Yadaw

Path:- D:\ Angel\pattern1.CPP

Unit:- II

Date:- 13/11/2010

Que 45:- Print this output…

* * * * *

* * * *

* * *

* *

*

* *

* * *

* * * *

* * * * *

Algorithm:- [To print output ]

Here i,j,k,x,y z are itiger type variable.

Step1: [Declare variable] int i,j;

int k,x,y,z;

Step2: Write : endl

Step3: Repeat step for 4,5,6,7,8,9, for y=1 t0 5

Step4: Reapeat step 4,5 for x=1 to x<=y

Step5: Write : " "

Step6: x=x+1

[End of nested for]

Step7: Reapeat step 8,9 for z = 5 to 1

Step8: "* "

Step9: z=z-1

[End of nested for]

Step8: Write : "\n"

Step9: y=y+1

[End of outer for]

Step10: Reapeat Step 11 ,12,13,14,15,16,17for i=2 to 5

Step11:Repeat step 11,12 for k=5 to i

Step11: Write : “ “

Step12: k=k-1

[End of nested for]

Page 171: C++ Assignment

C++ Assignment 2010

171

Step13: Reapeat step 14,15 for z = 1 to i

Step14: Write : “* “

Step15: z=z+1

[End of for loop]

Step16: Write : “\n”

Step17: i=i+1

[End of outer for loop]

Step18: Exit

Program:-

void main()

{

clrscr();

int i,j;

int k,x,y,z;

cout<<endl;

for(y=1;y<=4;y++)

{

for(x=1;x<=y;x++)

{

cout<<" ";

}

for(z=4;z>=y;z--)

{

cout<<"* ";

}

cout<<"\n";

}

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

{

for(k=4;k>=i;k--)

{

cout<<" " ;

}

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

Page 172: C++ Assignment

C++ Assignment 2010

172

{

cout<<"* ";

}

cout<<"\n";

}

getch();

}

Output:-

Page 173: C++ Assignment

C++ Assignment 2010

173

Author Name:- Premendra Yadaw

Path:- D: \Angel\pattern1.CPP

Unit:- II

Date:- 13/11/2010

Que 46:- Write a programfor matrix multiplication.

Algorithm:- [Multipliaction of two matrix ] Here mat1[3][3],mat2[3][3],mat3[3][3] cahr array

Step1: [Declare variable] int i,j,k;

Step2: Write : “Enter 1st matrix

Step3: Repeat step for 4,5,6,7,8,9, for i=1 to3

Step4: Reapeat step 4,5 for j=j+1

Step5: Read :mat1

Step6: j=j+1

[End of nested for]

Step7: i=i+1

[End of outer for]

Step8: Write : “Enter 1st matrix

Step9: Repeat step for 4,5,6,7,8,9, for i=1 to3

Step10: Reapeat step 4,5 for j=j+1

Step11: Read :mat1

Step12: j=j+1

[End of nested for]

Step13: i=i+1

[End of outer for]

Step14: Write : “Enter 2nd

matrix

Step15: Repeat step for 4,5,6,7,8,9, for i=1 to3

Step16: Reapeat step 4,5 for j=j+1

Step17: Read :mat2

Step18: j=j+1

[End of nested for]

Step19: i=i+1

[End of outer for]

Step20: Repeat step for 4,5,6,7,8,9, for i=1 to3

Step21: Reapeat step 4,5 for j=j+1

Step22: Reapeat step 4,5 for k=1 tp 3

Page 174: C++ Assignment

C++ Assignment 2010

174

Step23: mat3[i][j]=mat3[i][j]+mat[i][k]+mat[k][j]

Step24: k=k+1

Step25: j=j+1

[End of nested for]

Step26: i=i+1

[End of outer for]

Step27: Write : “1st matrix

Step28: Repeat step for 4,5,6,7,8,9, for i=1 to3

Step19: Reapeat step 4,5 for j=j+1

Step30: Write :mat1

Step31: j=j+1

[End of nested for]

Step32: i=i+1

[End of outer for] Step34: Write : “ 2nd matrix

Step35: Repeat step for 4,5,6,7,8,9, for i=1 to3

Step36: Reapeat step 4,5 for j=j+1

Step37: Write :mat2

Step38: j=j+1

[End of nested for]

Step39: i=i+1

[End of outer for]

Step40: Write : “matrix multiplication”

Step41: Repeat step for 4,5,6,7,8,9, for i=1 to3

Step42: Reapeat step 4,5 for j=j+1

Step45: Write :mat3[i][j]

Step46: j=j+1

[End of nested for]

Step49: i=i+1

[End of outer for]

Page 175: C++ Assignment

C++ Assignment 2010

175

Program:-

#include<iostream.h>

#include<conio.h>

void main()

{

int i,j,k;

int mat1[3][3];

int mat2[3][3];

int multi[3][3];

clrscr();

cout<<endl<<"Enter value Mat1"<<endl;

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

{

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

{

cin>>mat1[i][j] ;

}

}

cout<<endl<<"Enter value Mat2"<<endl;

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

{

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

{

cin>>mat2[i][j] ;

}

}

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

{

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

{

multi[i][j]=0;

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

{

multi[i][j]=multi[i][j]+mat1[i][k]*mat2[k][j];

}

}

}

Page 176: C++ Assignment

C++ Assignment 2010

176

cout<<endl<<"Mat1"<<endl<<endl;

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

{

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

{

cout<<mat1[i][j]<<"\t";

}

cout<<"\n";

}

cout<<endl<<"Mat2"<<endl<<endl;

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

{

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

{

cout<<mat2[i][j]<<"\t";

}

cout<<"\n";

}

cout<<endl<<"Multiplication of two matrix"<<endl<<endl;

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

{

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

{

cout<<multi[i][j]<<"\t";

}

cout<<"\n";

}

getch();

Page 177: C++ Assignment

C++ Assignment 2010

177

Output:-

Page 178: C++ Assignment

C++ Assignment 2010

178

Author Name:- Premendra Yadaw

Path:- D:\ Angel \lenth.CPP

Unit:- II

Date:- 13/11/2010

Que 47:-Write the program t perform following task without using

Libery function:

1.to revers the string

2.to count number o char in sting

3.Copy of string one to another string

4.count vowel,consonanat.

Algorithm:- [Revers fo string ]

Here str1,str is char array

Step1: [Declare variable]

char str[20][20],int

int l=0,i

Step2: Write : ”Enter string”

Step3: Read: str1;

Step4: Write:”Revers of string”

Step5: Reapeat step6,7 for i=1t0 str1[i]!=‟\0‟

Step6: l=l+1

Step7: i=i+1

[End of outer for]

Step8: Write : l

Step9: Write : “Revers of string”

Step10:Repeat step 11,12 for i=l to 0

Step11:Write: str1[i]

Step12: i=i-1

[End of nested for]

Step13: Repeat step 14,15 for i=0 to i<l

Step14: str2[i]=str1[i]

Step15: i=i+1

[End of outer for]

Step16: Write : ”Copy of string”, str2

Step17: Repeat step 18,19,20,21 for i=0 t0 str[i]!=‟/0‟

Step18: if(str1[i]==‟a‟|| str1[i]==‟e‟|| str1[i]==‟i‟|| str1[i]==‟o‟||

str1[i]==‟u‟) then

Page 179: C++ Assignment

C++ Assignment 2010

179

Step19: vow++

Step20: Else

con++

Step21: i=i+1

[End of outer for]

Step22: Write : ”Number of vowel in sting”,vow

Step23: Write : ”Number of consonanate in sting”,con

Step24: Exit

Page 180: C++ Assignment

C++ Assignment 2010

180

Program:-

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int l=0,i,j;

int vowel=0,con=0;

char str1[20],str2[20];

cout<<"Enter any string " ;

cin>>str1;

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

{

l++;

}

cout<<endl<<"Revers of string ";

for(i=l;i>=0;i--)

{

cout<<str1[i];

}

cout<<endl<<"Lenth of string ";

cout<<l;

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

{

str2[i]=str1[i];

}

str2[i]='\0';

cout<<endl<<"Copy of string "<<str2;

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

{

if(str1[i]=='a'||str1[i]=='i'||str1[i]=='e'||str1[i]=='u'||str1[i]=='o')

{

vowel++;

}

else

{

con++;

}

}

Page 181: C++ Assignment

C++ Assignment 2010

181

cout<<endl<<"Number of vowel in string "<<vowel;

cout<<endl<<"Number of consonanats in string "<<con;

getch();

}

Ooutput:-

Page 182: C++ Assignment

C++ Assignment 2010

182

Author Name:- Premendra Yadaw

Path:- D:\ Angel \polar.CPP

Unit:- II

Date:- 13/11/2010

Que 48:-Createclass polar having datamemeber radius and angle .

It contain member function for taking input in datamember.

Clas polar contains decleration of friend function add which a

Accept two object of class using function and object of class polar

After addition.test the class using function and object of class.

Algorithm:- [:-[To Print Polar as feet-inch]

Here p1,p2,p3 is object of polar class.

Step1: [Create object of polar class] date p1,p2,p3

Step2: [Call member function of polar class]

P2.init(11.0,6.25)

p2.read()

Step3 : Write : “p1 = “

Step4 : [Call member function of polar class]

p1.show()

Step5 : Write : “p2 = ”

Step6 : [Call member function of polar class]

p2.show()

Step7 : [Call member function of class]

P3.add()

Step8 : Write : “p1+p2”

Step9 : p3.show()

Step10 : Exit

[Sub algorithm of definition of class polar] Step1: class polar

Step2: [Declare private data member of class polar]

private :

float radious

float angle

Step3:[Declare public member function]

public:void read()

Step4: Write : “Enter radious “

Page 183: C++ Assignment

C++ Assignment 2010

183

Step5: Read : rediuos

Step6:Write : “Enter angle”

Step7:Read : angle

[End of funtion definition]

Step8:void show()

Step9: Write : radios, ”-“ ,angle

[End of funtion definition]

Step10:void add(polar p1,polar p2)

Step11: radious=p1.radious + p2.radious

Step12:angle=p1.angle + p2.angle

[End of funtion definition]

[End of class definition]

Step4: Exit

con++

Step21: i=i+1

[End of outer for]

Step22: Write : ”Number of vowel in sting”,vow

Step23: Write : ”Number of consonanate in sting”,con

Step24: Exit

Page 184: C++ Assignment

C++ Assignment 2010

184

Program:-

#include<iostream.h>

#include<conio.h>

class polar

{

private:

float redius;

float angle;

public:

void read()

{

cout<<" Enter Redius:- ";

cin>>redius;

cout<<endl<<" Enter Angle:- ";

cin>>angle;

cout<<endl;

}

void show()

{

cout<<redius<<"-"<<angle<<"\n";

}

void add(polar p1,polar p2)

{

redius=p1.redius+p2.redius;

angle=p1.angle+p2.angle;

}

};

void main()

{

clrscr();

polar p1,p2,p3;

p1.read();

p2.read();

cout<<" p1 = "<<"\t";

p1.show();

cout<<" p2 = "<<"\t";

p2.show();

Page 185: C++ Assignment

C++ Assignment 2010

185

p3.add(p1,p2);

cout<<" p1+p2 = ";

p3.show();

getch();

}

Output:-