วันอังคารที่ 30 มิถุนายน พ.ศ. 2552

#include
#include
int main(void)
{
struct car{
char brand[30];
char Engine[30];
char CylinderCapacity[30];
int MaxPower;
int MaxTorque;
float PowerRatio;
char Transmission[30];
char color[30];
char GearBox[30];
int Length;
int Width;
int weight;
int Height;
float controlMotronic;
int price;
}product;
strcpy(product.brand,"FERRARI SPIDER");
strcpy(product.Engine,"V8 DrySump");
strcpy(product.CylinderCapacity,"3586 cc ");
product.MaxPower = 400;
product.MaxTorque = 38;
product.PowerRatio = 3.6;
strcpy(product.Transmission,"MR");
strcpy(product.color,"Black");
strcpy(product.GearBox,"6 Speed");
product.Length = 4477;
product.Width = 1922;
product.weight = 1350;
product.Height = 1235;
product.controlMotronic = 7.3 ;
product.price = 24000000;

printf("\n Brand;%s\n Engine;%s\n CylinderCapacity;%s\n MaxPower;%d\n MaxTorque;%d\n PowerRatio;%.1f\n Transmission;%s\n Color;%s\n earBox;%s\n Length;%d\n Width;%d\n weight;%d\n Height;%d\n ControlMotronic;%.1f\n price;%d\n",
product.brand,product.Engine,product.CylinderCapacity,product.MaxPower,product.MaxTorque,product.PowerRatio,product.
Transmission,product.color,product.GearBox,product.Length,product.Width,product.weight,product.Height,product.controlMotronic,product.price,product);
}

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

#include
#include
void main()
{
struct resume {
char name[50];
char surname[50];
char nickname[20];
char id[30];
int age;
char birthday[50];
char gender[10];
float gpa;
char tel[50];
int day;
char month[20];
int year;
};
struct resume student;
strcpy(student.name,"ITTHA");
strcpy(student.surname,"THONGJARM");
strcpy(student.nickname,"BEST");
strcpy(student.id,"50132792058");
student.age=20;
strcpy(student.birthday,"24 August 1988");
strcpy(student.gender,"male");
student.gpa=2.33;
strcpy(student.tel,"0839978802");
student.day=30;
strcpy(student.month,"June");
student.year=2009;
printf(" Name:%s\n",student.name);
printf(" Surname:%s\n",student.surname);
printf(" Nickname:%s\n",student.nickname);
printf(" Id:%s\n",student.id);
printf(" Age:%d\n",student.age);
printf(" Birthday:%s\n",student.birthday);
printf(" Gender:%s\n",student.gender);
printf(" Gpa:%.2f\n",student.gpa);
printf(" Tel:%s\n",student.tel);
printf(" Today date is:%d%s%d\n",student.day,student.month,student.year);

}

สรุปเนื้อหาหลังเรียน

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

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

ในการคำนวณหาสมาชิกของอาร์เรย์ 1 มิติทำได้ดังนี้
จำนวนสมาชิกของอาร์เรย์ = (u-l)+1u คือค่าสูงสุด
หรือ Upper boundl คือค่าต่ำสุด หรือ Lower bound

ส่วน 2 มิติสามารถหาได้ดังนี้

จำนวนสมาชิก = M x N

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

type array-name[n];type คือ ชนิดของตัวแปรอาร์เรย์ที่จะสร้างขึ้น เช่น int,float,char เป็นต้นarray-name คือ ชื่อของตัวแปรอาร์เรย์ที่ต้องตั้งให้สื่อและเข้ากับชนิดของตัวแปรและจะต้องไม่ไปตรงกับคำสงวนของภาษาซีด้วยn คือขนาดของตัวแปรอาร์เรย์ที่จะสร้างขึ้น

การกำหนดข้อมูลให้กับตัวแปรอาร์เรย์เราสามารถกำหนดไปพร้อมกับการประสร้างตัวแปรได้เลย

value-1,value-2 คือข้อมูลที่กำหนดให้ตัวแปรและต้องเป็นชนิดเดียวกับตัวแปรนั้น ๆ ด้วย เช่น

int number[3] = {23,-123,43};
char name[5] = "BENZ";

อาร์เรย์ 2 มิติมีลักษณะการกำหนดตำแหน่งแบบแถวและคอลัมน์

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

type array-name[n][m];type คือ ชนิดของตัวแปรอาร์เรย์ที่จะสร้างขึ้น เช่น int,float,char เป็นต้นarray-name คือ ชื่อของตัวแปรอาร์เรย์ที่ต้องตั้งให้สื่อและเข้ากับชนิดของตัวแปรและจะต้องไม่ไปตรงกับคำสงวนของภาษาซีด้วยn คือ จำนวนแถวของตัวแปรอาร์เรย์m คือ จำนวนคอลัมน์ของตัวแปรอาร์เรย์

Structure โครงสร้างข้อมูลหมายถึง การที่นำข้อมูลที่มีความเกี่ยวข้องกัน เช่น ข้อมูลของนักศึกษาที่อาจประกอบด้วยชื่อ,นามสกุล,อายุ,เพศ,ชั้นเรียน มารวมกันและจัดทำเป็นโครงสร้างข้อมูล ดังภาพ

แต่ในการเรียนใช้งานจริง ๆ เราจะต้องสร้างตัวแปรชนิดโครงสร้างขึ้นมาใช้งานจริง ๆไม่สามารถใช้โครงสร้าง student ได้การประกาศตัวแปรชนิดโครงสร้าง

struct คือ คำที่ใช้กำหนดโครงสร้างข้อมูล(ต้องมีเสมอ)

name คือ ชื่อของโครงสร้างข้อมูลที่จะสร้างขึ้น

type var-1,type var-2 คือชื่อตัวแปรในกลุ่มโครงสร้างข้อมูล

struct-variable คือชื่อของตัวแปรชนิดโครงสร้างที่ต้องการสร้างขึ้นจะมีลักษณะโครงสร้างภายในเหมือนกับโครงสร้างข้อมูลที่กำหนด

*** เราสามารถประกาศ Structure หนึ่งเป็นสมาชิกของอีก Structure ก็ได้แต่ต้องประกาศตัวที่จะนำไปใส่ไปไว้อีก Structure ก่อน

** กรณีเป็นข้อความต้องใช้เรียกฟังชั่น strcpy

เขียนและบันทึกโดย ITTHA THONGJARM

แนะนำตัวเอง

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


ประวัติ

ชื่อ นาย อิษฏ์ฐะ ทองเจิม รหัส 50132792058 ชื่อเล่น เบสท์
Name Mr. ITTHA THONGJARM
หลักสูตร การบริหารธุรกิจ(คอมพิวเตอร์ธุรกิจ) คณะ วิทยาการจัดการ
มหาวิทยาลัยราชภัฎสวนดุสิต
Tel. 083-9978802
E-mail u50132792058@gmail.com