2. Demystifying
A DATA STRUCTURE(RECORD) is a group of data
elements, with the same features, grouped together
under one name.
Like other variable types these are also TYPES.
FIELDS or MEMBERS can have different types and different lengths.
Can be declared using the following syntax ( abstract ) :
struct type_name {
member_type1 member_name1;
member_type2 member_name2;
member_type3 member_name3;
.
.
} object_names;
اصفهان صنعتی دانشگاه–کامپیوتر و برق دانشکده–نیا بهنامی–سروری–آخوندی–پورقدرت
2
6. Arrays of data structures
As other types of variables we can also have arrays of
data structures .
struct product {
int weight;
double price;
};
product p[100];
اصفهان صنعتی دانشگاه–کامپیوتر و برق دانشکده–نیا بهنامی–سروری–آخوندی–پورقدرت
6
7. Data structures as Function Arguments
اصفهان صنعتی دانشگاه–کامپیوتر و برق دانشکده–نیا بهنامی–سروری–آخوندی–پورقدرت
7
void heavy(product arrayOfProduct[])
{
product heavyProducts[100];
for (int i = 0; i < 100; i++)
{
if (arrayOfProduct[i].weight > 10000)
heavyProducts[i].weight = 1;
else
heavyProducts[i].weight = 0;
}
for (int j = 0; j < 100; j++)
{
if (heavyProducts[j].weight == 1)
{
system("color 40");
cout << “The element number" << j + 1 << "is heavy" << endl;
}
}
}
8. The end
اصفهان صنعتی دانشگاه–کامپیوتر و برق دانشکده–نیا بهنامی–سروری–آخوندی–پورقدرت
8
Questions …