Vous êtes sur la page 1sur 151

Programming in C++

Submitted To: Mrs. Lovejinder Kaur

Submitted By: Avneet Kaur BCA-2nd year Roll No- 14710000275

Guru Nanak Khalsa College For Women, Gujharkhan Campus, Model Town,Ludhiana

INDEX
S.NO
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22.

CONTENTS
Wap to print a string. Wap to reading an object from file. Wap to find average of two numbers. Wap to swap to numbers. Wap to calculate simple interest. Wap to print fibonacci series. Wap to find the greatest among three. Wap to add,multiply,subtract or divide using switch statement. Wap to calculate area of circle using symbolic constants. Wap to calculate grow salary of an employee and HRA, PF, DA and other funds. Wap to calculate number is even or odd using if else statement. Wap to Area of triangle, circle & rectangle using switch statement Wap to calculate sum of five digit number Wap to reverse a number and check if it is in palindrome or not. Wap to check whether the character is in uppercase and lowercase. Wap to arrange three numbers in ascending order. Wap to whether character is uppercase or lowercase Wap to show dynamic initializing of variables. Wap to default arguments.

Functions
Wap to show use of scope resolution operator. Wap to show the use manipulators. Wap to show inline function.

23. 24.

Wap to add 2 times using function arguments. Wap to illustrate return by reference.

Classes
25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. Wap to show concept of classes. Wap to display complex numbers using class. Wap to display date, month, year using class. Wap to static member function. Wap to array of objects. Wap to illustrate objects and classes within classes. Wap to show another program using classes. Wap to use of class.

Operator overloading
Wap to operator overloading using friend function. Wap to operator overloading using binary operator. Wap to use unary operator. Wap to relational operator overloading. Wap to function overloading.

Constructor and Destructor


Wap to constructor in derived class. Wap to parameterized constructors. Wap to initialization in constructors. Wap to dynamic constructor. Wap to copy constructor. Wap to calculate area of rectangle using overloading constructor.

Inheritance
44. 45. Wap to single inheritance using public mode. Wap to single inheritance using private mode.

46. 47. 48. 49. 50. 51.

Wap to hybrid inheritance. Wap to multilevel inheritance. Wap to multiple inheritance. Wap to heirarichal inheritance. Wap to create a grade card using inheritance. Wap to create an employees salary structure using inheritance.

Pointers
52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. Wap to show the use of this pointer. Wap to show how to refer to pointers address by using pointers. Wap to show the manipulation of pointers. Wap to implement array of pointers. Wap to show array of pointers to objects. Wap to perform arithmetic operations on pointers. Wap to ilustrate how pinters work to access to derived class. Wap to show how to access the array contents using pointers. Wap to show how to access strings using pointers and arrays. Wap to show how to declare and define function pointers. Wap to show how to use pointers to objects. Wap to illustrate the use of virual functions using pointers.

Managing Console I/O operations


64. 65. 66. Wap to show character I/O with get() and put(). Wap to demonstrate the use of getline() for reading the strings. Wap to Display string wuth write().

67. 68. 69. 70. 71. 72.

Wap to specify field size with width(). Wap to show precision setting with precision(). Wap to show padding with fill().

Working with files


Wap to illustrate how class objects canbe written to and read from the disk files. Wap to open a binary file for storing a set of numbers on a file. Wap to converting lowercase to uppercase

Program: To wap to printing a string??


#include<iostream.h> #include<conio.h> void main() { clrscr(); cout<<" C++ is better than C:\n"; getch(); }

Output:
C++ is better than C:

Program: To read an object from a file??


#include<iostream.h> #include<conio.h> #include<fstream.h> class student_info { protected: char name[20]; int age; char sex; public: void get(); void display(); }; void main() { clrscr(); student_info obj; fstream infile; infile.open("data",ios::in); infile.read((char*)&obj,sizeof(obj)); infile.close(); }

Program: Wap to find average of two numbers??


#include<iostream.h> #include<conio.h> void main() { clrscr(); float number1,number2, sum,average; cout<<"enter two numbers:"; cin>>number1; cin>>number2; sum=number1+number2; average =sum/2; cout<<"sum="<<sum<<"\n"; cout<<"average="<<average<<"\n"; getch(); }

Output:
enter two numbers:23 34

Program: To swapping two numbers??


#include<iostream.h> #include<conio.h> void swap(int &,int &); void main() { clrscr(); int a,b; cout<<" enter value of a and b:\n"; cin>>a>>b; swap(a,b); cout<<" value after swapping \n"<<a<<"\n"<<b<<"\n"; getch(); } void swap(int &x,int &y) { int t; t=x; x=y; y=t; cout<<" value in swapping \n"<<x<<"\n"<<y<<"\n"; }

Output:
enter value of a and b: 45 34 value in swapping

34 45 value after sawpping 34 45

Program: To calculate the simple interest??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,c,d; float i; cout<<"\n enter a,b,c:\n"; cin>>a>>b>>c; d=(a*b*c); cout<<"\n D:"<<d<<"\n"; i=d/100; cout<<"\n INTERSET:"<<i; getch(); }

Output:
enter a,b,c: 34 23 67 D:-13142 INTERSET:-131

Program: To print fibonacci series??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int a=0,b=1,n; int c=0; cout<<" enter n:"; cin>>n; if(n==1) cout<<"0"; if(n==2) cout<<"1"; for(int i=3;i<=n;i++) { c=a+b; a=b; b=c; } if(c!=0) cout<<n<<"the number is"<<c; getch(); }

Output:
enter n: 45 45th number is-23075

Program: To greatest among three numbers??


#include<iostream.h> #include<conio.h> void main() { clrscr(); float a,b,c; cout<<" enter the value of the number:"; cin>>a>>b>>c; if (a>b) { if (a>c) cout<<"a is greatest"; else cout<<"c is greatest"; } else if(b>a) cout<<"b is greatest"; else cout<<" c is greatest"; getch(); }

Output:
enter the value of the number: 45 34 23 a is greatest

