Você está na página 1de 4

THE HONG KONG POLYTECHNIC UNIVERSITY

Computer Programming (ENG236/ENG2002) 2012/13 Assignment 3


A. Instructions
1.

2.
3.
4.

You should submit ONE compressed file with the name: xxxxxxxx (where xxxxxxxx is your student ID number) on or
before 21 April 2013 via email: ykmok@outlook.com. The file should contain solution folders of your programs. Three
marks will be deducted for each day delayed.
You must add a comment to show your name and student ID at the beginning of each header file.
Your programs need to be well commented. Lacking comments will result in down-grading.
You are NOT advised to share a copy of your program source to your fellows. Plagiarism by others may make your mark
zero.

B. The Programming Task


By using Visual Studio C++, you need to implement a Windows Forms application program that carries out the tasks of the
previous assignment 2 but in graphical mode. First of all, you MUST create a folder with the name as your student id and then a
project name as your student id too which should be placed into this created folder.
You should download the customer data file customer.txt for your program. The file name and the format of data cannot be
changed. Each row of the file contains one customer information in which the sequence of data is listed in the following table.
These properties are separated by one # character. ifstream and ofstream objects must be used to process the data in the file.
Seq.
Property
Type Max. Min.
Limitations
1
Login ID
char
10
5
1. value is unique and case-sensitive; 2. allow space; 3. not accept # char
2
Password
char
10
5
1. value is case-sensitive; 2. allow space; 3. not accept # char
3
Name
char
30
1. first char of each word is in upper-case; 2. allow space; 3. no # char
4
Email
char
30
1. value contain one @ character at least; 2. no space and no # char
5
Card No.
int
1. value is unique; 2.range: 55000000 to 55999999 inclusively
6
Class Level
int
values are only: 1(=Silver), 2(=Gold), 3(=Platinum) or 4(=Diamond)
7
Reward Cash
float
1. allow negative value
When the program runs, it requires user login first.

Fig. 1
Do Check
1
Put your student id on the title of the window
2
Check id that exists in the file and the input password is matched
3
If the id inputs as admin, the required password is ddff
4
window size is fixed
After successful user login, it goes into the customer information window.

Fig. 2

Fig. 2a

Fig. 2b
Page 1 of 4

version 1.3 26 March

Do
1
2
3
4

6
7

Check
Put the found records number on the title of the window which is according to the record located on which row in the file
Display customer record, only input fields of Name and Email can be editable.
Password should be masked by * while Class value is shown as combobox item
Change button: go to Change Password window as Fig. 2b and show the record id;
Change button in Fig. 2b: check original password that match the input of Old password, check the length of new password
and this contains no # char, finally check the Re-confirm password matches the New password, then change the password
of the record but not saved to file.
Cancel button in Fig. 2b: go back to Customer info. window as Fig. 2
Update rec. button: 1. check values of name and email; if error found, show the error in message box as shown in Fig. 2. 2.
make the first character of each word of the name input to uppercase, 3. save password, name and email of the record to the
file, 4. show message box as Fig. 2a, 5. change the heading and the button text as shown in Fig. 2a
Cancel button or Logout button: go back to Login window as Fig. 1.
window size is fixed

If user logins as admin with password ddff, it goes into the admin. operation window Fig. 3.

Fig. 3
Do
1
2
3
4
5

Fig. 3a
Fig. 3b
Check
Put the total number of records on the title of the window
Only shown a textbox as Fig. 3a when first option chosen and only shown a groupbox as Fig 3b when third option selected
Go button: check the operation selected and the input data if any; if error occurs , show message box as shown in above Fig.
Logout button: go back to Login window as Fig. 1
window size is fixed

When the 1st option of searching a customer is selected and the input card number exists, it goes to customer info. window.

Fig. 4

Fig. 4a

Fig. 4b
Page 2 of 4

version 1.3 26 March

Do
1
2
3
4
5
6
7

Check
Put the found records number on the title of the window which is according to the record located on which row in the file
Display customer record except password(masked by *), all data fields are editable (change button is invisible now)
Clear the password field and display input characters when characters are being typed in this field as shown in Fig. 4a
Class value should be shown and selected as combobox item: Silver, Gold, Platinum and Diamond
Update rec. button: 1. check all data input as the Data-Checking table stated below, 2. if no error found, save all information
of the record to the file, 3. show message box as Fig. 4b and change the heading and the button text
Cancel button or Back button: go back to Admin. operation window as Fig. 3.
window size is fixed

