Using Putty / Unix, what is the proper way to create a quit
option in a program? I know of a few ways to do it in C++ ,
and I know there's more "proper" ways to do it than other
ways. Thanks for the help
This project is to acquaint you with fundamental UNIX commands
and utilities when creating a multifunctional application. You will
practice on managing shell variables, using shell operators,
employing selection and repetition logic structures, creating a
menu-based program, listing contents of a file, adding records to a
file, searching patterns in a file, deleting records from a file,
and using UNIX commands/utilities to manage cursor and output
format, etc. The completion of the project will strengthen your
knowledge and skills of utilizing UNIX commands/utilities and UNIX
shell script programming language.
In this project you will build a menu-based application for
tracking vehicle information. The specifications of the project are
as follows:
1.
(5 points) The vehicle records are stored in a text file
vehicle_data, as shown in Figure 1. The file contains information
about a vehicle’s ID, year, make, model, mileage, and price. Each
record is stored on one line and has the above six fields separated
by the colon “:” character. The initial data file contains the
following records:
(10 points) It is a menu-based program with a main screen
offering the user options to view records, add records, find
records, delete records, and quit the program, as shown in Figure
2. Use a case statement to determine what choice the user made and
perform the appropriate action. The only way to exit the
application is by pressing Q or q to quit the program. All other
options should return to the main menu. Your program should handle
the case in which the user doesn’t enter anything, or the user
enters an invalid option.
Note: When using the vehicle_data file in your scripts, use the
relative path to the current working directory, for example,
myfile=./vehicle_data. Do not use absolute path or relative path to
your home directory.
(20 points) The View Records option should display a sub-menu,
as shown in Figure 3, to let user choose how the records are sorted
before they are displayed. The records can be sorted by Make in
alphabetic order, or sorted by Year, Mileage, or Price in ascending
numerical order, or sorted by ID in ascending numerical order by
default. The records should be displayed in a neat fixed-length
format as shown in Figure 4 and Figure 5. The total number of
records should also be displayed. The program returns to the main
menu after records are displayed and the “Enter” key is
pressed.
2.
3.
Hints:
(15 points) The Add Records option should allow the user to
enter the vehicle ID, year, make, model, mileage, and price. This
information will be appended to the end of the file vehicle_data,
all on one line, separated by the colon “:” character (see Figure
6, 7 and 8). If a vehicle ID has already existed in the data file,
display an error message and let the user reenter the data (see
Figure 9). The program should allow the user to add another record
if ‘y’ is entered or return to the main menu if ‘q’ is entered (see
Figure 7, 9, and 10).
Extra credit (3 points): A record with an empty field can’t be
added to the data file. If any field is empty, display an error
message “No field can be empty. Record is not added”.
(5 points) The Find Records option should prompt the user for a
string pattern to search for in the data file and display all the
records that contain that pattern (see Figure 11). The program
returns to the main menu after the “Enter” key is pressed.
Extra credit (2 points): Display “No record found” if no match
is found (see Figure 12).
(10 points) The Delete Records option should prompt the user for
a pattern, display all the records that contain that pattern, ask
the user to confirm yes or no to delete these records (see Figure
13), and perform the appropriate actions. The program returns to
the main menu after the “Enter” key is pressed.
Extra credit (2 points): Display “No record found” if no match
is found (see Figure 14).
(2 points) The Quit option will exit the
application.
(8 points) The source code of the above four options (view, add,
find, and delete) should be placed in four separate script
files.
(10 points) Make a shell script called functions that defines
the following five functions: i. sort_ID to sort the records in the
ascending numerical order of vehicle ID.
ii. sort_year to sort the records in the ascending order of
vehicle’s year.
iii. sort_make to sort the records in the alphabetic order of
vehicle’s make,
iv. sort_mileage to sort the records in the ascending order of
vehicle’s mileage,
v. sort_price to sort the records in the ascending order of
vehicle’s price. Use function(s) in the View Records module to sort
the records according to user’s choice.
(5 points) The program should have necessary comments including,
but not limited to, the script name, author’s name, date
information, and the purpose of the script.
Using Putty / Unix, what is the proper way to create a quit option in a program? I know of a few ways to do it in C++ ,
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am