Program: To add ,subtract,multiply,divide using switch statement??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int a, b,i,c; cout<<"\n enter 2 numbers:"; cin>>a>>b; cout<<"\n1.ADDITION"; cout<<"\n2.SUBTRACTION"; cout<<"\n3.MULTIPLICATION"; cout<<"\n4.DIVISION"; cin>>i; switch(i); { case1:c=a+b; cout<<"addition is:"<<c;

case2:c=a-b; cout<<"subtraction is:"<<c;

case3:c=a*b; cout<<"multiplication is:"<<c; case4:c=a/b;

cout<<"division is:"<<c; } getch(); }

Output:
enter 2 numbers: 45 35

1.ADDITION 2.SUBTRACTION 3.MULTIPLICATION 4.DIVISION

addition is:70 subtraction is:10 multiplication is: 1575 division is:1

Program: To area of circle using symbolic constants??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int r; float a; const float pi=3.14; cout<<" enter radius:"; cin>>r; cout<<" radius:"<<r<<"\n"; a=pi*r*r; cout<<"area of circle:"<<a; getch(); }

Output:
enter radius:6 radius:6 area of circle:113.040001

Program: To calculate grow salary of employee and HRA, PF, DA and other funds??
#include<iostream.h> #include<conio.h> class employee { int empno; char ename[30]; float basic,hra,pf,da,of,sal; public: void get() { cout<<" enter employee no"; cout<<" enter employee name"; cout<<"enter basic salary"; cin>>empno>>ename>>basic; } void show() { cout<<endl<<"employee no"<<empno; cout<<endl<<"employee name"<<ename; cout<<endl<<"basic salary"<<basic; cout<<endl<<"hra"<<hra; cout<<"da"<<da<<"\n"<<"pf"<<pf<<"\n"<<"other fund"<<of<<"\n" <<"gross salary"<<sal<<"\n";

} }; void calculate() { if(basic>0 && basic<10000) { hra=0.02*basic; da=0.03*basic; pf=0.0; of=0.0; } else { if(basic>30000 && basic<70000) { hra=0.1*basic; da=0.07*basic; pf=0.1*basic; of=0.02*basic; } else { hra=0.15*basic; da=0.1*basic; pf=0.2*bsal; of=0.05*basic; sal=basic+hra+da-of-pf;

} } } void main() { clrscr(); employee e; e.get(); e.show(); getch(); }

Program: To number is even or odd using if else??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int n,c; cout<<" enter number:"; cin>>n; cout<<" number:"<<n<<"\n"; c=n%2; if(c==0) cout<<" number"<<n<<" is even"; else cout<<" number"<<n<<" is odd"; getch(); }

Output:
enter number: 56 number:56 number 56 is even

Program : Area of triangle, circle, rectangle using switch statement:


#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,base,alt,r,l,b; float pi,c; cout<<"\n1.area of triangle"; cout<<"\n2.area of circle"; cout<<"\n3.area of rectangle"; cin>>i; switch(i) { cout<<"enter values:"; cin>>base>>alt; c=0.5*base*alt; cout<<"area of triangle:"<<c; const float pi=3.14; cout<<"enter value:"; cin>>r; c=pi*r*r; cout<<"area of circle:"<<c; cout<<"enter value:"; cin>>l>>b; c=l*b;

cout<<"area of rectangle is:"<<c; } getch(); }

Output:
1.area of triangle 2.area of circle 3.area of rectangle 45 enter value:34 34 area of triangle is:5.78 enter value:2 area of circle is:12.56 enter value:2 area of rectangle is:6042

Program: To calculate sum of five digit number??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int n; cout<<" enter 5-digit number:"; cin>>n; cout<<"5-digit number:"<<n<<"\n"; int n1,sum=0; while(n>0) { n1=n%10; sum=sum+n1; n=n/10; } cout<<" sum of 5-digit number is:"<<sum; getch(); }

Output:
enter 5-digit number: 12345 5-digit number:12345 sum of 5-digit number is:15

Program: To calculate reverse of a number & check it is palindrome or not??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int rem=0,rev=0,c=0; int num,z; cout<<" enter a number:"; cin>>z; num=z; while(num>0) { rem=num%10; num=num/10; rev=(rev*10)+rem; } cout<<" reversed number is:"<<rev; if(z==rev) { cout<<"\n number is palindrome"; c=1; } if(c==0)

{ cout<<"\n number is not palindrome"; } getch(); }

Output:
enter a number: 345 reversed number is:543 number is not palindrome

Program: To check whether character is in uppercase or lowercase??


#include<iostream.h> #include<conio.h> void main() { clrscr(); char ch; cout<<"\n enter ch:"; cin>>ch; cout<<"\n character :"<<ch; if((ch>=65)&&(ch<=90)) cout<<"\n character"<<ch<<" is in upper case"; else if((ch>=97)&&(ch<=122)) cout<<"\n character"<<ch<<" is in lower case"; else cout<<"\n no character"; getch(); }

Output:
enter ch: B character :B character B is in upper case

Program: To arrange three numbers in ascending order??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,c; cout<<"\n enter values of three numbers:\n"; cin>>a>>b>>c; cout<<"\nA:"<<a<<"\nB:"<<b<<"\nC:"<<c<<"\n"; if((a>b)&&(a>c)) { if(b>c) cout<<"\nc:"<<c<<"\na:"<<a<<"\nb:"<<b; else cout<<"\nb:"<<b<<"\nc:"<<c<<"\na:"<<a; } else if((b>a)&&(b>c)) { if(a>c) cout<<"\nc:"<<c<<"\na:"<<a<<"\nb:"<<b; else cout<<"\na:"<<a<<"\nc:"<<c<<"\nb:"<<b; }

else if((c>a)&&(c>b)) { if(a>b) cout<<"\nb:"<<b<<"\nc:"<<c<<"\na:"<<a;

else cout<<"{\na:"<<a<<"\nb:"<<b<<"\nc:"<<c; getch(); } }

Output:
enter values of three numbers: 10 20 30

A:10 B:20 C:30

a:10 b:20 c:30

Program: To dynamic initialization of variables??


#include<iostream.h> #include<conio.h> class integer { int a,b; public: integer() { a=0; b=0; } integer( int m,int n) { a=m; b=n; } void display() { cout<<"A:"<<a<<"\n"<<"B:"<<b<<"\n"; } }; void main() { clrscr();

int x,y; cout<<" enter value of x and y:\n"; cin>>x>>y; integer n1;

integer n2(x,y); n1.display(); n2.display(); getch(); }

