You are on page 1of 16

:Arrays

:

.
.
.
) (Arrays .
:
.1
.2
.3
.4
.5

.
.
.
.
.

: :
" :
".

) (char ) (int ) (float
) (float, int, char
.

.
) (
.c++
.c++

:
:
One Dimensional Arrays

. .


.
Multidimensional Arrays
.

.
.

5 6.

: :


.
.



20

30

25

1
1
1

1
a
b
mem

1
1

;]int a[20
;]char b[30
;]float mem[25

20
30
2
10
200
10 3
10
10
2
10
20

;]int d[20][30

stack

char
;]stack[10][200
char
;]x[10][10][10

double
;]y[10][20


:
;}int a[]={1,2,3,4,5,6
a
12345. 6
;}}float b[][]={{1,2,3},{4,5,6},{7,8,9
B 3 .
1 :2 .3 45. 6
78.9
;}char c[]={a,n,o

: :

.

for
while do while for
.
) (
.
:


.
.

.
.

:
.
: 1
.
:
#include<iostream.h>
void main(void)
{
int degrees[25],i,n;
float sum,average;
cout<<Enter number of students n please /n;
cin>>n;
sum=0;
for(i=0;i<n;i++)
{
cout<<Enter the degree of student no. <<i<<please \n;
cin<<degrees[i];
sum=sum+degrees[i];
}
average=sum/n;
cout << The average of degrees is <<average<<\n;
}

. %20 :2
:
#include<iostream.h>
void main(void)
{
int salary[100],i,n;
float average;
cout<<Enter number of employees n please /n;
cin>>n;
for(i=0;i<n;i++)
{
cout<<Enter the salary of employee no. <<i<<please \n;
cin<<salary[i];
salary[i]= salary[i]*(1.2);
cout<<Salary after increasing= <<salary[i]<<\n;
}
}

:3

:

:
include<iostream.h>
void main(void)
{
int a[10][10],b[10][10],c[10][10],i,j,m,n;
cout<<Enter number of rows and columns please m and nplease /n;
cin>>m>>n;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<Enter the the elements of matrices a and b for row #<<i<<and col. #<<j<<
please\n;
cin>>a[i][j]<<b[i][j];
cout<<The sum of the matrix is given by= <<c[i][j]<<\n;
}
}

:3
welcome name name
:
# include<iostream.h>
#include<string.h>
void main(void)
{
char namr[80]

; cout<<place enter your name :


;)gets(name
;cout<<welcome << name
}
:
-1 name gets

'name[0] = 'a ss;]= name[15
-2
) ( null
**
># include <iostream.h
)void main(void
{
;char strin[ ] = hello
;cout<<the character array is<< strin <<\n
}
* :
string hello char string[ ] = "hello printf sizeof The character array is hello
6 5 hello :
:

)(
:


.
.


dbase MS-Access FoxPro
records
fields . C
struct
.Record

.
) (structures .
:
.1
.2
.3
.4

.
.
.
.

: :
) (
.

:
:
-1
.
-2
.
-3 typedef
.
struct
.
struct

.
.
:
struct structure_name
{
;type1 field1
;type2 field2
.
.
.
;typen fieldn
;}
structure_name .
var1,var2,,varn structure_name :
;struct structure_name var1,var2,,varn
:
struct S
{
;int a
;float b
;char c
float d
;]char name[20
;}
S 5 :
a b c d name string 20. )( S :
;struct S x,y,z
x,y,z .
.S
struct

.
.
. :
struct structure_name

{
;type1 field1
;type2 field2
.
.
.
;typen fieldn
;} var1,var2,,varn
structure_name .
var1,var2,,varn .
:
struct S
{
;int a
;float b
;char c
float d
;]char name[20
;} x,y,z
S 5 :
a b c d name string 20. x,y,z .S
typedef
struct
.
. .
:
typedef struct
{
;type1 field1
;type2 field2
.
.
.
;typen fieldn
;} structure_name
structure_name .
var1,var2,,varn .

;structure_name var1,var2,,varn
:

typedef struct
{
;int a
;float b
;char c
float d
;]char name[20
;} S

S 5 :
a b c d name string 20. x,y,z S
;S x,y,z

:
.
". :
;cin>>x.b
b x .S
;cout <<y.d
d y S .
;z.d=x.b+y.d
d z b S
d y . S

.

)( -
.
. employee
.
- employee

struct employee
{
char name[40];
char address[40];
int age;
float salary;
}
struct dept
{
int deno;
int product;
sturct employee emp;
}

:- -

dept emp struct dept dept1; dept : dept1.emp.age = 25 dept1


emp
age

:
#include <stdio.h>
#include <conio.h>
#include<iostream.h>
void main ()
{
struct data
{
int num;
char stat;
};
struct data stud;
stud.num = 5;
stud. stat='t';
cout<<"\n stud.num =<< stud.num<< stud.stat="<< stud. stat;
getch();
}

strud.num =5, stud.stat=t


:
#include<iostream.h>
#include<stdio.h> // gets()
#include<stdlib.h>
// atoi()
struct employee
{
char name[40];
char address[40];
int age;
float salary;
};
struct department
{
int depnum;
char product[40];
struct employee emp;
};
void main(void)
{
struct deparment dept;
char temp[10];
cout<<enter dept no : ;
gets(temp);
dept.deptnum = atoi(temp);
cout<<enter dep. Product : ;
gets(dept.product);
cout<<enter employee name : ;
gets(dept.emp.name);
cout<<enter employee address ;
gets(dept.emp.address);
cout<<enter employee age : ;
gets(temp);
dept.emp.age = atoi(temp);
cout<<enter employee salary : ;
gets(temp);
dept.emp.salary = atof(temp)
cout<<\n\n you entered \n\n ;
cout<<dept no : \t\t <<dept.deptnum<<\n;
cout<<dept product : \t\t <<dept.product<<\n;
cout<<employee address : \t\t<< dept.emp.address<<\n;

;cout<<employee age : \t\t<<dept.emp.age<<\n


;cout<<employee salary: \t\<<dept.emp.salary<<\n
}

:-
employee department employee gets name emp :
;)gets(dept.emp.name
printf .
:


:
>#include<iostream.h
>#include <stdio.h
>#include <conio.h
)( void main
{
struct data
{
;int no
;]char name[10
;}

struct data stud1, stud2;


cout<<stud1.no = ";
cin>> stud1.no;
cout<<stud1.name = ";
cin>> stud1.name;
stud2 = stud1;
cout<< stud1.no =\t<< stud1. no<< stud1.name "<< stud1.name <\n;
cout<< stud2.no =\t<< stud2. no<< stud2.name "<< stud2.name <\n;
getch();
}

stud1.no= 5
stud2.no= 5

stud1.name= tamer
stud2.name= tamer
: Structures Nested



.
#include <stdio.h>
#include <conio.h>
#include<iostream.h>
void main()
{
struct person{
int no;
char name[10];
};
struct group{
struct person P1;

struct person P2;


int code;

};
struct group G1;
cout<<"\n\n G1.P1.no= ";
cin>>G1.P1.no;
cout<<\n G1.P1.name= ";
cin>>G1.P1.name;
cout"\n G1.code = ";
cin>>G1.code;
G1.P2=G1.P1;
cout<<"\n\n The data of Groups :\n\t";
cout<<\n\t G1.P1.no=<<G1.P1.no;
cout<<"\n\t G1.P1.name="<<G1.P1.name;
cout<<"\n\t G1.code="<<G1.code;
cout<<"\n\t G1.P2.no "<<G1.P2.no;
cout<<"\n\t G1.P2.name=<<G1.P2.name;

G1.P1.no= 10
G1.P1.name= Samer
G1.code =199
The data of Groups :
G1.P1.no=10
G1.P1.name= Samer
G1.code=199
G1.P2.no=10
G1.P2.name= Samer

You might also like