C++ Assignment
C++ Assignment
SESSION: 2010-11
SUBMITTED BY
GUIDED BY
Mr. PREMENDRA YADAW
Prof. V.K.PATLE M.C.A. Ist Sem
1
MC
C++ Assignment 2010
INDEX
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.
2
C++ Assignment 2010
4
C++ Assignment 2010
c) d)
1 1
1 2 1 2 1
1 2 3 1 3 3 1
1 2 34 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
5
C++ Assignment 2010
Que 1:- Write a program to print the values of given variable using
refrence variable.
6
C++ Assignment 2010
Program:-
Output:-
7
C++ Assignment 2010
Flowchart:-
START
Int a=1,b=2,c=3
Int &z=a
Print a,b,c
,z
z=b
Print a,b,c,z
,z
z=c
Print a,b,c,z
,z
STOP
8
C++ Assignment 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]
9
C++ Assignment 2010
Program:-
Output:-
10
C++ Assignment 2010
Flowchart:-
START
Int a,b,c=10
Float distance
a=c
b=c+1
distance=55.9
Float distance
Print
a,b,c,disance
,distance,,z
STOP
11
C++ Assignment 2010
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.
12
C++ Assignment 2010
Program:-
#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();
}
13
C++ Assignment 2010
Output:-
14
C++ Assignment 2010
15
C++ Assignment 2010
Program:-
Output:-
16
C++ Assignment 2010
Flochart:-
START
Float c,f
INPUT :c
a,b,c ,z
f=1.8*c+32
PRINT: f
a,b,c,,z
INPUT: f
c=f-32/1.8
STOP
17
C++ Assignment 2010
18
C++ Assignment 2010
Program:-
#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:-
19
C++ Assignment 2010
Flowchart:-
START
int p
int l=p
p=300
PRINT
“l =”, l
PRINT
“p=”, p
PRINT
“::p=”,::p
PRINT
“p=”, p
PRINT
“::p=”,::p
STOP
20
C++ Assignment 2010
Que 6:- Write a program to print series upto 1 t0 n using for loop.
21
C++ Assignment 2010
Program:-
#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:-
22
C++ Assignment 2010
Flowchart:- START
int n
INPUT: n
int i=0
False
i< n
True
PRINT: i+2
i=i+2
STOP
23
C++ Assignment 2010
24
C++ Assignment 2010
Program:-
#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:-
25
C++ Assignment 2010
Flowchart:-
START
int s=0,ss=0,i
i=2
False
i<=15
True
s+=i
ss+=i*i
PRINT: s , ss
ss+=i*i
START
26
C++ Assignment 2010
27
C++ Assignment 2010
Program:-
#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:-
28
C++ Assignment 2010
Flowchart:-
START
int a,b,c
INPUT: a,b,c
d=a
if(d=a)
d=b
if (c>d)
d=c
PRINT :d
STOP
29
C++ Assignment 2010
Que 9:- Write a program to find value of largest variable using else
if..else Statement.
30
C++ Assignment 2010
Program:-
#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:-
31
C++ Assignment 2010
Flowchart:-
START
int a,b,c
INPUT: a,b,c
True
STOP
32
C++ Assignment 2010
33
C++ Assignment 2010
Program:-
#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();
}
34
C++ Assignment 2010
Output:-
35
C++ Assignment 2010
Flowchart:- START
char name[20]
int age
INPUT: name
INPUT:age
PRINT
False
name,age
STOP
36
C++ Assignment 2010
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
37
C++ Assignment 2010
Program:-
#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:-
38
C++ Assignment 2010
Flowchart:-
START
int n,d=0
do
INPUT: n
True
PRINT: ”END”
goto end
False
if(n<0)
True
PRINT:”Skip No.”
continue
d=d+1
False
While(1)
end:”Enterned number is
0”
STOP
39
C++ Assignment 2010
Que 12:- Write a program to find out the given year is leap
year or not.?
40
C++ Assignment 2010
Program:-
#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:-
41
C++ Assignment 2010
Flow-chart:- START
yr
If (((yr/4=0) AND
(yr/100!=0)) OR It is not leap year
(yr/400)) then
then
It is leap year
STOP
42
C++ Assignment 2010
[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
43
C++ Assignment 2010
Program:-
#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:-
44
C++ Assignment 2010
Flowchart:- START
int x= 2222
Call functionb()
Print:x
STOP
// Flow Of Funtionb()
START
int x= 222
Call functiona()
Print:x
STOP
// Flow Of Funtiona()
START
int x= 2222
Print:x
STOP
45
C++ Assignment 2010
Program:-
#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;
}
47
C++ Assignment 2010
Output:-
48
C++ Assignment 2010
Flowchart:-
START
int a=5
PRINT:”funtionA()”
Call funtionA()
PRINT:”funtionB”
Call funtionB()
STOP
49
C++ Assignment 2010
// Flow of funtionA()
START
a=a+4
return a
STOP
// Flow of funtionA()
START
int a=1
return (a)
STOP
50
C++ Assignment 2010
51
C++ Assignment 2010
Program:-
#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:-
52
C++ Assignment 2010
Flowchart:-
START
int x
x=1
x<4
x = x+1
STOP
START
int a=0
a = a+2
PRINT: a
STOP
53
C++ Assignment 2010
Que 16:- Write a program to print today date and exam study
date using structure.
54
C++ Assignment 2010
Program:-
#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:-
55
C++ Assignment 2010
Flowchart:-
START // Structure Declaretion
struct date
int day
int month
int year
STOP
START
STOP
56
C++ Assignment 2010
58
C++ Assignment 2010
Program:-
#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;
59
C++ Assignment 2010
cout<<"subject= "<<s1.subject<<endl;
cout<<"Date= "<<s1.today.day<<"_"<<s1.today.month<<"-"<<s1.today.year;
getch() }
Output:-
60
C++ Assignment 2010
Flowchart:-
START
int day
int month
int year
STOP
struct student
int rollno
int marks
char name[10]
char subject[10]
char marks
date today
STOP
61
C++ Assignment 2010
Flowchart_of_main():-
START
student s1
PRINT:”Today Date”
PRINT:s1.today.day
,S1,today.month
S2,today.year
PRINT:”Name”
s1.name
PRINT:”Rollno.”
s1.rollno
PRINT:”Marks”
s1.marks
STOP
62
C++ Assignment 2010
{
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:-
#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:-";
64
C++ Assignment 2010
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();
}
65
C++ Assignment 2010
Output :-
66
C++ Assignment 2010
Flowchart:-
START
int rollno
int marks
char name[10]
char subject[10]
char marks
cahr per
STOP
student s1[10]
int n,i=0
INPUT: n
i=0
67
C++ Assignment 2010
for(i<n)
False
True
INPUT:s[i]. INPUT:
per s[i].marks
i=i+1
i=i=0
for(i<n)
False
True
PRINT: PRINT:
s[i].marks s[i].per
i=i+1
START
68
C++ Assignment 2010
70
C++ Assignment 2010
#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;
71
C++ Assignment 2010
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();
}
72
C++ Assignment 2010
Output:-
Flowchart:-
START
struct student
int rollno
char name[10]
char marks
float per
STOP
73
C++ Assignment 2010
Flowchart of main()
START
student s1
int n
INPUT:n
int i=0
For(i<n)
False
True
PRINT:”Enter
student record”
i=i+1
i=0
False For(i<n
True
PRINT:”Stu-
dent Record”
i = i +1
STOP
74
C++ Assignment 2010
Flowchart of read()
START
student s1
INPUT
s1.rollno
s1.name
s1.marks
s1.per
return s1
STOP
START
PRINT
s1.rollno
s1.name
s1.marks
s1.per
STOP
75
C++ Assignment 2010
Que 20:- Write a program to print revers any number and sum
of those number.
76
C++ Assignment 2010
Program:-
#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:-
77
C++ Assignment 2010
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
78
C++ Assignment 2010
80
C++ Assignment 2010
Program:-
#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:
81
C++ Assignment 2010
82
C++ Assignment 2010
Output :-
83
C++ Assignment 2010
84
C++ Assignment 2010
Program:-
#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:-
85
C++ Assignment 2010
Flowchart:-
START
int x,y
INPUT : x,y
min(x,y) = 200
//call function min(x,y)
PRINT : x,y
STOP
START
If(n1<n2 Else
True
return n1
return n2
STOP
86
C++ Assignment 2010
87
C++ Assignment 2010
Program:-
#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:-
88
C++ Assignment 2010
Flowchart:-
START
char s[80]
INPUT: s
PRINT: s
STOP
START
int i = 0
False If(str[i]!
= „/0‟
True
Str[i] =toupper(str[t])
int i = i+1
STOP
89
C++ Assignment 2010
90
C++ Assignment 2010
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:-
91
C++ Assignment 2010
Flowchart:-
START
int i, j, flag
char string[80]
INPUT: string
l=0
False for(i<l/2)
True
l = l+1
False for(i<l/2)
True
False
If(string[i]
!string[j]
True
Flag=0;break
i=i+1
if(flag) True
Else
PRINT:”not PRINT:”Palindrome
Palindrome
STOP
92
C++ Assignment 2010
93
C++ Assignment 2010
Program:-
#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:-
94
C++ Assignment 2010
Flowchart:-
START
int n
INPUT: n
PRINT:”Factorial”
STOP
Flowchartof fact(int i)
START
long result
True If Else
(n==0)
result =1 result =2
int i
i=i+1
STOP
95
C++ Assignment 2010
void showdata()
{Write : “Rollno”,rollno
Write : “Name”,name
} [End of funtion definition]
}[End of class definition]
Step4: Exit
96
C++ Assignment 2010
Program:-
#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();
}
97
C++ Assignment 2010
Output:-
98
C++ Assignment 2010
Que 27:- Write a program to print date using class and object.
99
C++ Assignment 2010
Program:-
#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();
}
100
C++ Assignment 2010
Output:-
101
C++ Assignment 2010
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]
Step4: Exit
103
C++ Assignment 2010
#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()
104
C++ Assignment 2010
{
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:-
105
C++ Assignment 2010
106
C++ Assignment 2010
void display()
{
Write : “Account Number“ , accno
Write :“Balance” , balance
} [End of funtion definition]
Step4: Exit
107
C++ Assignment 2010
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)
{
108
C++ Assignment 2010
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();
}
109
C++ Assignment 2010
Output:-
110
C++ Assignment 2010
111
C++ Assignment 2010
void display()
{
Write : “Account Number“ , accno
Write :“Balance” , balance
} [End of funtion definition]
Step4: Exit
112
C++ Assignment 2010
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;
113
C++ Assignment 2010
}
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();
}
114
C++ Assignment 2010
Output:-
115
C++ Assignment 2010
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;
116
C++ Assignment 2010
Output:-
Flow-chart:-
START
a,b,c,x,x1
a,b,c
x,x1
STOP
117
C++ Assignment 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.
118
C++ Assignment 2010
Program:-
#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:-
119
C++ Assignment 2010
Flowchart:-
START
s,n,sum=0,t
s=n
t = n%10,
sum =sum*10+t,n=n/10
While(n!= 0)
sum
STOP
120
C++ Assignment 2010
121
C++ Assignment 2010
Flow-chart:-
START
s1=0,s2=0,i=1,j=1
if(i<=t)
then
If(j<=i)
s1=s1+j
j=j+1
s2=s2+s1
i=i+1
sum2
STOP
122
C++ Assignment 2010
#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:-
123
C++ Assignment 2010
b)
Author Name:- Premendra Yadaw
Path:- D:\ Angel \series2.CPP
Unit:- II
Date:- 27/10/2008
Flow-chart:-
START
sum=0,i=1
if(i<=n)
sum=sum+1/(i*i)
i=i+1
sum
STOP
124
C++ Assignment 2010
Output:-
125
C++ Assignment 2010
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.
Flow-Chart:-
START
a,b,c
If(a>b)
If(a>c)
a is big
c is big
If(b>c)
b is big
c is small c is big
b is small
a is small
STOP
127
C++ Assignment 2010
/*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";}
}
128
C++ Assignment 2010
else if(snd<trd)
{
cout<<"\nsecond no. is smallest";
}
else
{
cout<<"\nthird no. is smallest";
}
getch();
}
Output:-
129
C++ Assignment 2010
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.
130
C++ Assignment 2010
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);
131
C++ Assignment 2010
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:-
132
C++ Assignment 2010
133
C++ Assignment 2010
Flow-Chart:- START
Term,a=0,b=1,c=0,
Sum=0,i=3
a,b
sum=a+b
While(i<=n)
c=a+b
sum=sum+c
a=b, b=c,
i=i+1
sum
STOP
134
C++ Assignment 2010
#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:-
135
C++ Assignment 2010
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.
137
C++ Assignment 2010
#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'
138
C++ Assignment 2010
||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:-
139
C++ Assignment 2010
140
C++ Assignment 2010
Program:-
#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();}
141
C++ Assignment 2010
Output:-
142
C++ Assignment 2010
143
C++ Assignment 2010
#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();
}
144
C++ Assignment 2010
Output:-
145
C++ Assignment 2010
#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;
147
C++ Assignment 2010
148
C++ Assignment 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.
150
C++ Assignment 2010
151
C++ Assignment 2010
Program:-
#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();
152
C++ Assignment 2010
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:-
153
C++ Assignment 2010
154
C++ Assignment 2010
155
C++ Assignment 2010
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);
156
C++ Assignment 2010
a.show();
b.show();
c.show();
getch();
}
Output:-
157
C++ Assignment 2010
158
C++ Assignment 2010
159
C++ Assignment 2010
#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;
160
C++ Assignment 2010
Output:-
161
C++ Assignment 2010
Step4: x=y;
Step5: y=t;
}[End of function definition]
Step6: Exit
163
C++ Assignment 2010
#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;
164
C++ Assignment 2010
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:-
165
C++ Assignment 2010
166
C++ Assignment 2010
167
C++ Assignment 2010
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;
168
C++ Assignment 2010
Output:-
169
C++ Assignment 2010
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++)
171
C++ Assignment 2010
{
cout<<"* ";
}
cout<<"\n";
}
getch();
}
Output:-
172
C++ Assignment 2010
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]
174
C++ Assignment 2010
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];
}
}
}
175
C++ Assignment 2010
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();
176
C++ Assignment 2010
Output:-
177
C++ Assignment 2010
178
C++ Assignment 2010
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
179
C++ Assignment 2010
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++;
}
}
180
C++ Assignment 2010
Ooutput:-
181
C++ Assignment 2010
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
183
C++ Assignment 2010
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();
184
C++ Assignment 2010
p3.add(p1,p2);
cout<<" p1+p2 = ";
p3.show();
getch();
}
Output:-
185