Output:
enter value of x and y: 10 20 A:0 B:0 A:10 :20

Program: Wap to default arguments??


#include<iostream.h> #include<conio.h> #include<stdio.h> void main() { clrscr(); float amount; float value(float p,int n,float r=0.15); void printline(char ch='*',int len=40); printline(); amount=value(5000.00,5); cout<<"\n final value="<<amount<<"\n\n"; printline('='); getch(); } float value(float p,int n,float r) { int year=1; float sum=p; while(year<=n) { sum=sum*(1+r); year=year+1; }

return(sum); } void printline(char ch,int len) {

for(int i=1;i<=len;i++)printf("%c",ch); printf("\n"); }

Output:
****************************************

final value=10056.786133

Program: Wap to scope resolution operator ??


#include<iostream.h> #include<conio.h> int m=10; void main() { clrscr(); int m=20; { int k=m; int m=30; cout<<" we are in inner block \n"; cout<<" k="<<k<<"\n"; cout<<"m="<<m<<"\n"; cout<<"::m="<<::m<<"\n"; } cout<<"\n we are in outer block \n"; cout<<"m="<<m<<"\n"; cout<<"::m="<<::m<<"\n"; getch(); }

Output:
we are in inner block k=20

m=30 ::m=10

we are in outer block m=20 ::m=10

Program: Wap to manipulators of pointers??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int a=10,*ptr; ptr=&a; cout<<" the value of a is :"<<a; cout<<"\n\n"; *ptr=(*ptr)/2; cout<<" the value of a is :"<<(*ptr); cout<<"\n\n"; getch(); }

Output:
the value of a is :10 the value of a is :5

Program: To wap to inline function??


#include<iostream.h> #include<conio.h> inline float mul(float x,float y) { return(x*y); } inline double div(double p,double q) { return (p/q); } void main() { clrscr(); float a=12.345; float b=9.82; cout<<mul(a,b)<<"\n"; cout<<div(a,b)<<"\n"; getch(); }

Output:
121.227898 1.257128

Program: To add two times using function arguments??


#include<iostream.h> #include<conio.h> class time { int hrs,min; public: void get(int h,int m) { hrs=h; min=m; } void display() { cout<<hrs<<":"<<min; } void sum(time t1,time t2) { min=t1.min+t2.min; hrs=min/60; min=min%60; hrs=hrs+t1.hrs+t2.hrs; } }; void main()

{ clrscr(); time T1,T2,T3; T1.get(45,89); T2.get(4,67); T3.sum(T1,T2); T1.display(); T2.display(); T3.display(); getch(); }

Output:
45:894:6751:36

Program: To wap to return by reference??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int x=10; int & modify(int &); modify(x)=25; cout<<"\n value of x="<<x; getch(); } int & modify(int &y) { cout<<" value of y="<<y; return y; }

Output:
value of y=10 value of x=25

Program: To wap to showing concept of class??


#include<iostream.h> #include<conio.h> class item { int a,b; public: void get(int x,int y) { a=x; b=y; } void display() { cout<<"a:"<<a<<"\n"; cout<<"b:"<<b<<"\n"; } }; void main() { clrscr(); item c,d; cout<<"\n object c "<<"\n"; cout<<"\n object d"<<"\n"; c.get(100,299);

c.display(); d.get(200,300); d.display(); getch(); }

Output:
object c object d a:100 b:299 a:200 b:300

Program: To display complex numbers using class??


#include<iostream.h> #include<conio.h> class number { int a,b; public: void get(int real,int imag) { a=real; b=imag; } void show() { cout<<"\n COMPLEX NUMBER:"<<a<<"+"<<b<<"\n"; } }; void main() { clrscr(); number n; n.get(10,20); n.show(); number n1; n1.get(40,70);

n1.show(); getch(); }

Output:
COMPLEX NUMBER:10+20 COMPLEX NUMBER:40+70

Program: To display date,month,year,using class??


#include<iostream.h> #include<conio.h> class date { int a,b,c; public: void get(int date,int month,int year) { a=date; b=month; c=year; } void show() { cout<<"\n DATE:"<<a<<"-"<<b<<"-"<<c<<"\n"; } }; void main() { clrscr(); date d1; d1.get(17,9,1990); d1.show(); date d2;

d2.get(6,7,1984); d2.show(); getch(); }

Output:
DATE:17-9-1990 DATE:6-7-1984

Program: Wap to static member function??


#include<iostream.h> #include<conio.h> class test { int code; static int count; public: void set() { code=++count; } void show() { cout<<" object number:"<<code<<"\n"; } static void showcount() { cout<<"count:"<<count<<"\n"; } }; int test :: count; void main() { clrscr();

test t1,t2; t1.set(); t2.set(); test:: showcount(); test t3; t3.set(); test ::showcount(); t1.show(); t2.show(); t3.show(); getch(); }

Output:
count:2 count:3

Program: To wap to array of objects??


#include<iostream.h> #include<conio.h> class babita { char name[30]; float age; public: void get() { cout<<"enter name:"; cin>>name; cout<<"enter age:"; cin>>age; } void display() { cout<<"name:"<<name<<"\n"; cout<<"age:"<<age<<"\n"; } }; const int size=3; void main() { clrscr();

babita manager[size]; for(int i=0;i<size;i++) { cout<<"\n details of manager"<<i+1<<"\n"; manager[i].get(); } cout<<"\n"; for(i=0;i<size;i++) { cout<<"\n manager"<<i+1<<"\n;"; manager[i].display(); } getch(); }

Output:
details of manager1 enter name: baby enter age:30

details of manager2 enter name:barbie enter age:60

details of manager3 enter name:bani enter age:80

manager1 name:baby age:30

manager2 name:barbie age:60

manager3 name:bani age:80

Program: To illustrate objects and classes within class??


#include<iostream.h> #include<conio.h> class item { float price[50]; float sum; public: void get() { cout<<" enter limit"; cin>>n; cout<<" enter item="<<n; for(int i=0;i<n;i++) { cin>>code[i]>>price[i]; } } void display() { cout<<" items are"; for(i=0;i<n;i++) { cout<<enter <<code[i]<<" price[i]"; void sum of price()

{ for(i=0;i<n;i++) { sum=sum+price[i]; } cout<<" sum="<<sum; } } }; void main() { clrscr(); item t; t.get(); t.display(); getch(); }

