محاضرات مقرر البرمجة1 ++C (نظري +عملي)
Transcript of محاضرات مقرر البرمجة1 ++C (نظري +عملي)
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
1/127
1(C++)(
+):.
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
2/127
1(C++)(
+):.
(1)++C 1.
C++.
.Array.2 .3
Function and procedure.
.Structures.4(2).Pointers.5(2).Files.67. Object Oriented Prog(OOP).(3)
(1)++C .1
C++.
(- )
(-
)
. -- cincout.
(ifswitch - ?)(fordowhile):.2
- -
(....(
-. .3
:
-
- .
:.4
.
2:.5 -
.2:.6
-
.
7. Object Oriented Prog(OOP).3 Class-Class.
#includeusing namespace std;
void main(){
}
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
3/127
1(C++)(
+):.
++1C (
+)
:. .
E_mail : [email protected]
20102009
-
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
4/127
1(C++)(
+):.
:.1
(- -)
: :
:
:((:
(-
)
:
: :
::
-: .- :
:cin :.cout
(ifswitch - ?)(fordowhile)
if, if...else, switch, while, do...while or for
if statement (single selection) if...else statement (double selection) switch statement (multiple selection) while statement do...while statement
for statementfor(initialization;loopContinuationCondition; increment)
statement
for(int j = x; j
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
5/127
1(C++)(
+):.
long x,y;x=y=1;
for (int j =x; j
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
6/127
1(C++)(
+):.
{statement
} while ( condition );
initialization;while ( loopContinuationCondition ){
statementincrement;
}
if ( grade >= 60 )cout = 60 )
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
7/127
1(C++)(
+):.
// 60-69 gets "D"cout 5 )cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
8/127
1(C++)(
+):.
if ( studentGrade >= 60 )
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
9/127
1(C++)(
+):.
case 1:cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
10/127
1(C++)(
+):.
>>>>>>>>>>
>
>
int count = 1;
// initialize count
while ( count
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
11/127
1(C++)(
+):.
for ( int k = 1; k
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
12/127
1(C++)(
+):.
{for ( int j = 1; j
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
13/127
1(C++)(
+):.
.
1
for (int x = 1; x
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
14/127
1(C++)(
+):.
int hour,mint,seco,temp,secon;coutsecon;seco=secon%60;temp=secon/60;
mint=temp%60;hour=temp/60;
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
15/127
1(C++)(
+):.
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
16/127
1(C++)(
+):.
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
17/127
1(C++)(
+):.
:. if, if...else, switch, while, do...while or for
if statement (single selection) if...else statement (double selection) switch statement (multiple selection) while statement do...while statement for statement
:.:
Borland
.
#include
using namespace std;void main(){..
..}
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
18/127
1(C++)(
+):.
:
.:
(1 .:
#includeusing namespace std;
void main(){
int i,j,n;
coutn;for(i=1;i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
19/127
1(C++)(
+):.
(2 .:
int i,j,n;
coutn;for(i=n;i>=1;i--)
{
for(j=i;j>=1;j--)
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
20/127
1(C++)(
+):.
(5 .:
int i,j,n;coutn;for(i=n;i>=1;i--){
for(j=i;j
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
21/127
1(C++)(
+):.
// 1)
#include
using namespace std;void main(){int s,d,a,b,m,c,x;// 5= s cin>>s;x=s;for(d=1;d=1;m--){
cout=2;c--){cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
22/127
1(C++)(
+):.
// 2)
#includeusing namespace std;void main(){int i , j , n;coutn; //5= n for( i=1 ; i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
23/127
1(C++)(
+):.
//3)
#include
using namespace std;void main(){int i , j , n;coutn; //5= n for( i= n; i >=1 ;i--)
{for( j =1 ; j
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
24/127
1(C++)(
+):.
:Arrays
(
)
. , (1
. (2. (34) .. (5. (6 (7 (
- ... -).
8),
. . (9
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
25/127
1(C++)(
+):.
Arrays.:
.
double , int , char , float
int c[12]; // int b[100], x[27]; ]; // int array1[ 2 ][ 3 ]; // int b[ 2 ][ 2 ];//
:. 1) 2) (
...-).
: ..
[4 34 56 10 77 51 93 30 5 52 ]
4
34
56
1077
51 93
30 5 56 10 77
51 93 30
5 52 10
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
26/127
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
27/127
1(C++)(
+):.
. :1)
i i
int x[4], y[4];for (int i=0;i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
28/127
1(C++)(
+):.
int array1[5]={100,50,50,100,50};int s=0;for(int a=0;a
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
29/127
1(C++)(
+):.
:. . , (1
int c[12]; . (2
.
. (3int x[ 5]={44,55,66,88,90};
( 4 .x[4]= 90;
5
(++.for(int i=0;i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
30/127
1(C++)(
+):.
.- -: 1) ,
.
(2 (
- ... -).
. (3
: ,
,
Bubble Sort
,(
Quick Sort
).
- ..
- ..!
: !
- ..! , -
,
..
..
.
-
,
. -
.
:
5
2
6
4
3
..
5
..2 :2
5
6
4
3
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
31/127
1(C++)(
+):.
..
2.. 643.
..
5
6
,
4
.. ""4 :2
4
6
5
3
,
4..
3
,
:2
3
6
5
4
, 6..
5(
..,
..( :2
3
5
6
4
5..
4..
:
2
3
4
6
5
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
32/127
1(C++)(
+):.
..
6....
5..!! 5.
2
3
4
5
6
..
.. ..
..!
, ,!!
,
,
!!
:1)
5
int x[5];int temp;for( int count=0; count
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
33/127
1(C++)(
+):.
x[i]=x[j];x[j]=temp;}
for( int i=0; i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
34/127
1(C++)(
+):.
if (i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
35/127
1(C++)(
+):.
}s1=s2=0;for( i=0; i< n; i++)
if(a[i]%2==0)s1+=a[i];elses2+=a[i];cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
36/127
1(C++)(
+):.
14) ( a
b
c
int a[5]={10,20,10,30,40};
int b[5]={40,30,40,20,10};int c[5];for(int i=0; i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
37/127
1(C++)(
+):.
.:
1) N
2) N
3)
N
4)
N
( ( 5)
N
6)
N
7) N
8) N
9)
N
10) N
11) N
12) N
13) N 5
14) N
1015)
N
16)
N
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
38/127
1(C++)(
+):.
17) N( )
18) N(
) Ali 19) N(
)
20) N(
(
21) N(
)
3
22) N( )
23) N( )
24) N( )
25) N(
(
26) N( (
27) N( ) a
(28 N
29) N
X1 X2
30) N
.
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
39/127
1(C++)(
+):.
:
.1 ( - ... -
).
2. ,.
. .3
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
40/127
1(C++)(
+):.
:. . , (1
int b[ 2 ][ 2 ];int array2[ 2 ][ 3 ];
2)
56 10 77 51 93 305 52 10
3
;{ { .int array1[2][3]={{1,2,3},{ 4, 5, 6 (
4) .a[ 0 ][ 0 ] = 0;a[ 0 ][ 1 ] = 0;a[ 2 ][ 1 ] = a[ 2 ][ 3 ] = 0;
. (51
for ( int i = 0; i < 2; i++ ){for ( int j = 0; j < 3; j++ )cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
41/127
1(C++)(
+):.
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
42/127
1(C++)(
+):.
: :1
:
C++VB.NET
778078 607087899088
:
.
:.:.
18
const int arraySize = 3;int table[arraySize ][arraySize];for ( int i = 0; i < arraySize; i++ )
{for ( int j = 0; j < arraySize; j++ ){
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
43/127
1(C++)(
+):.
2)
// ;int a,b,i,j a=4;intx[5][5]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};for(i=0;i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
44/127
1(C++)(
+):.
:. 1)
n
{int maxa[100][100];int i,j,m,n;coutn;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
45/127
1(C++)(
+):.
cin>>sort_up[i][j];cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
46/127
1(C++)(
+):.
4) n
int ziro2up[100][100];
int i,j,m,n;coutn;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
47/127
1(C++)(
+):.
5) n
for(i=0;i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
48/127
1(C++)(
+):.
7) n
for(i=0;i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
49/127
1(C++)(
+):.
9) n
int search[100][100];
int i,j,m,n;coutn;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
50/127
1(C++)(
+):.
10) N
for(i=0;i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
51/127
1(C++)(
+):.
cin>>n;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
52/127
1(C++)(
+):.
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
53/127
1(C++)(
+):.
17)
for ( i = 1; i= 1; j-- ){
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
54/127
1(C++)(
+):.
}cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
55/127
1(C++)(
+):.
{for ( j = 1; j
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
56/127
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
57/127
1(C++)(
+):.
1)
int a[5]={1,2,3,4,5};int i;
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
58/127
1(C++)(
+):.
4)
int a[5]={1,2,3,4,5};
int i;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
59/127
1(C++)(
+):.
(6 ( ).:
int array1[100][100];
int i,j,n;coutn;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
60/127
1(C++)(
+):.
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
61/127
1(C++)(
+):.
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
62/127
1(C++)(
+):.
if (i>=j)array1[ i ][ j ]=i;
else
array1[ i ][ j ]=0;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
63/127
1(C++)(
+):.
(13 ().:
int array1[100][100];
int i,j,n;coutn;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
64/127
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
65/127
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
66/127
1(C++)(
+):.
void oddeven(int x){if(x%2==0)
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
67/127
1(C++)(
+):.
..6void max(){
if(x1>y1)cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
68/127
1(C++)(
+):.
}}
void main(){cin>>s;readar(x,s);
parry(x,s); }
8. max
void max(int a[],int n){int m;
m=a[0];for(i=1; i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
69/127
1(C++)(
+):.
(12
(
(
#includeusing namespace std;int i,s;int x[100];//======
void parry(int a[],int n){cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
70/127
1(C++)(
+):.
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
71/127
1(C++)(
+):.
max(x,s);break;
}
default:{cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
72/127
1(C++)(
+):.
1:
-
.: .1
2.
3.
.4
2:
:
#includeusing namespace std;
void main(){
int array1[100][100];
int i,j,n;coutn; N=5 cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
73/127
1(C++)(
+):.
}cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
74/127
1(C++)(
+):.
else if (i+j==n+1)array1[ i ][ j ]=j;
else
array1[ i ][ j ]=0;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
75/127
1(C++)(
+):.
{if (i==j)
array1[ i ][ j ]=i;
else if (i+j==n+1)array1[ i ][ j ]=j;else
array1[ i ][ j ]=0;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
76/127
1(C++)(
+):.
function.:
1) fact
#includeusing namespace std;//---------------int fact(int n){
int i,f;
if (!(n>1))return 1;return(n*fact(n-1) );
}//---------------
void main(){ int n,f;coutn;f=fact(n);cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
77/127
1(C++)(
+):.
2) fact
#include
using namespace std;//---------------int fact(int n){
int i,f;if (n>1)f=n*fact(n-1);
elsef=1;return(f);}//---------------
void main(){ int n,f;coutn;f=fact(n);cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
78/127
1(C++)(
+):.
3) fact
#includeusing namespace std;//---------------int fact(int n){
int i,f;f=(n>1)?n*fact(n-1):1;return(f);
}//---------------
void main(){ int n,f;coutn;f=fact(n);
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
79/127
1(C++)(
+):.
4) powerfxn
#include
using namespace std;//---------------int powerf(int x,int n)//{int p;if(n==0)return(1);
p=x*powerf(x,n-1);
return(p);}//---------------
void main(){ int x,n,p;coutx>>n;
p=powerf(x,n);cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
80/127
1(C++)(
+):.
5) sum1N
#includeusing namespace std;
//---------------int sum(int n)//{int s;if(n==1)return(1);elsereturn(n+sum(n-1));
}//--------------- void main(){ int n,s;coutn;s=sum(n);cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
81/127
1(C++)(
+):.
6) .#includeusing namespace std;
//-------------------------void v1(int n){for( int i = 1 ; i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
82/127
1(C++)(
+):.
void v4(int n){
for(int i=n;i>=1;i--)
{ for(int j=i;j
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
83/127
1(C++)(
+):.
}//-------------------------
void main()
{int m;coutm;
v1(m);cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
84/127
1(C++)(
+):.
void main(){
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
85/127
1(C++)(
+):.
{cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
86/127
1(C++)(
+):.
cin>>c1;switch(c1){
case '1':{couts;readar2(x,s);break;
}case '2':
{if (s==0){cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
87/127
1(C++)(
+):.
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
88/127
1(C++)(
+):.
1)
#includeusing namespace std;void main(){int n;coutn;for( int i= n; i >= 1 ;i--)
{for( int j=1 ; j
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
89/127
1(C++)(
+):.
int a[5]={5,4,3,2,1};int i;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
90/127
1(C++)(
+):.
: (1
(
1- 2-
3- -4
2
(
3) Result
( ).
4) min
5) sum 1100.
-
.:
N=5
1 0 0 0 5
0 2 0 4 0
0 0 3 0 0
0 2 0 4 0
1 0 0 0 5
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
91/127
1(C++)(
+):.
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
92/127
1(C++)(
+):.
)struct 2)
1), .
struct student{
char name[10];int deg;
};
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
93/127
1(C++)(
+):.
. (2couts[i].name
4) .
#includeusing namespace std;//==============struct student{
char name[10];int deg;
};//=============int i, j , n;//==============void main(){//==============student s[10],t;//=============coutn;//=============for( i= 0; i >s[i].name;
cin>>s[i].deg;}
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
94/127
1(C++)(
+):.
//==============for ( i=0 ;i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
95/127
1(C++)(
+):.
{char name[10];date datee;
}st;void main(){
cin>>st.name;cin>>st.datee.day>>st.datee.month>>st.d
atee.yaer;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
96/127
1(C++)(
+):.
cin>>st[i].datee.day>>st[i].datee.month>>st[i].datee.yaer;
}
=================//for(i=0;i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
97/127
1(C++)(
+):.
. (,) (1
(,) (2
%.15
),,) (3
.
) , ,) (4
.
. ),,) (5
. (,) (6
(,) (7
%.15
),,) (8
.
( , ,) (9
.
),,) (10
.
)pointer 2)
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
98/127
1(C++)(
+):.
++pointerC
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
99/127
1(C++)(
+):.
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
100/127
1(C++)(
+):.
#includeusing namespace std;
void main(){int x;cout > x;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
101/127
1(C++)(
+):.
// }
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
102/127
1(C++)(
+):.
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
103/127
1(C++)(
+):.
#includeusing namespace std;int main()
{int x = 1, y = 5;cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
104/127
1(C++)(
+):.
}
#includeusing namespace std;
void main (){int *varPtr;
int var = 20 ;varPtr = &var;
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
105/127
1(C++)(
+):.
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
106/127
1(C++)(
+):.
}
#includeusing namespace std;int main(){int value1 = 5,
value2 =15;int* p1;int* p2;
p1 = &value1;p2 = &value2;*p1 =10;*p2 = *p1;
p1 = p2;*p1 =20;
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
107/127
1(C++)(
+):.
return 0;}
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
108/127
1(C++)(
+):.
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
109/127
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
110/127
1(C++)(
+):.
void main ( ){FILE *f;
f=fopen("c:\\stdudent1.txt","w");fprintf(f," welcome to C++");fclose(f);}
#include
using namespace std;void main ( ){FILE *f;int score;f=fopen("c:\\stdudent1.txt","w");coutscore;
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
111/127
1(C++)(
+):.
while(score !=0){fprintf(f,"%d\n",score);
cout score;}fclose(f);}
stdudent1
.
#includeusing namespace std;
void main ( ){FILE *myfile;// struct employee//{int empno;// char name[10];// ;[ 20float salary;//
};employee emp[100];// ;[ 100int i,n;
myfile=fopen("c:\\stdudent1.txt","w");coutn;for(i=0;i
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
112/127
1(C++)(
+):.
{cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
113/127
1(C++)(
+):.
int i,n;myfile=fopen("stdudent1.txt","w");if(myfile==NULL)
{cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
114/127
1(C++)(
+):.
( OBJECT ORIENTED PRORAMMING++
(:(Class & Object
:
class
++(C++)
(C),
Data
(Functions) , (object)
.
++(C++) (structures)
(classes), (Functions)
++(C++)
(C),
,
++((C++))
( C,)
.
((Declaration of Class
,
(Member Scope)
:
class class_name
{
private:
DataMembers declaration;FunctionMembers declaration;
public:
DataMembers declaration;
FunctionMembers declaration;};
(Compiler) (class)
,
.
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
115/127
1(C++)(
+):.
(class members):
, (Data) (Functions,)
(method),
(Data Members)
(Member functions.)
(private)(public)
(Encapsulation) (data
hiding),
,( ) (private)
((public ,
, (scope) , (Main)
,
(private)
.
:
class rectangle
{ private:
int len,br;public:
void getdata();
void setdata(int I,int b);
void displaydata( );
void area_peri( );
};
(RECTANGLE),
(br)(len),
, ,
.
/
(class body),
,((public ()
(private),
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
116/127
1(C++)(
+):.
,
.
, , /
.
/ (class instance:) (float)
,
y
:
Float y;
y float
( ),
(instance)
,
(rectangle), ) )
:rectangle r1,r2;
(r1r2)
(rectangle),
,
(rectangle),
c++,
.
,
2 (
, sizeof()),
object , r1
,
r2
.
class
,
(instance object)
.
(Accessing class members:)
private,
,()main
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
117/127
1(C++)(
+):.
,
( )
.
dot
(object.function()) r1:r1.setdata(10,20); r2.setdata(4,5);
brlen
r1 r2
:
:( )
,
,
:
Class rectangle{
private:
int len,br;
public:
void getdata()
{
coutbr;
}
void setdata(int I,int b)
{
len=I;
br=b;
}
void displaydata()
r1 r2
Len br Len br
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
118/127
1(C++)(
+):.
{
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
119/127
1(C++)(
+):.
:
,
1 .
:.1
class
declaration,
.
2.
(inline),
inline, , inline
:
Inline Return-type calss_name::function_name(argument
lis) {}
inline
.3
,
(headfile(*.h)) () (*.cpp)
libraries
.
.4(local class)
(mian function),
.
:
functions,
, ,
, (return)
.
, ,
scope of the member)).,
..
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
120/127
1(C++)(
+):.
:
,
(by reference), (by value)
(string.h)
,(
):
#include
#include
Class str
{
private:
char s[50];
public:
void set (char *ss)
{
strcpy(s,ss);
}
void print(){
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
121/127
1(C++)(
+):.
}
str (
,(array of characters set()
) ) , print()
, concat()
(
)
(
).
main()
s1 set()
,
s2 s1
,
s1 .
(hand in hand.)
.. s2s1
:
s2.concat(s1);
s2.print(); s2 :
main(), void concat (str s2),
, ( )
str,
,
s2 str.
:
,
,((integers or floats
:
class sample{
private:
int i;
public:
void set(int ii)
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
122/127
1(C++)(
+):.
{
i=ii;
}
void print(){
cout
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
123/127
1(C++)(
+):.
:
C++ C++ How to Program, Fifth Edition C++ C++ Introduction To Object Oriented Programming &
C++
Yashavant Kanetkar BPB
PUBLICATION
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
124/127
1(C++)(
+):.
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
125/127
1(C++)(
+):.
2008
C++
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
126/127
1(C++)(
+):.
-
8/9/2019 http://www.softxgame.com ( +) C++ 1
127/127
1(C++)(
+):.