Sunteți pe pagina 1din 2

CP12a Performance Task #2 – Finals

Create a new project called UpdateProgram. Using the same database and the existing table tbl_users,
create an update program that will modify records based on a given user id. Refer to the example
output below:

Assuming we have two records in tbl_users.

uid username password a_name age gender


1001 root admin123 super user 33 m
1002 guest random321 wondergirl 25 f

Program interface / output

User’s input Input #


Enter user id: 1001 <enter> 1
Would you like to update root [y/n]? y <enter> 2
Enter new username: moderator <enter> 3
Enter new password: moderator321 <enter> 4
Confirm new password: moderator321 <enter> 5
Enter new account name: arminne <enter> 6
Enter new age: 34 <enter> 7
Enter new gender: f <enter> 8
You have successfully updated the account!

Input # 1 – When entering the user id, the program should first check if there’s an existing record using
the index(user id) provided by the user. User id 1001 refers to the first record.
NOTE: if the user id provided doesn’t exist in the database, the program should say “Unable to find
record.”

Input # 2 – After entering the user id, a confirmation should display asking the user to confirm if he
wishes to proceed to update the selected user, the prompt should show the username.
NOTE A: If the user entered ‘n’, the program should abort the operation. Entering ‘y’ will proceed to the
next inputs.
NOTE B: The program should only accept ‘y’ or ‘n’ inputs only, entering other characters will abort the
operation, and the program should say “invalid input, please try again”

Input # 3 – Upon entering “y” as for yes, the program will now continue to ask the user. The first update
should be the username.

Input # 4 – Next, the password.

Input # 5 – Password verification, the user should match his password.


NOTE: If the password did not match, the program should abort and the program should say “invalid
password”

Input # 6 – Account Name

Input # 7 – User’s Age


NOTE: The program should only accept a number. Other than that, the program will abort. The program
should say “invalid input, please try again”.

Input # 8 – User’s gender


NOTE: The program should accept only ‘f’ or ‘m’ input, any other characters should abort the operation,
and the program should say “invalid input, please try again”.

Once done, the record should change based by the new data given by the user.
Modified record after running the update program.

uid username password a_name age gender


1001 moderator moderator321 arminne 34 f
1002 guest random321 wondergirl 25 f

If you wish for more challenges, you can do the following. (optional)

1. If the user entered an invalid input, the program should ask the user to re-enter the data. (done
using a loop)
2. The user should not be able to register another account if the username already exist in the
database. The program will suggest a username that doesn’t exist yet based on the username
given.
3. After updating the account, the program will ask the user again, if he would like to update
another account.
eg. Would you like to update another account? [y/n]
hitting ‘y’ would start the program again, repeating the same process.

Rubrics

Input # Points Validation


1 10 Must be able to search the id from the database
2 10 Must accept y or n characters only
3 5
4 5
5 10 Must be able to compare password.
6 5
7 10 Must accept numeric characters only.
8 10 Must accept f or m characters only
Total 65

S-ar putea să vă placă și