Program: To another program using class??


#include<iostream.h> #include<conio.h> class item { int a,b; public: void get(int x,int y) { a=x; b=y; } void put() { cout<<" a:"<<a<<"\n"<<"b:"<<b<<"\n"; } }; void main() { clrscr(); item t; t.get(100,200); t.put(); getch(); }

Output:
a:100 b:200

Program: To wap to use of class??


#include<iostream.h> #include<conio.h> class person { char name[30]; int age; public: void get() { cout<<"enter name:"; cin>>name; cout<<"enter age:"; cin>>age; } void show() { cout<<"\n name:"<<name; cout<<"\n age:"<<age; } }; void main() { clrscr(); person p;

p.get(); p.show(); getch(); }

Output:
enter name:babita enter age:23

Program: To wap to operator overloading using friend function??


#include<iostream.h> #include<conio.h> const size=3; class vector { int v[size]; public: vector(); vector(int *x); friend vector operator *(int a,vector b); friend vector operator *(vector b,int a); friend istream & operator>> (istream &,vector &); friend ostream & operator<< (ostream & ,vector &); }; vector:: vector() { for(int i=0;i<size;i++) v[i]=0; } vector::vector(int *x) { for(int i=0;i<size;i++) v[i]=x[i]; }

vector operator*(int a,vector b) { vector c; for(int i=0;i<size;i++) c.v[i]=a*b.v[i]; return c; } vector operator *(vector b,int a) { vector c; for(int i=0;i<size;i++) c.v[i]=b.v[i]*a; return c; } istream & operator>>(istream &din,vector &b) { for(int i=0;i<size;i++) din>>b.v[i]; return(din); } ostream & operator<< (ostream &dout,vector &b) { dout<<"("<<b.v[0]; for(int i=1;i<size;i++) dout<<","<<b.v[i]; dout<<")"; return(dout);

} int x[size]={2,4,6}; void main() { clrscr(); vector m; vector n=x; cout<<"enter elements of vector m"<<"\n"; cin>>m; cout<<"\n"; cout<<"m="<<m<<"\n"; vector p,q; p=2*m; q=n*2; cout<<"\n"; cout<<"p="<<p<<"\n"; cout<<"q="<<q<<"\n"; getch(); }

Output:
enter elements of vector m 5 6 7

m=(5,6,7)

p=(10,12,14) q=(4,8,12)

Program: To wap to operator overloading using binary operator??


#include<iostream.h> #include<conio.h> class complex { float x,y; public: complex() { } complex(float real ,float imag) { x=real; y=imag; } void show() { cout<<x<<"+j"<<y<<"\n"; } complex operator+(complex c) { complex temp; temp.x=x+c.x; temp.y=y+c.y; return(temp);

} }; void main() { clrscr(); complex c1,c2,c3; c1=complex(2.5,3.5); c2=complex(1.6,2.7); c3=c1+c2; cout<<"c1="; c1.show(); cout<<"c2="; c2.show(); cout<<"c3="; c3.show(); getch(); }

Output:
c1=2.5+j3.5 c2=1.6+j2.7 c3=4.1+j6.2

Program: To wap to unary operator??


#include<iostream.h> #include<conio.h> class space { int x,y,z; public: void get(int a,int b,int c) { x=a; y=b; z=c; } void show() { cout<<x<<"\n"; cout<<y<<"\n"; cout<<z<<"\n"; } void operator-() { x=-x; y=-y; z=-z; }

}; void main() { clrscr(); space s; s.get(10 ,-20,30); cout<<"s:"; s.show(); -s; cout<<"s:"; s.show(); getch(); }

Output:
s:10 -20 30 s:-10 20 -30

Program: To relational operator overloading??


#include<iostream.h> #include<conio.h> class data { int x,y; public: data() { x=17; y=12; } data(int a,int b) { x=a; y=b; } void display() { cout<<"x"<<x; cout<<"y"<<y; } friend int operator>(data d1,data d2); }; int operator> (data d1,data d2)

{ if(d1.x>d2.x &&d1.y>d2.y) { return(1);

} else { return(0); } }; void main() { clrscr(); data d1; data d2(4,6); data d3(32,25); if(d1>d2) { cout<<" object 1 is greater"; d1.display(); } else { cout<<" object 2 is greater"; d2.display(); }

if(d1>d3) { cout<<" obj1 is greater"; d1.dispaly(); } else { cout<<" obj3 is greater"; d3.display(); getch(); } }

Program: To wap to function overloading??


#include<iostream.h> #include<conio.h> int volume(int); double volume(double,int); long volume(long,int ,int); void main() { clrscr(); cout<<volume(10)<<"\n"; cout<<volume(2.5,8)<<"\n"; cout<<volume(100l,75,15)<<"\n"; getch(); } int volume(int s) { return(s*s*s); } double volume(double r,int h) { return(3.14519*r*r*h); } long volume(long l,int b,int h) { return(l*b*h);

Output:
1000 157.2595 112500

Program: Wap to constructor in derived class??


#include<iostream.h> #include<conio.h> class a { int x; public: a(int i) { x=i; } void show_a() { cout<<"x="<<x<<"\n"; } }; class b { float y; public: b(int j) { y=j; } void show_b()

{ cout<<"y="<<y<<"\n"; } }; class c:public a,public b { int m,n; public: c(int e,int f,int g):a(e),b(f) { m=f; n=g; } void show_c() { cout<<"m="<<m<<"\n"; cout<<"n="<<n<<"\n";} }; void main() { clrscr(); c c1(5,45,56); cout<<"\n"; c1.show_a(); c1.show_b(); c1.show_c(); getch();

Output:
x=5 y=45 m=45 n=56

Program: Wap to parameterized constructors??


#include<iostream.h> #include<conio.h> class integer { int m,n; public: integer(int x ,int y) { m=x; n=y; } void show() { cout<<"m="<<m<<"\n"; cout<<"n="<<n<<"\n"; } }; void main() { clrscr(); integer int1(45,100); integer int2=integer(25,67); cout<<"\n object1"<<"\n"; int1.show();

cout<<"\n object2"<<"\n"; int2.show(); getch(); }

Output:
object1 m=45 n=100

object2 m=25 n=67

