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
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
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,
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
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
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 isan 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.
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( );
}
C++ Assignment 2010
8Flowchart:-
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 STARTC++ 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 isan 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.
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:
-C++ Assignment 2010
11Flowchart:-
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 distanceC++ 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 codean 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.
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(); }
C++ Assignment 2010
14
-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:
- [Toconvert
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
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();
}
C++ Assignment 2010
17Flochart:-
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.8C++ 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
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:
-C++ Assignment 2010
20Flowchart
p=300 STOP int p PRINT “l =”, l START int l=p PRINT “p=”, p PRINT “::p=”,::p PRINT “p=”, p PRINT “::p=”,::pC++ 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
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:
-C++ Assignment 2010
23Flowchart
:-False True int n START INPUT: n i=i+2 i< n PRINT: i+2 int i=0 STOP
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
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:
-C++ Assignment 2010
26Flowchart
:- False True START int s=0,ss=0,i i=2 i<=15 s+=i ss+=i*i PRINT: s , ss START ss+=i*iC++ 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
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:
-C++ Assignment 2010
29Flowchart
:- START int a,b,c INPUT: a,b,c d = a if(d=a) if (c>d) d = b d = c PRINT :d STOPC++ 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
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();
}
C++ Assignment 2010
32Flowchart
:- 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 STARTC++ 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
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(); }
C++ Assignment 2010
35
Output:
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
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
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:
-C++ Assignment 2010
39Flowchart
:- 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 endC++ 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 theyear 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]
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
:-
C++ Assignment 2010
42Flow-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
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 veribleStep1: [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
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
:-C++ Assignment 2010
45Flowchart
:- // 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:xC++ 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 veribleStep1: [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
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; }
C++ Assignment 2010
48
C++ Assignment 2010
49Flowchart
:- //global variable STOP START PRINT:”funtionA()” int a int a=5 PRINT:”funtionB” Call funtionA() Call funtionB()C++ Assignment 2010
50 // Flow of funtionA() // Flow of funtionA() START STOP a=a+4 return a START return (a) int a=1 STOPC++ 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 veribleStep1: [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
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
:-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
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 dateStep1: [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
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();
}
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
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 studentStep1: [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
{
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
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;C++ Assignment 2010
60 cout<<"subject= "<<s1.subject<<endl; cout<<"Date= "<<s1.today.day<<"_"<<s1.today.month<<"-"<<s1.today.year; getch() }Output:
-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
C++ Assignment 2010
62Flowchart_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 STOPC++ 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 typeStep1: [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.
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;
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(); }
C++ Assignment 2010
66
Output
C++ Assignment 2010
67
Flowchart:-
//structure student delclear
Flowchart of
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 perC++ 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 STARTC++ 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 typeStep1: [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
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
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;
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(); }
C++ Assignment 2010
73Output:-Flowchart
:- START struct student int rollno char name[10] char marks float per STOPC++ Assignment 2010
74Flowchart 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
C++ Assignment 2010
75Flowchart 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 STOPC++ 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
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:-
C++ Assignment 2010
78START 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
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;
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
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:
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(); }
C++ Assignment 2010
83
Output :-
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
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:-
C++ Assignment 2010
86
//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
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
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:-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 STOPC++ 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
C++ Assignment 2010
91Program:
- #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" ; elsecout<<"it is not palindrom"; getch();}
C++ Assignment 2010
92Flowchart:-
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
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
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();
}