Data-Checking Table:
Input
Check
ID
1. length should be 5 to 10 inclusively; 2. no # char; 3. admin id and existing id not allowed
Password 1. length should be 5 to 10 inclusively; 2. no # char
Card No. 1. 8 digit whole number of range 55000000 to 55999999 inclusively; 2. existing card no. not allowed
Name
1. length is not longer than 30 chars; 2. not empty and not all space; 3. no # char; 4. first character of each word
changed into upper case
Email
1. length is not longer than 30 chars; 2. no # char, no space but at least one @ char
R. Cash
1. input of number, not characters like abc; 2. not empty
Class
1. at least one class selected;
When the 2nd option of Add a customer is selected, it goes to customer info. window.

Fig. 5
Do
1
2
3
4
5
6
7

Fig. 5a

Fig. 5b

Check
Put the next number of last record number on the title of the window and this record is empty for data storage
The heading becomes Add a customer record:
All data fields become editable and empty (change button is invisible now, update rec. button becomes add rec. button)
Class value should be shown and selected as combobox item: Silver, Gold, Platinum and Diamond
Add rec. button: 1. check all data input as the Data-Checking table stated above, 2. if no error found, save all information of
this added record to the end of the file, 3. show message box as Fig. 5a and change the heading and the button text as Fig. 5b
Cancel button: go back to Admin. operation window as Fig. 3.
window size is fixed

When the 3rd option of searching customers and a class is selected, it opens a window of customers of selected class as shown in
Fig. 6. All customers information of the selected class will be displayed except the password, and the format should be as Fig. 6
shown and not editable.
Fig.7 below shows the list of all customers in ascending order of Cash Reward when the 4th option of sorting customers in
ascending orders is selected. The format and the list information should be displayed as Fig. 7 and not editable.

Page 3 of 4
version 1.3 26 March

Fig. 6.

Fig. 7.

NOTE:
1. Reference example program is provided for you to follow which can be run in computer with visual studio 2010 installed
2. You may assume the data file customer.txt contains no more than 30 customer records
3. A window displayed requires a corresponding windows form created, normally under Header Files of the project. For
example, Record.h, a windows form for customer information window
4. All Forms should be loaded as modal form, i.e. called by function ShowDialog();
5. For example, if it is required to open a customer info. window, then the codes will be:
#include Record.h
Record^ info = gcnew Record();
info->ShowDialog();

//line 1

6. If some information need transferring to the new window, a new constructor in the new form may be created. For example:
public: Record(int display, int record_no) {
InitializeComponent();
rec_no = record_no; //rec_no is a local variable of the class Record, used for locating the record in the array
if (display == 1) {...}
//change properties of components to display Fig. 2
else if (display == 2) {...} //change properties to display Fig. 4
else if (display == 3) {...} //change properties to display Fig. 5
....}

So if it is user login successfully, the line 1 will be changed into:


Record^ info = gcnew Record(1, n);

//n is the number of record found, i.e. index of record of the customer array

7. Going back to previous form can be done by function: Close(); //close current form
8. Using objects of ifstream and ofstream to process data file, for example:
ifstream fin(customer.txt);
if (fin) {
while (!fin.eof()) { ...;
fin.getline(id_string, 11, #); ...;
fin.getline(cash_string, 30, \n);
... }
fin.close();
} else { ... } //show message of cant open file

9. A property that makes textBox to be editable or not editable is:


textBox1->ReadOnly = false;

//make editable; true = not editable;

10. Button to be shown or not shown:


button1->Visible = true;

//show button1; false = not shown;

11. Changing text of a component, for example, a label:


label1->Text = put your words here;

12. Pop-up a message dialog window can be, for example:


MessageBox::Show(No record by such id., ====Attention====); //1st String is message, 2nd String is window title

13. Customer list window may contain a richTextBox. The records can be shown, for example:
String^ rec_Str= ;
for (int i=0, j=1; i < ... ; i++) //loop n records times
if (record[i]s class level == the selected class) { ...;
//record is an array of all customer records
rec_Str += ------------Count# + j + ---\r\nID: + gcnew String(record[i].id) + ...; //append record info
j++; ...;
}
richTextBox1->Text = rec_Str;

14. Dont use goto instruction in the program


15. Functions that may help you to manipulate the char array:
i. strcpy(dest_ch, source_ch);
ii. strcmp(ch_array1, ch_array2)
iii. strlen(ch_array);

//copy char array


//if two char arrays are equal, this will return zero
//returns no. of char in the array

16. If you have any queries on the programming, just email to me your question: yk.mok@polyu.edu.hk
Page 4 of 4
version 1.3 26 March

Você também pode gostar