Program: To wap to initialization in constructors??


#include<iostream.h> #include<conio.h> class a { int x; public: a(int i) { x=i; cout<<"\n a constructed"; } void show_a() { cout<<"x="<<x<<"\n"; } }; class b { int p,q; public: b(int j,int k):p(j),q(k+p) { cout<<"\n b constructed"; }

void show_b() { cout<<"p="<<p<<"\n"; cout<<"q="<<q<<"\n"; } }; class c: public b,public a { int u,v; public: c(int j,int k,int l):a(j*2),b(l,l),u(j),v(k) { cout<<"\n c constructed"; } void show_c() { cout<<"u="<<u<<"\n"; cout<<"v="<<v<<"\n"; } }; void main() { clrscr(); c c1(4,6,9); cout<<"\n\n display member values"<<"\n\n"; c1.show_a(); c1.show_b();

c1.show_c(); getch(); }

Output:
b constructed a constructed c constructed

display member values

x=8 p=9 q=18 u=4 v=6

Program: To wap to dynamic constructor??


#include<iostream.h> #include<conio.h> #include<string.h> class string { char *name; int length; public: string() { length=0; name=new char[length+1]; } string(char *s) { length=strlen(s); name=new char[length+1]; strcpy(name,s); } void display() { cout<<name<<"\n"; } void join (string &a,string &b);

}; void string:: join (string &a,string &b) { length =a.length+b.length; delete name; name=new char[length+1]; strcpy(name,a.name); strcat(name,b.name); }; void main() { clrscr(); char *first="babita"; string name1(first), name2("choudhary"), name3("kaur"),s1,s2; s1.join(name1,name2); s2.join(s1,name3); name1.display(); name2.display(); name3.display(); s1.display(); s2.display(); getch(); }

Output:
Jasmeen Gulati kaur Jasmeen Gulati Jasmeen Gulati Kaur

Program: Wap to copy constructor??


#include<iostream.h> #include<conio.h> class code { int id; public: code() { } code(int a) { id= a; } void display() { cout<<"\n id"; } code(code &x) { id=x.id; } void display_id() { cout<<id;

} }; void main() { clrscr(); code A(100); code B(A); code C=A; code D; D=A; cout<<"\n id of A:"; A.display_id(); cout<<"\n id of B:"; B.display_id(); cout<<"\n id of C:"; C.display_id(); cout<<"\n id of D:"; D.display_id(); getch(); }

Output:
id of A:100 id of B:100 id of C:100 id of D:100

Program: To area of rectangle using overloading constructor??


#include<iostream.h> #include<conio.h> class area { int l,a,b; public: area() { l=10;b=20; } area(int length,int breadth) { l=length; b=breadth; } area(area &a) { l=a.l; b=a.b; } void display() { a=l*b; cout<<"area of rectangle:"<<a<<"\n";

} }; void main() { clrscr(); area a1; a1.display(); area a2(100,200); a2.display(); area a3(a1); a3.display(); getch(); }

Output:
area of rectangle:200 area of rectangle:20000 area of rectangle:200

Program: To wap to single inheritance using public mode??


#include<iostream.h> #include<conio.h> class B { int a; public: int b; void get_ab(); int get_a(); void show_a(); }; class D:public B { int c; public: void mul(); void display(); }; void B::get_ab() { a=56; b=89; } int B::get_a()

{ return(a); } void B::show_a() { cout<<"\n a="<<a<<"\n"; } void D::mul() { c=b*get_a(); } void D::display() { cout<<"a="<<get_a()<<"\n"; cout<<"b="<<b<<"\n"; cout<<"c="<<c<<"\n"; } void main() { clrscr(); D d; d.get_ab(); d.mul(); d.show_a(); d.display(); d.b=20; d.mul();

d.display(); getch(); }

Output:
a=56 a=56 b=89 c=4984 a=56 b=20 c=1120

Program: To wap to single inheritance using private mode??


#include<iostream.h> #include<conio.h> class B { int a; public: int b; void get_ab(); int get_a(); }; class D:private B { int c; public: void mul(); void display(); }; void B::get_ab() { a=8; b=10; } int B::get_a() {

return(a); } void D::mul() { get_ab(); c=b*get_a(); } void D:: display() { cout<<"A:"<<get_a()<<"\n"; cout<<"B:"<<b<<"\n"; cout<<"\n C:"<<c<<"\n"; } void main() { clrscr(); D s1; s1.mul(); s1.display(); getch(); }

Output:
A:8 B:10 C:80

Program: To wap to hybrid inheritance??


#include<iostream.h> #include<conio.h> class A { protected: int rollno; public: void get_a() { cout<<"\n enter rollno="; cin>>rollno; } }; class B:public A { protected: int sub1,sub2; public: void get_b() { cout<<"\n enter subject1:"; cin>>sub1; cout<<"\n enter subject2:"; cin>>sub2;

} }; class D { protected: int activities; float marks; public: void get_d() { cout<<"enter student activities ="; cin>>activities; cout<<" enter marks="; cin>>marks; } }; class C:public B,public D { float total; public: void sum() { total=sub1+sub2+activities; } void show() { cout<<"sum is "<<total;

} }; void main() { clrscr(); C obj; obj.get_a(); obj.get_b(); obj.get_d(); obj.sum(); obj.show(); getch(); }

Output:
enter rollno=1001

enter subject1:english

enter subject2:

enter student activities = enter marks=sum is 19920

Program: To wap to multilevel inheritance??


#include<iostream.h> #include<conio.h> class A { protected: int x; public: void get_a(int i) { x=i; } void show_a() { cout<<" X="<<x<<"\n"; } }; class B { protected: int y; public: void get_b(int j) { y=j;

} void show_b() { cout<<"Y="<<y<<"\n"; } }; class C:public B { int z; public: void get_c(int k) { z=k; } void display() { cout<<"Z="<<z<<"\n"; } }; void main() { clrscr(); C c1; c1.get_b(121); c1.get_c(131); c1.show_b(); c1.display();

getch(); }

Output:
Y=121 Z=131

Program: To wap to multiple inheritance??


