In this project, you are required to develop a similar program with project 1 bu
ID: 3695742 • Letter: I
Question
In this project, you are required to develop a similar program with project 1 but using C programming language. This program named “MyWallet.c” is a simple bills manager system. Each bill corresponds to a record (line) in a text file named “bills.txt” (if this file is inexistent, create it). Each record consists of 7 fields (record ID, category, detail, amount, year, month, day) separate by percent sign(%).
e.g.:
1%restaurant%subway%5.58%2016%2%11
2%gas station%shell%20.15%2016%3%1
• No percent sign(%) in each field because % is the field separator. For example, (1%resta%urant%subway%5.58%2016%2%11) is forbidden because the category field contains a %.
• The “record ID” is an unique non-negative int number (starts from 0) and generated by this system automatically. (when create a new record, the ID should be the last record’s ID number +1.)
• The category and the detail are string values with maximum length of 255 characters, the amount is double number. All of these three values are input by users.
• The year , month, and day are three int numbers generated by this system by using the record creation time.
• MyWallet should provide a menu with following functionalities that users can choose from at the top level menu:
1. Enter “a” to add a new bill
• Ask for category
• Ask for detail
• Ask for amount
• Generate record ID and date
• Add this new record into “bills.txt” file
• At the end, print "New bill added successfully"
• Provide option "t" for "Try again" and "b" for "Back to main menu"
2. Enter “d” to remove a bill
• Ask for record ID
• Examine if this record exits. if no, print a message “No such record!”, otherwise, display this record and remove it from “bills.txt” file.
• Provide option “t” for “Try again” and “b” for “Back to main menu”
3. Enter “c” to count amount
• Ask for time range (start date(year, month,day) and end date(year,month,day))
• Count and display amount of all bills in this time period. (add all satisfied records’ amount values together)
• Provide option “t” for “Try again” and “b” for “Back to main menu”
4. Enter “v” to view bills
• Ask for search type (by category, by time, or by record ID)
• Ask for category if by category
• Ask for time range if by time
• Ask record ID if by record ID
• Display all bills satisfied the condition
• Provide option “t” for “Try again” and “b” for “Back to main menu”
5. Enter “q” to quit this system
• Terminate this system
Explanation / Answer
Ans;
clear
i="y"
var=1
total=0;
FILE = "bills.txt"
while [ $i = "y" ]
do
clear
echo "Enter “a” to add a new bill "
echo "Enter “d” to remove a bill "
echo "Enter “c” to count amount "
echo "Enter “v” to view bills "
echo "Enter “q” to quit this system"
echo "Enter your choice "
read ch
case $ch in
a)$cat FILE >> copy_FILE;;
echo "Enter category: "
read cate
echo "Enter detail: "
read deta
echo "Enter amount:"
read amount
now = "$(date+'%d/%m/%Y')"
echo "$var $cate $deta $amount $now">> $FILE ;;
let "var++"
d)echo "Enter Id"
read id
# set -a
# sed '/$id/d' $FILE>dbs1
grep -v "$id" $FILE>dbs1
echo "Record is deleted"
cat dbs1;;
c)echo "Total amount: $total"
v) start_date = $(date +'%d/%m/%Y')
end_date = $(date +'%d/%m/%Y')
read -p "Enter start date (dd-mm-yy): " start_date
read -p "Enter end date (dd-mm-yy): " end_date
cat FILE | while [$ch = "t"]
do
if [$now == $start_date -ge $now == $end_date];
total = 'expr $amount + $total'
echo "Try it again by press t"
echo "Back to menu press b"
read c
case $c in
t) ch = "c"
b) i = "y"
q)exit;;
*)echo "Invalid choice ";;
esac
echo "Do u want to continue ?"
read i
if [ $i != "y" ]
then
exit
fi
done
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.