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

การบ้าน Structure

Structure


นี่เป็นตัวอย่างการเขียน Structure ของร้านให้เช่า DVD แห่งหนึ่ง

ซึ้งก่อนเช่านั้นก็จำเป็นต้อง ระบุ วัน เดือน ปี ปัจจุบัน รหัส สมาชิก

ชื่อ นามสกุล สมาชิก ชื่อหนัง วันที่ยืม และ วันที่คืน หนัง



#include"stdio.h"
struct data
{
int day;
int month;
int year;
};
struct member
{
int id;
char name[40];
char last[40];
char movie[100];
char tel[12];
char mail[100];
int rent;
int returnError;
struct data dvd;
}sm;
void input_data()
{
printf(".:'*':. Wellcome to NooM DVD SHOP.:'*':. \n:");
printf("date data:");
scanf("%d-%d-%d",&sm.dvd.day,&sm.dvd.month,&sm.dvd.year);
printf("\n.:'*':. Data member.:'*':. \n");
printf("\nID member : ");
scanf("%d",&sm.id);
printf("name of customer:");
scanf("%s",&sm.name);
printf("lastname of customer:");
scanf("%s",&sm.last);
printf("Telephone Number of customer:");
scanf("%s",&sm.tel);
printf("E-Mail of customer:");
scanf("%s",&sm.mail);
printf("\nname movie:");
scanf("%s",&sm.movie);
printf("day of rent:");
scanf("%d",&sm.rent);
}
void show_data()
{
printf("\n.:'*':. Data of member.:'*':. \n");
printf("\nDisplay Date : %d-%d-%d\n",sm.dvd.day,sm.dvd.month,sm.dvd.year);
printf("ID of Member :%d\n",sm.id);
printf("Name and Lastname of Member:%s %s\n",sm.name,sm.last);
printf("Telephone Number of Customer :%s\n",sm.tel);
printf("E-mail of Customer :%s\n",sm.mail);
printf("\nRent Data\n");
printf("\nName movie :%s\n",sm.movie);
printf("Day of rent :%d-%d-%d\n",sm.rent,sm.dvd.month,sm.dvd.year);
printf("Day of return %d-%d-%d\n",sm.rent+3,sm.dvd.month,sm.dvd.year);
}
main()
{
input_data();
show_data();
return 0;
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น