#include<iostream.h> #include<conio.h> class A { protected: int a; public: void get_a(int x) { a=x; } void display() { cout<<"\n A="<<a; } }; class B { protected: int b; public: void get_b(int y) { b=y;

} void display_b() { cout<<"\n B="<<b; } }; class C:public A, public B { int c; public: void sum() { c=a+b; } void show() { cout<<"\n C="<<c; } }; void main() { clrscr(); C c1; c1.get_a(100); c1.display(); c1.get_b(200); c1.display_b();

c1.sum(); c1.show(); getch(); }

Output:
A=100 B=200 C=300

Program: To wap to hierachical inheritance??


#include<iostream.h> #include<conio.h> class base { protected: int a; public: void get_a(int x) { a=x; } void display() { cout<<"\n base A="<<a; } }; class square:public base { int l; public: void squ() { l=a*a; }

void show() { cout<<" square of no: A:"<<l; } }; class cube: public base { int l; public: void cub() { l=a*a*a; } void show_c() { cout<<"\n cube of no"<<a; } }; void main() { clrscr(); square s1; cube c1; s1.display(); s1.squ(); s1.show(); c1.get_a(47);

c1.display(); c1.cub(); c1.show_c(); getch(); }

Output:
base A=0 square of no: A:0 base A=47 cube of no =47

Program: To create a grade card using inheritance??


#include<iostream.h> #include<conio.h> class person { int rollno; char name[20],address[30]; public: void get() { cout<<" enter rollno"; cin>>rollno; cout<<"enter name"; cin>>name; cout<<"enter address"; cin>>address; } void show() { cout<<"ROLLNO"<<rollno; cout<<"NAME"<<name; cout<<"ADDRESS"<<address; } }; class result:public person

float m1,m2,m3,tm,per; public: void getdata() { cout<<" enter marks of 3 subjects"; cin>>m1>>m2>>m3; } void calculate() { tm=m1+m2+m3; per=tm/3; } void display() { calculate(); cout<<"total marks"<<tm; cout<<" percentage"<<per; } }; void main() { result r; r.getdata(); r.display(); getch();

Output:
enter marks of 3 subjects 45 67 89

total marks 201 percentage 67

Program: To create an employee's salary structure using inheritance??


#include<iostream.h> #include<conio.h> class employee { int empno; char ename[20],bsal[30]; pubic: void input() { cout<<" enter employee no"; cin>>empno; cout<<" enter employee name"; cin>>ename; cout<<" enter basic salary"; cin>>bsal; } void show() { cout<<endl<<"employee no"<<empno; cout<<endl<<"employee name"<<ename; cout<<endl<<" basic salary"<<bsal; } };

class result: public employee { input(); float hra,da,pf,of,gross salary; public: void getdata() { cout<<" enter<<hra<<da<<pf<<of<<gross salary"; cin>>hra>>da>>pf>>of>>gross salary; } void sum() { gross salary=hra+da-pf-of; } void display() { sum(); cout<<" basic salary"<<gsal; } }; void main() { clrscr(); result r; r.getdata(); r.display(); r.sum(); getch(); }

Program: To show the use of this pointer??


#include<iostream.h> #include<conio.h> #include<string.h> class person { char name[20]; float age; public: person(char *s,float a) { strcpy(name,s); age=a; } person & person::greater(person & x) { if(x.age>=age) return x; else return *this; } void display(void) { cout<<"name:"<<name<<"\n"; cout<<"age:"<<age<<"\n"; }

}; void main() { clrscr(); person p1("john",37.50), p2("amhed",29.0), p3("hebber",40.25); person p=p1.greater(p3); cout<<"elder person is:\n"; p.display(); p=p1.greater(p2); cout<<"elder person is:\n"; p.display(); getch(); }

Output:
elder person is: name:hebber age:40.25 elder person is: name:john age:37.5

Program: To show how to refer to a pointers address by using pointers?


#include<iostream.h> #include<conio.h> void main() { int a, *ptr1, **ptr2; clrscr(); ptr1=&a; ptr2=&ptr1; cout<<"The address of a : "<<ptr1<<"\nThe address of ptr1: " <<ptr1<<"\n\n"; cout<<"After incrementing the address values:\n\n"; ptr1+=2; cout<<"The address of a: "<<ptr1<<"\n"; ptr2+=2; cout<<"The address of ptr1: "<<ptr2; getch(); }

Output:
The address of a : 0x8fa2fff4 The address of ptr1: 0x8fa2fff4 After incrementing the address values: The address of a: 0x8fa2fff8 The address of ptr1: 0x8fa2fff6

Program: To show the manipulation of pointers?


#include<iostream.h> #include<conio.h> void main() { int a= 10,*ptr; ptr=&a; clrscr(); cout<<"The value of a: "<<a; cout<<"\n\n"; *ptr=(*ptr)/2; cout<<"The value of a: "<<(*ptr); cout<<"\n\n"; getch(); }

Output:
The value of a : 10

The value of a : 5

Program: To implement array of pointers??


#include<iostream.h> #include<conio.h> #include<string.h> #include<ctype.h> void main() { int i=0; char *ptr[10]={ "books", "television", "computer", "sports" }; char str[25]; clrscr(); cout<<"\n\n\n\nenter your favorite leisure pursuit:"; cin>>str; for(i=0;i<4;i++) { if(!strcmp(str,ptr[i])) { cout<<"\n\nyour favorite pursuit "<<"is available here"<<endl; break; }

} if(i==4) cout<<"\n\nyour favorite "<<"not available here"<<endl; getch(); }

Output:
enter your favorite leisure pursuit:books

your favorite pursuit is available here

Program: To show array of pointers to objects??


#include<iostream.h> #include<conio.h> #include<string.h> class city { protected: char *name; int len; public: city() { len=0; name=new char[len+1]; } void getname(void) { char *s; s=new char[30]; cout<<"enter city name:"; cin>>s; len=strlen(s); name=new char[len+1]; strcpy(name,s); }

void printname(void) { cout<<name<<"\n"; } }; void main() { city *cptr[10]; int n=1; int option; do { cptr[n]=new city; cptr[n]->getname(); n++; cout<<"do oyu want to enter one more name?\n"; cout<<"(enter 1 for yes 0 for no):"; cin>>option; } while(option); cout<<"\n\n"; for(int i=1;i<=n;i++) { cptr[i]->printname(); } getch(); }

Output:
enter your favorite leisure pursuit:books your favorite pursuit is available here enter city name:hyderabad

