หน้าเว็บ

วันจันทร์ที่ 29 มิถุนายน พ.ศ. 2552

DTS 02-24-06-2552


Array and Record



Array หมายถึงเนื้อที่หน่วยความจำที่เรียงต่อกันใช้เก็บข้อมูลชนิดเดียวกัน เนื้อที่หน่วยความจำนี้มีชื่อเดียวกันแต่แยกตำแหน่งหรือระบุตำแหน่งของข้อมูลแต่ละตัวด้วยการใช้ดรรชนีกำกับ (Index) หรือ Subscript ซึ่งเราสามารถทราบขนาดและมิติ (Dimension) ของ Array เหล่านั้นได้ด้วยการสังเกตที่ดรรชนีกำกับ (Index) หรือ Subscript จะพิจารณาตามประเภทของอะเรย์ในมิติต่างๆ ดังนี้

- อาร์เรย์ 1 มิติ
- อาร์เรย์ 2 มิติ


อาร์เรย์ 1 มิติ คือตัวแปรอาร์เรย์ที่ใช้เก็บข้อมูลเป็นกลุ่ม มีลักษณะตำแหน่งที่ตั้งเป็นลักษณะแถวเดียว(วางตามแนวนอน) หรือคอลัมน์เดียว(วางตามแนวตั้ง)


รูปแบบการประกาศตัวแปรอาร์เรย์มิติเดียว

Data – type array-name [expression]




อาร์เรย์ 2 มิติ คือใช้เก็บข้อมูลเป็นกลุ่ม ที่ข้อมูลนั้นใช้ตัวแปรชื่อเดียวกันแต่ต่างกันที่ตัวห้อย(subscript) ซึ่งจะบอกลำดับความแตกต่างของตัวแปรว่าอยู่ในแถวใด ในคอลัมน์ที่เท่าไร ลำดับใดในแถว


รูปแบบการประกาศตัวแปรอาร์เรย์สองมิติ

Data – type array – name [row size] [column size]




เช่น int a[3][3];

a[0][0] a[1][0] a[2][0]
a[0][1] a[1][1] a[2][1]
a[0][2] a[1][2] a[2][2]


Structure
สตรักเจอร์ (structure) หรือข้อมูลแบบโครงสร้าง เป็นกลุ่มของข้อมูลชนิดเดียวกันหรือหลายชนิด ที่อยู่ภาคใต้ชื่อเพียงชื่อเดียว ข้อมูลแต่ละรายการของกลุ่มเรียกว่า สมาชิกของสตรักเจอร์ (member of the structure) ลักษณะของสตรักเจอร์จะมีลักษณะเหมือนกับการจัดข้อมูลแบบ record ในภาษาปาสคาล สตรักเจอร์มีลักษณะแตกต่างจากอาร์เรย์คือ สมาชิกของสตรักเจอร์เป็นข้อมูลคนละชนิดกันได้ ส่วนสมาชิกของอาร์เรย์จะต้องเป็นข้อมูลชนิดเดียวกัน

ตัวอย่างการกำหนดข้อมูลสตรักเจอร์

struct employee
{
char name[20];
int age;
float salary;
}employ ;

----------------------------------------------------------------------------------
การบ้าน


#include
struct place
{
char name_of_place[50];
char phone_number[15];
char e_mail[30];
int day;
int month;
int year;
};
struct address
{
char city[20];
char country[20];
struct place place1;
} address1;
void input_data()
{
printf("place data\n");
printf("name_of_place=");
scanf("%s",& address1.place1.name_of_place);
printf("phone_number=");
scanf("%s",&address1.place1.phone_number);
printf("e-mail=");
scanf("%s",&address1.place1.e_mail);
printf("day=");
scanf("%d",&address1.place1.day);
printf("month=");
scanf("%d",&address1.place1.month);
printf("year=");
scanf("%d",&address1.place1.year);
printf("city=");
scanf("%s",&address1.city);
printf("country=");
scanf("%s",&address1.country);
}
void show_data()
{
printf("Display Data of place\n");
printf("name_of_place=%s\n",address1.place1.name_of_place);
printf("phone_number= %s\n",address1.place1.phone_number);
printf("e_mail=%s\n",address1.place1.e_mail);
printf("day=%d\n",address1.place1.day);
printf("month=%d\n",address1.place1.month);
printf("year=%d\n",address1.place1.year);
printf("city=%s\n",address1.city);
printf("country=%s\n",address1.country);
}
main()
{
input_data();
show_data();
}

VDO แนะนำตัว

วันเสาร์ที่ 27 มิถุนายน พ.ศ. 2552

ประวัติส่วนตัว




ชื่อ : นางสาว ศิริพรรณ พุ่มพะเนิน

MISS SIRIPUN PUMPANERN


ชื่อเล่น :นิ้ง

รหัสนักศึกษา : 50152792007

หลักสูตร : การบริหารธุรกิจ (คอมพิวเตอร์ธุรกิจ) คณะ วิทยาการจัดการ

มหาวิทยาลัยราชภัฎสวนดุสิต

e-mail address : nu_ninknong@hotmail.com