You are not allowed to perform this action
c:homework:hw15
國立屏東大學 資訊工程學系 程式設計(二)
作業15
動態結構體陣列
turnin code c.hw15
due date: April 15, 23:59
目的
練習使用動態結構體陣列
第1題
本次作業延續自作業14。設計一個程式用以管理多個聯絡人資訊。每個聯絡人包含以下資訊:
- name
- gender
- birthday
- phonetype
- phone
- address
同作業14,下列標頭檔已定義了相關的結構體、列舉資料型別與union:
#include <stdio.h>
#include <string.h>
#define numContact 10
typedef enum {Male, Female} Gender;
typedef enum {Januray, February, March, April, May, June, July,
August, September, October, November, December} Month;
typedef struct
{
Month month;
short day;
int year;
} Date;
typedef struct
{
char firstname[20];
char lastname[10];
} Name;
typedef enum {CHT, TWN, FET} Carrier;
typedef struct
{
char number[10];
Carrier carrier;
} Mobile;
typedef struct
{
char areacode[4];
char number[8];
} Landline;
typedef enum {LandLine, MobilePhone} PhoneType;
typedef struct
{
Name name;
Gender gender;
Date birthday;
PhoneType phonetype;
union
{
Landline landline;
Mobile mobile;
} phone;
char address[50];
} Contact;
Contact getAContact();
void showAContact(Contact c);
void sortContacts(Contact cs[]);
上述的「getAContact()」、「showAContact()」與「sortContacts()」函式,已在作業14中完成實作。
本次作業請修改上述函式之實作,並提供「main.c」程式,其中必須包含「main()」函式,以取多不定數目的聯絡人資料的讀取,最後並將資料排序後輸出。
注意,「numContact」定義了聯絡人的個數(#define numContact 10)。由於與本題要求不同,你可以忽視此常數,但不可以變動contact.h檔案內容。
- 程式執行結果參考:
[9:19 user@ws hw15] ./a.out
Name: Amy Wang <---- 一律為firstname lastname
Gender (M/F): F
Birthday (YYYY/MM/DD): 1977/3/5 <---- 假設使用者不會輸入錯誤的日期
Phone Type (L/M): L
Number: (08)7238700 <---- 區碼用括號標示
Address: No.51, Mingsheng E. Rd., Pingtung City
Name: Cheng-Kung Liu
Gender (M/F): M
Birthday (YYYY/MM/DD): 1995/12/3
Phone Type (L/M): M
Number: 0918123456
Carrier (C/T/F): T
Address: No.99, ChongHui St., Taipei City
.... 略
Name: Quit
Cheng-Kung Liu (Male) December 3rd, 1995, 0918123456(Taiwan Mobile), No. 99, ChongHui St., Taipei City.
Amy Wang (Female) March 5th, 1977, (08)7238700, No.51, Mingsheng E. Rd., Pingtung City.
... 略
[9:19 user@ws hw15]
本題要求以動態結構體陣列的方式來儲存及管理聯絡人資料,初始時陣列大小為10,當空間不足時,動態地調整陣列大小(增加10筆空間)。
注意:
- 程式執行的輸出格式必須與上述一致。
- 題目中的「contact.h」及「contact.c」可在「/home/stu/public/c/2015SCHW15」下載。
- 此題需turnin兩個檔案「main.c」與「contact.c」
提示:
- 你可以將多筆資料先存成文字檔,以導入(「< data.txt」)的方式進行測試。
c/homework/hw15.txt · 上一次變更: 2019/07/02 15:01 由 127.0.0.1