do oyu want to enter one more name? (enter 1 for yes 0 for no):1 enter city name:ludhiana do oyu want to enter one more name? (enter 1 for yes 0 for no):1 enter city name:jalandhar do oyu want to enter one more name? (enter 1 for yes 0 for no):0

hyderabad ludhiana jalandhar

Program : To perform arithmetic operations on pointers?


#include<iostream.h> #include<conio.h> void main() { int num[]={56,75,22,18,90}; int *ptr; int i; clrscr(); cout<<"The array values are:\n\n"; for(i=0;i<5;i++) cout<<num[i]<<"\n\n"; ptr=num; cout<<"\nValue of ptr: "<<*ptr<<"\n"; ptr++; cout<<"\nValue of ptr: "<<*ptr<<"\n"; ptr--; cout<<"\nValue of ptr: "<<*ptr<<"\n"; ptr+=2; cout<<"\nValue of ptr: "<<*ptr<<"\n"; ptr-=1; cout<<"\nValue of ptr: "<<*ptr<<"\n"; ptr+=3; cout<<"\nValue of ptr: "<<*ptr<<"\n"; ptr-=2;

cout<<"\nValue of ptr: "<<*ptr<<"\n"; getch(); }

Output:
The array values are: 56 75 22 18 90

Value of ptr: 56 Value of ptr: 75 Value of ptr: 56 Value of ptr: 22 Value of ptr: 75 Value of ptr: 90

Program: To illustrate how pointers work to a derived objects??


#include<iostream.h> #include<conio.h> class bc { public: int b; void show() {cout<<"b="<<b<<"\n";} }; class dc:public bc { public: int d; void show() {cout<<"b="<<b<<"\n"; cout<<"d="<<d<<"\n"; } }; void main() { clrscr(); bc *bptr; bc base; bptr=&base; bptr->b=100;

cout<<"bptr points to base object \n"; bptr->show(); dc derived; bptr=&derived; bptr->b=200; cout<<"bptr now points to derived object \n"; bptr->show(); dc *dptr; dptr=&derived; dptr->d=300; cout<<"dptr is derived type pointer \n"; dptr->show(); cout<<"using((dc *)bptr)\n"; ((dc *)bptr)->d=400; ((dc *)bptr)->show(); getch(); }

Output:
bptr points to base object b=100 bptr now points to derived object b=200 dptr is derived type pointer b=200 d=300

using((dc *)bptr) b=200 d=400

Program: To show how to access the array contents using pointers?


#include<iostream.h> #include<conio.h> void main() { int numbers[50], *ptr; int n,i; cout<<"\nEnter the count\n"; cin>>n; cout<<"\nEnter the numbers one y one"; for(i=0;i<n;i++) cin>>numbers[i]; ptr=numbers; int sum=0; for(i=0;i<n;i++) { if(*ptr%2==0) sum=sum+*ptr; ptr++; } cout<<"\n\nSum of even numbers"<<sum; getch();

Output:
Enter the count 5 Enter the numbers one y one 2 4 7 5 8

Sum of even numbers 14

Program: To show how to access strings using pointers and arrays?


#include<iostream.h> #include<conio.h> #include<string.h> void main() { char str[]="Test"; int len= strlen(str); clrscr(); for(int i=0;i<len;i++) { cout<<str[i]<<i[str]<<*(str+i)<<*(i+str); } int lenM=len/2; len--; for(i=0;i<lenM;i++) { str[i]=str[i]+str[len-i]; str[len-i]=str[i]-str[len-i]; str[i]=str[i]-str[len-i]; } cout<<"The string reversed:"<<str; getch(); }

Output:
TTTTeeeesssstttt The string reversed: tseT

Program: To show how to declare and define function pointers?


#include<iostream.h> #include<conio.h> typedef void(*FunPtr)(int,int); void add(int i,int j) { cout<<i<<"+"<<j<<"="<<i+j; } void subtract(int i,int j) { cout<<i<<"-"<<j<<"="<<i-j; } void main() { FunPtr ptr; ptr=&add; ptr(1,2); ptr=&subtract; ptr(3,2); getch();

Output:
1+2=3 3-2=1

Program: How to use pointers to objects?


#include<iostream.h> #include<conio.h> class item { int code; float price; public: void getdata(int a,float b) { code=a; price=b; } void show(void) { cout<<"code: "<<code<<"\n"; cout<<"Price: "<<price<<"\n"; } };

const int size=2; void main() { item *p=new item[size]; item *d=p; int x,i;

float y; clrscr(); for(i=0;i<size;i++) {

cout<<"\nInput code and price for item\n" <<i+1; cin>>x>>y; p->getdata(x,y); p++; } for(i=0;i<size;i++) { cout<<"\nItem:"<<i+1<<"\n"; d->show(); d++; } getch(); }

Output:
Input code and price for item1 24 56

Input code and price for item2 25 75

Item:1 code: 24 Price: 56

Item:2

code: 25 Price: 75

Program: To illustrate the use of virtual fuctions using pointers??


#include<iostream.h> #include<conio.h> class base { public: void display() { cout<<"\ndisplay base"; } virtual void show() { cout<<"\nshow base"; } }; class derived:public base { public: void display() { cout<<"\n display derived"; } void show() { cout<<"\n show derived"; }

}; void main() { clrscr(); base b; derived d; base *bptr; cout<<"\nbptr points to base\n"; bptr=&b; bptr->display(); bptr->show(); cout<<"\n\n bptr points to derived\n"; bptr=&d;

bptr->display(); bptr->show(); getch(); }

Output:
bptr points to base

display base show base

bptr points to derived

display base show derived

Program: To show character I/O with get() and put()??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int count=0; char c; cout<<"input text\n"; cin.get(c); while(c!='\n') { cout.put(c); count++; cin.get(c); } cout<<"number of characters="<<count<<"\n"; getch(); }

Output:
input text object oriented programming object oriented programming number of characters=27

Program: To demonstrate the use of getline() for reading the strings??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int size=20; char city[20]; cout<<"enter city name:"; cin>>city; cout<<"city name:"<<city<<"\n\n"; cout<<"enter city name:"; cin.getline(city,size); cout<<"city name now:"<<city<<"\n\n"; cout<<"enter another city name:"; cin.getline(city,size); cout<<"new city name:"<<city<<"\n\n"; getch(); }

