30 มิถุนายน, 2552

DTS 02-24/06/2552

สรุป
วันนี้รู้จักกับ Array และ Structure
Array เป็นโครงสร้างข้อมูลที่เรียกว่า Linear list การกำหนด subscript แต่ละตัวจะประกอบไปด้วย ค่าสูงสุดและค่าต่ำสุดของ subscript นั้น
ค่าต่ำสุด เรียกว่า ขอบเขตล่าง
ค่าสูงสุด เรียกว่า ขอบเขตบน
Structure หรือโครงสร้าง คือกลุ่มของข้อมูลที่มีชนิดเหมือนกันหรือต่างกันก็ได้ ซึ่งนำมารวมกลุ่มแล้วเรียกเป็นชื่อเดียวกัน
Structure มีประโยชน์มากในการสร้างและจัดการโครงสร้างข้อมูลที่ซับซ้อน
Structure แตกต่างกับ Array คือ สมาชิกของ Structure เป็นข้อมูลคนละชนิดกันได้ ส่วนสมาชิกของ Array จะต้องเป็น้อมูลชนิดเดียวกัน
รูปแบบของ Structure
struct struc_name
{
type 1 name 1;
type 2 name 2;

type N name N;
} struc_variable;


ทำ Structure

#include
struct product
{
char shop[20];
char name[20];
int amount;
int price;
char div[20];
int net;
char off[20];
}pro;
struct customer
{
char names[20];
}you;
struct date
{
int day;
int month;
int year;
}now;
void main()
{
printf("Welcom in Shop");
printf("\n\nShop:");
scanf("%s",&pro.shop);
printf("Product name:");
scanf("%s",&pro.name);
printf("Amount:");
scanf("%d",&pro.amount);
printf("Price:");
scanf("%d",&pro.price);
printf("Division:");
scanf("%s",&pro.div);
printf("Officer:");
scanf("%s",&pro.off);
printf("\nCustomer name is:");
scanf("%s",&you.names);
printf("Date dd/mm/yy:");
scanf("%d/%d/%d",&now.day,&now.month,&now.year);
{
printf("\n\n\nReport of customer");
printf("\n\nShop:%s \nProduct:%s\n",pro.shop,pro.name);
printf("Amount:%d\t Price:%d\n",pro.amount,pro.price);
printf("Nettotal:%d\n",pro.amount*pro.price);
printf("Customer Name:%s\n",you.names);
printf("Date:%d/%d/%d",now.day,now.month,now.year);
}
}

DTS 01-17/06/2552

สรุป
แนะนำเนื้อหาในรายวิชา และทบทวนเรื่องการใช้โปรแกรมภาษาซี
รวมถึงเรื่องโครงสร้างของข้อมูลด้วย

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



ชื่อ  :               

Name :

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

ปัจจุบันศึกษาอยู่ที่ :



E-mail :


โทร. :