1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Project report

29 1 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

ASSIGNMENT REPORT 1 C Programming Assignment Report Khoi Quy Nguyen Ho Chi Minh University of Technology Author Note Course name Introduction to Programming CO1003, HK182 Begin date 18 February, 2019[.]

ASSIGNMENT REPORT C Programming Assignment Report Khoi Quy Nguyen Ho Chi Minh University of Technology Author Note Course name: Introduction to Programming CO1003, HK182 Begin date: 18 February, 2019 Due date: 22 May, 2019 Submission date: 22 May, 2019 ASSIGNMENT PROGRESS REPORT Abstract This is the report of our team’s approach to the assignment The requirement was to write a customer relationship management program for an enterprise, which was divided into parts: customer information, information of commercial transactions, product details and subtasks In total, data structures and 21 functions were created Despite adversities throughout the project, we were able to communicate well and finished the project 20 days prior to the (recently changed) deadline, which was due 22 May However, minor changes was needed so we submitted again at 22 May ASSIGNMENT PROGRESS REPORT Method Participants As listed from the instructor’s attribution beforehand, our team has members: - Nguyen Quy Khoi (Student ID: 1852158) - Pham Phu Duy Khuong (Student ID: 1652327) - Quach Duc Khuong (Student ID: 1652328) - Mai Huy Gia Khiem (Student ID: 1652297) Assessments and Measures Test description and Results: (Nguyen Quy Khoi) (20 February)​ Create structure data types: ​Date​ , ​Customer​ , ​Product​ , Transaction.  - In this task, the structure data types were created according to the assignment’s requirement (25 February) ​Check for validation date - In this task, function ​isLeapYear​is used to check for leap year, which occurs every years (does not include the years divisible by 100) and century leap year, which occurs every 400 years starting from year AC This function uses operation ​%.​ - Restrain limit of days corresponding to each month (months with 31 days, 30 days and February) ASSIGNMENT PROGRESS REPORT Input: 29/2/2019 Input: 28/2/2019 Output: Output: Functions used for date validation: ​isLeapYear​ , ​isValidDate​ (Added on May 14)​ Check if a given string only contains alphabets and spaces (function isName​ ) The function operates based on known functions from the library ​ctype.h using for loop (Added on May 14)​ Check if a given string only contains alphabets, digits, spaces and commas (function ​isArray​ ) The function operates based on known functions from the library ​ctype.h​using for loop Get information from different parts: ​getCustomerInformation​ , getProdDetailInformation​ , ​createTransaction​ - (20 March)​ In function ​getCustomerInformation​and getProdDetailInformation​ , the information is validated using functions isValid​ , ​isName​and ​isArray​ - (23 March)​ In function ​createTransaction​ , transaction types are written in array of strings instead of enumerate data type for simplicity The types are then attached an order from to using variable ​choice​ , which was validated by function ​inputNumber​(this part was helped by Quack Duc Khuong)​ The rest are checked using while loop, function ​isValidDate​ , ​isValid​ (27 March)​ Display product details (function ​displayProdDetail​ ) if requested (27 March) ​Display customer information (function ​customerDataBase​ ) if requested ASSIGNMENT PROGRESS REPORT (27 March) ​Display product availability (function ​productDataBase​ ) if requested (27 March) ​Display transaction details (function ​transactionDataBase​ ) if requested 10 (14 May)​ Write project report (Mai Huy Gia Khiem) (23 February)​ Check if a given string with known length only contains digits which were written in ASCII code (function ​isValid​ ) (25 February)​ Return a number from user input which is smaller than a given limit (function ​inputNumber​ , validation loop included) The function is used in case of incorrect input from users ​(13 March)​ Given the selection menu constituting customer, product, transaction and save (in order to end the process of inputting information), let the user choose one of the options (function ​inputData​ , validation loop included) The function serves as an information input menu for users (Pham Phu Duy Khuong) (18 February)​ Proposing possible strategies for the assignment (27 February)​ After having finished inputting information, let the user choose to retrieve of these options: customer, product in stock, transaction and exit (function displayMenu​ , validation loop included) The function serves as a menu for retrieving any information from the data ASSIGNMENT PROGRESS REPORT (4 March)​ Comparison between processing date and starting date (function compareDate​ ) If the variable ​processDate​is “smaller” than ​startDate​ , replace processDate​with ​startDate​ (28 March)​ Complete subtask (function ​doTask1​ ) In order to search for customers whose number of transactions and value are the highest, the parameters in function doTask1 must include transaction information, customer ID as well as the limit for each requirement The logic is as follows: - Find customers with the highest number of transactions: As first, sort out every customer and transaction by comparing ​customers.id​and transactions.custID​ This was done with nested for loops (using twice) The inner for loop counts the number of transaction of each customer while the outer one increases based on how many customers are there from the input data Inside the loop, a conditional function checks whether the ​counter​variable is larger than ​maxTransaction​ If it is the case, ​maxTransaction​will have its value changed to ​counter​ In addition, the integer array ​index​will change correspondingly to the condition - Find customers with the highest value: Overall, the code is fairly similar to the aforementioned process The only difference is that the loop will sort out any customer who does not satisfy both conditions This part is possible because of the data from array ​index​in the previous loop - After having finished the requirements, function ​customerDataBase​is used to display subtask ASSIGNMENT PROGRESS REPORT (28 March)​ Complete subtask (function ​doTask2​ ) This task uses similar technique from ​doTask1​to search for the most valued product (Quach Duc Khuong) (18 February)​ Proposing possible strategies for the assignment (28 March)​ Complete subtask (function ​doTask3​ ) This task is similar to ​doTask2​ Task and task were done by both Duc Khuong and Duy Khuong (28 March) ​Complete subtask (function ​doTask4​ ) This task is similar to ​doTask1​ The only difference is the output of the function, which displays city names instead of customer information Because of several similarities between task and task 4, Duc Khuong and Duy Khuong did both together (28 March)​ Complete subtask (function ​doTask5​ ) - Similar to the array above, transaction types are written in array of strings instead of enumeration For each transaction, if its type is similar to a chosen type, the corresponding element in the array ​sameType​will have the same structure data - After that, the next for loop will sort out the elements in the array in ascending order and print out the result using function ​transactionDataBase​ ASSIGNMENT PROGRESS REPORT (The whole team) Main function: - As planned in the first week, the main function would be a combination of switch case, for and while loop Although the deadline for function completion was set to be 15 March at first, we went idle for weeks in March As a result, it was put off until 28 March - In the first half of April, which was a 2-week off from school, we completed the main function The only obstacle we faced was case for inputting transaction data It was resolved as follows: + The input data is restrained by conditional operator If the condition returns True, we will check for transaction date and starting date using function compareDate​​(done by Pham Phu Duy Khuong) + If a customer chooses several different products, the initial quantity of the each product is reduced until they are out of stock ​(done by Quach Duc Khuong) - After having finished the switch case statement, the last thing to is to display desired data from user ​(done by Quach Duc Khuong)​ and write down functions for subtasks Results Almost every task was finished Noticeable flaws: We did not check for identical ID numbers and phone numbers while inputting data As a result, conflicts will occur if user input for IDs happens to be the same with preceding ones ASSIGNMENT PROGRESS REPORT Full source code #include   #include   #include   #include     #define MAX_DATA 10    typedef struct {  int day;  int month;  int year;  } Date;    typedef struct{  char id[9];  char name[100];  char phone[13];  char address[200];  char city[100];  Date startDate;  } Customer;    typedef struct {  char id[9];  char name[100];  char model[100];  unsigned int quantity;  float unitPrice;  } Product;    typedef struct {  char id[9];  char custID[9];  char type[7];  float value;  Product prod;  Date processDate;  int quantity;  } Transaction;    ASSIGNMENT PROGRESS REPORT Customer getCustomerInformation();  Product getProdDetailInformation();  Transaction createTransaction(Customer customer, Product prod);    int isArray(char str[]);  int isName(char str[]);  int isLeapYear(int year);  int isValidDate(Date inDate);  int isValid(char str[], int strLength);  int inputNumber(int limit);  int inputData();  int displayMenu();    Date compareDate(Date, Date);    void customerDataBase(Customer customers[], int size);  void productDataBase(Product products[], int size);  void transactionDataBase(Transaction transactions[], int size);    //void displayCustomerMenu(Customer);  //void displayProdMenu(Product);  //void displayTransactionMenu(Transaction);  void displayProdDetail(Product);  //void displayCustomerInformation();  //void displayTransactionInformation();    void doTask1(Transaction transactions[], int transNum, Customer  customers[], int custNum);  void doTask2(Transaction transactions[], int transNum);  void doTask3(Transaction transactions[], int transNum);  void doTask4(Transaction transactions[], int transNum, Customer  customers[], int custNum);  void doTask5(Transaction transactions[], int transNum);    int main()  {  Customer customers[MAX_DATA];  Product products[MAX_DATA];  Transaction transactions[MAX_DATA];    int isExit = 0;  int custNum = 0;  10 ASSIGNMENT PROGRESS REPORT 15 } while (!isValid(prod.id, 8));  {  printf("2/ Input product name: ");  gets(prod.name);  } while (!isName(prod.name));  {  printf("3/ Input product model: ");  gets(prod.model);  } while (!isArray(prod.model));  printf("4/ Input product quantity: ");  scanf("%d", &prod.quantity);  printf("5/ Input product unit price: ");  scanf("%f", &prod.unitPrice);  return prod;  }    Transaction createTransaction(Customer customer, Product prod) {  Transaction transaction;  char type[3][7] = {"whole", "retail", "other"};  int choice = -1;  printf("Input transaction detail\n");  getchar();  {  printf("1/ Input transaction ID: ");  gets(transaction.id);  } while (!isValid(transaction.id, 8));  strcpy(transaction.custID, customer.id);  {  printf("2/ Input transaction processing date in form of  dd/mm/yyyy: ");  scanf("%d/%d/%d", &transaction.processDate.day,  &transaction.processDate.month, &transaction.processDate.year);  } while (!isValidDate(transaction.processDate));  printf("3/ Choose the type of transaction\n1 Whole\n2 Retail\n3.  Other\n");  choice = inputNumber(3);  strcpy(transaction.type, type[choice - 1]);  transaction.prod = prod;  // printf("%d/%d/%d\n", transaction.processDate.day,  transaction.processDate.month, transaction.processDate.year);  return transaction;  }  ASSIGNMENT PROGRESS REPORT 16   int isName(char str[]) {  for (int i = 0; str[i] != '\0'; i++) {  if (isalpha(str[i]) != || isspace(str[i]) != 0) continue;  else return 0;  }  return 1;  }    int isArray(char str[]) {  for (int i = 0; str[i] != '\0'; i++) {  if (isalpha(str[i]) != || isspace(str[i]) != ||  isdigit(str[i]) != || str[i] == ',') continue;  else return 0;  }  return 1;  }    int isLeapYear(int year) {  if (year % != 0)  return 0;  else if (year % 100 != 0)  return 1;  else if (year % 400 != 0)  return 0;  else  return 1;  }    int isValidDate(Date inDate) {  if (inDate.day < || inDate.month < || inDate.year < ||  inDate.day > 31 || inDate.month > 12)  return 0;  if (inDate.month == 2) {  if (isLeapYear(inDate.year)) {  if (inDate.day > 29)  return 0;  } else {  if (inDate.day > 28)  return 0;  }  }  ASSIGNMENT PROGRESS REPORT 17 if (inDate.month == || inDate.month == || inDate.month == ||  inDate.month == || inDate.month == || inDate.month == 10 ||  inDate.month == 12) {  if (inDate.day > 31)  return 0;  } else {  if (inDate.day > 30)  return 0;  }  return 1;  }    int isValid(char str[], int strLength) {  int inStrLength = strlen(str);  if (inStrLength != strLength)  return 0;  for (int i = 0; i < strLength; i++) {  int convert = (int) str[i];  if (convert > 57 || convert < 48)  return 0;  }  return 1;  }    int inputNumber(int limit) {  int userChoice = -1;  while (1) {  printf("Please select: ");  int flag = scanf("%d", &userChoice);  if (flag == EOF) {  while (fgetc(stdin) != '\n') {}  continue;  }  else if (flag == 0) {  while (fgetc(stdin) != '\n')  continue;  }  else if (userChoice < || userChoice > limit) {  while (fgetc(stdin) != '\n')  continue;  }  else  ASSIGNMENT PROGRESS REPORT 18 break;  }  return userChoice;  }    int inputData() {  printf("**************************************************\n");  printf("Select information you want to input\n");  printf("1 Customer\n");  printf("2 Product\n");  printf("3 Transaction\n");  printf("4 Save\n");  int userChoice = -1;  while (1) {  printf("Please select: ");  int flag = scanf("%d", &userChoice);  if (flag == EOF) {  while (fgetc(stdin) != '\n') {}  continue;  }  else if (flag == 0) {  while (fgetc(stdin) != '\n')  continue;  }  else if (userChoice < || userChoice > 4) {  while (fgetc(stdin) != '\n')  continue;  }  else  break;  }  printf("**************************************************\n");  return userChoice;  }    int displayMenu() {  printf("**************************************************\n");  printf("Select information you want to retrieve\n");  printf("1 Customer\n");  printf("2 Product in stock\n");  printf("3 Transaction\n");  printf("4 Exit\n");  ASSIGNMENT PROGRESS REPORT 19 int userChoice = -1;  while (1) {  printf("Please select: ");  int flag = scanf("%d", &userChoice);  if (flag == EOF) {  while (fgetc(stdin) != '\n') {}  continue;  }  else if (flag == 0) {  while (fgetc(stdin) != '\n')  continue;printf("*****Task5*****\n");  }  else if (userChoice < || userChoice > 4) {  while (fgetc(stdin) != '\n')  continue;  }  else  break;  }  printf("**************************************************\n");  return userChoice;  }    Date compareDate(Date custDate, Date transDate) {  if (custDate.year < transDate.year) {  return custDate;  } else if (custDate.year == transDate.year) {  if (custDate.month < transDate.month)  return custDate;  else if (custDate.month == transDate.month) {  if (custDate.day < transDate.day)  return custDate;  else  return transDate;  } else  return transDate;  } else  return transDate;  }    void displayProdDetail(Product prod) {  printf("Product Details List\n");  ASSIGNMENT PROGRESS REPORT printf("Product printf("Product printf("Product printf("Product printf("Product 20 ID: %s\n", prod.id);  name: %s\n", prod.name);  model: %s\n", prod.model);  quantity: %d\n", prod.quantity);  unit price: %.2f\n", prod.unitPrice);  }    void customerDataBase(Customer customers[], int size) {  for (int i = 0; i < size; i++) {  printf("%d/ %s\t%s\t%s\t%s\t%s\t%d/%d/%d\n", i + 1,  customers[i].id, customers[i].name, customers[i].phone,  customers[i].address, customers[i].city,  customers[i].startDate.day,  customers[i].startDate.month, customers[i].startDate.year);  }  }    void productDataBase(Product products[], int size) {  for (int i = 0; i < size; i++) {  printf("%d/ %s\t%s\t%s\t%d in stock\t%.2f\n", i + 1,  products[i].id, products[i].name, products[i].model,  products[i].quantity, products[i].unitPrice);  }  }    void transactionDataBase(Transaction transactions[], int size) {  for (int i = 0; i < size; i++) {  printf("%d/ %s\t%s\t%s\t%s\t%.2f\t%d/%d/%d\n", i + 1,  transactions[i].id, transactions[i].custID, transactions[i].prod.name,  transactions[i].type, transactions[i].value,  transactions[i].processDate.day,  transactions[i].processDate.month, transactions[i].processDate.year);  displayProdDetail(transactions[i].prod);  printf("\n");  }  }    void doTask1(Transaction transactions[], int transNum, Customer  customers[], int custNum) {  int maxTransaction = -1;  int index[MAX_DATA];  int indexSize = -1; 

Ngày đăng: 11/04/2023, 18:46

Xem thêm:

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w