Output:
enter city name:delhi city name:delhi enter city name:city name now:

enter another city name:chennai new city name:Chennai

Program: To display string with write()??


#include<iostream.h> #include<conio.h> #include<string.h> int main() { char*string1="C++"; char*string2="Programming"; int m=strlen(string1); int n=strlen(string2); for(int i=1;i<n;i++) { cout.write(string2,i); cout<<"\n"; } for(i=n;i>0;i--) { cout.write(string2,i); cout<<"\n"; } // concatenating strings cout.write(string1,m).write(string2,n); cout<<"\n"; // crossing the boundary cout.write(string1,10);

return (0); }

Output:
P Pr Pro Prog Progr Progra Program Programm Programmi Programmin Programming Programmin Programmi Programm Program Progra Progr Prog Pro Pr P C++Programming

Program: To specify field size with width()??


#include<iostream.h> #include<conio.h> void main() { clrscr(); int items[4]={10,8,12,15}; int cost[4]={75,100,60,99}; cout.width(5); cout<<"items"; cout.width(8); cout<<"cost"; cout.width(15); cout<<"total value"<<"\n"; int sum=0; for(int i=0;i<4;i++) { cout.width(5); cout<<items[i]; cout.width(8); cout<<cost[i]; int value=items[i]*cost[i]; cout.width(15); cout<<value<<"\n"; sum=sum+value;

} cout<<"\n grand total="; cout.width(2); cout<<sum<<"\n"; getch(); }

Output:
items cost total value 10 8 12 15 75 100 60 99 750 800 720 1485

grand total=3755

Program: To show precision setting with precision()??


#include<iostream.h> #include<conio.h> #include<math.h> void main() { clrscr(); cout<<"precision set to 3 digits \n\n"; cout.precision(3); cout.width(10); cout<<"VALUE"; cout.width(15); cout<<"SQRT_OF_VALUE"<<"\n"; for(int n=1;n<=5;n++) { cout.width(8); cout<<n; cout.width(13); cout<<sqrt(n)<<"\n"; } cout<<"\n precision set to 5 digits \n\n"; cout.precision(5); cout<<"sqrt(10)="<<sqrt(10)<<"\n\n"; cout.precision(0); cout<<"sqrt(10)="<<sqrt(10)<<"(default setting)\n";

getch(); }

Output:
precision set to 3 digits

VALUE SQRT_OF_VALUE 1 2 3 4 5 1 1.414 1.732 2 2.236

precision set to 5 digits

sqrt(10)=3.16228

sqrt(10)=3.162278(default setting)

rogram: To show padding with fill()??


#include<iostream.h> #include<conio.h> void main() { clrscr(); cout.fill('<'); cout.precision(3); for(int n=1;n<=6;n++) { cout.width(5); cout<<n; cout.width(10); cout<<1.0/float(n)<<"\n"; if(n==3) cout.fill('>'); } cout<<"\n padding changed\n\n"; cout.fill('#'); cout.width(15); cout<<12.345678<<"\n"; getch(); }

Output:
<<<<1<<<<<<<<<1 <<<<2<<<<<<<0.5 <<<<3<<<<<0.333 >>>>4>>>>>>0.25 >>>>5>>>>>>>0.2 >>>>6>>>>>0.167

padding changed

#########12.346

Program: To illustrate how class objects can be written to and read from the disk files??
#include<iostream.h> #include<conio.h> #include<fstream.h> #include<iomanip.h> class INVENTORY { char name[10]; int code; float cost; public: void readdata(void); void writedata(void); }; void INVENTORY::readdata(void) { cout<<"enter name:"; cin>>name; cout<<"enter code:"; cin>>code; cout<<"enter cost:"; cin>>cost; } void INVENTORY::writedata(void)

{ cout<<setiosflags(ios::left) <<setw(10)<<name <<setiosflags(ios::right) <<setw(10)<<code <<setprecision(2) <<setw(10)<<cost <<endl; } void main() { clrscr(); INVENTORY item[3]; fstream file; file.open("stock.dat",ios::in|ios::out); cout<<"enter details for three items\n"; for(int i=0;i<3;i++) { item[i].readdata(); file.write((char *) & item[i],sizeof(item[i])); } file.seekg(0); cout<<"\noutput\n\n"; for(i=0;i<3;i++) { file.read((char *) & item[i],sizeof(item[i])); item[i].writedata();

} file.close(); getch(); }

Output:
enter details for three items enter name:C++ enter code:101 enter cost:175 enter name:Fortran enter code:102 enter cost:150 enter name:Java enter code:225 enter cost:225

output

C++ Fortran Java

101 102 225

175 150 225

Program: To open a binary file for storing a set of numbers on a file??


#include<iostream.h> #include<conio.h> #include<fstream.h> #include<iomanip.h> const char * filename="BINARY"; void main() { clrscr(); float height[4]={175.5,153.0,167.25,160.70}; ofstream outfile; outfile.open(filename); outfile.write((char *) & height,sizeof(height)); outfile.close(); for(int i=0;i<4;i++) height[i]=0; ifstream infile; infile.open(filename); infile.read((char *) & height,sizeof(height)); for(i=0;i<4;i++) { cout.setf(ios::showpoint); cout<<setw(10)<<setprecision(2) <<height[i];

} infile.close(); getch(); }

Output:
175.50 153.00 167.25 160.70

Program : Converting lowercase to uppercase??


#include<fstream.h> #include<iostream.h> #include<iomanip.h> #include<stdlib.h> #include<ctype.h> #include<conio.h> void main() { clrscr(); ofstream outfile; ifstream infile; char fname1[10],fname2[10]; char ch,uch; cout<<" enter a file name to be copied?\n"; cin>>fname1; cout<<"new file name?\n"; cin>>fname2; infile.open(fname1); if(infile.fail()) { cerr<<" no such file exists\n"; } outfile.open(fname2); if(outfile.fail()) {

cerr<<"unable to create file\n"; exit(1); } while(!infile.eof()) { ch=(char)infile.get(); uch=toupper(ch); outfile.put(uch); }; infile.close(); outfile.close(); }

Output:
input file this is a test program output file THIS IS A TEST PROGRAM

Vous aimerez peut-être aussi