CSE 1
3
2
0: Intermediate Programming
University of Texas at Arlington
Spring 2021
Dr. Alex Dillhoff
Assignment
4
This assignment focuses on using command line arguments, structs, typedefs, and file
I/O.
1. Create a program that copies the data from one file to another while converting all
characters matching the search key with that of the replace key. Your program
should accept four arguments:
(a) input filename
(b) output filename
(c) search character
(d) replace character
• Warn the user if the input file does not exist.
• Your program should check to make sure the output file does not already exist.
If it does, print “DESTINATION FILE EXISTS.” to stdout.
• Print the number of characters changed to stdout using the format string
“%d characters changed.”
• The search and replace characters are case-sensitive.
• Save your code as search_and_replace.c.
Example Run
$ ./a.out input.txt output.txt A d
15 characters changed.
2. Create a program that reads a file of 2D coordinates and calculates the bounding
box and center of the bounding box. The bounding box is defined as the minimum
area that fully encompasses all the coordinates. The center of that bounding box is
calculated by taking the mean of the bounding box coordinates: (x1+x2
2
, y1+y2
2
).
• Use file keypoints.txt for an example of what the input data will look like.
• If the input file cannot be opened, warn the user by printing “CANNOT OPEN FILE.”
to stdout.
• Use typedef to create a type vector2f that defines an array of 2 float values.
Use this type when working with coordinate data in your program.
• Print the resulting bounding box and center to stdout using the format string
%.2f,%.2f,%.2f,%.2f,%.2f,%.2f, following the pattern
xmin, ymin, xmax, ymax, xcenter, ycenter.
CSE 1320: Assignment 4 Dillhoff
• Save your code as bounding_box.c.
Example Run
$ ./a.out keypoints.txt
0.00,0.00,100.00,100.00,50.00,50.00
3. Create a program that parses a CSV file of product data and loads the items into a
struct with the following members:
• ID
• Name
• Price
• Quantity
Additional Requirements
• Use file prices.csv for an example of what the input data will look like.
• Your program should take two arguments: an input file to process and a price
limit.
• Print only the names of each item to stdout that have a price less than or
equal to the given limit.
• If an item has 0 stock, indicated by quantity, do not print it out.
• If the given file does not exist or cannot be opened, warn the user by printing
“CANNOT OPEN FILE.” to stdout.
• Save your code as price_check.c.
Example Run
$ ./a.out prices.csv 199.99
MSI X470 Gaming Plus
Corsair DDR4 Memory
4. Given a file containing keywords that were parsed from messages on a social media
website, create a program that allows a user to determine if a keyword is trending
or not. A keyword is considered trending if there are at least 3 occurrences of it in
the given file.
• In your code, create a function that accepts a string and an array of strings. The
function should return 1 if the input string is considered trending, 0 otherwise.
• Your program should accept two command line arguments (not including the
program name) representing the name of the file to load and the keyword to
check, respectively.
• Make sure you check that the given file exists.
• Format your output similar to the example run given below. The keyword
should be printed in quotes.
• Use the file keywords.txt.
2
CSE 1320: Assignment 4 Dillhoff
• Save your code as trending.c.
$ ./a.out keywords.txt coffee
“coffee” is not trending.
$ ./a.out keywords.txt perseverance
“perseverance” is trending with 6 messages.
5. Create a program that reads and writes creature data from and to a file using
fread() and fwrite(). The creature data should be represented as a struct with
the following data members:
• Name
• CR
• AC
• HP
Your program should include a menu that allows the user to list creature data or
add a new creature. It should keep the user inside the program until they choose
an option to exit.
• The struct should be defined using typedef.
• The data file should be passed as a command line argument.
• If the file cannot be opened for any reason, warn the user.
• If the file does not exist, create it.
• The program should check for invalid input in the menu. You can assume valid
data will be entered for the creatures.
• Your output should match the output shown in the example below. Take care
that the divider line is the same length as the name and that the entries have
an empty line between them.
• After adding a creature, it should be written (append) to the file.
• Save your code as creature_db.c.
Example Run – Adding Creatures
1. List Creatures
2. Add Creature
3. Exit
> 2
Enter Name: Adult Blue Dragon
Enter Challenge Rating: 16
Enter Armor Class: 19
Enter Hit Points: 225
Creature added!
Example Run – List Creatures
3
CSE 1320: Assignment 4 Dillhoff
1. List Creatures
2. Add Creature
3. Exit
> 1
Beholder
——–
CR: 13
AC: 18
HP: 180
Adult Blue Dragon
—————–
CR: 16
AC: 19
HP: 225
Create a zip file using the name template LASTNAME_ID_A4.zip which includes the all
required code files. Submit the zip file through Canvas.
4
1 | 0 | Intel Core i | 7 | 3 | |||||
1001 | Intel Core i7-9700K | 4 | 8 | 5 | |||||
1002 | Intel Core i7-4790K | 294.98 | 21 | ||||||
1003 | Intel Core i7-9800X | 654.31 | |||||||
11 | AMD Ryzen 9 3900XT | 498.99 | |||||||
1101 | AMD Ryzen 5 3600XT | 249.99 | 15 | ||||||
2000 | MSI X470 Gaming Plus | 124.99 | 13 | ||||||
2100 | ASUS ROG Strix B550-E | 279.99 | |||||||
3000 | MSI GeForce RTX 3080 | 759.99 | |||||||
3001 | MSI GeForce RTX 3090 | 1549.99 | |||||||
4000 | Corsair Vengeance RGB Pro 16GB | 87.99 | |||||||
4100 | G.SKILL Ripjaws V Series 32GB | 113.99 | |||||||
4101 | G.SKILL TridentZ RGB Series 32GB | 134.99 | |||||||
4200 | Patriot Viper Steel 16GB | 149.99 |
0.2747 | -0.0407 |
0.2930 | -0.3502 |
0.2509 | -0.5394 |
0.1940 | -0.6613 |
0.0828 | -0.7390 |
-0.1972 | -0.1785 |
-0.3611 | -0.2505 |
-0.5128 | -0.3271 |
-0.5788 | -0.3423 |
-0.1744 | -0.1047 |
-0.3375 | -0.1832 |
-0.4705 | -0.2038 |
-0.5197 | -0.2352 |
-0.0669 | -0.0326 |
-0.2741 | -0.2601 |
-0.3911 | -0.4155 |
-0.4484 | -0.4903 |
0.0518 | 0.0372 |
-0.0310 | -0.3577 |
-0.0200 | -0.6797 |
-0.0152 | -0.8077 |
pokemon
countdowntomars
sagan
countdowntomars
critrole
awc
euler
sotu
pokemon
countdowntomars
gen4
critrole
curiosity
expanse
awc
leibnitz
sagan
countdowntomars
expanse
awc
leibnitz
awc
rlcs
sotu
sagan
einstein
critrole
pokemon
pokemon
awc
blizzconline
einstein
einstein
pokemon
expanse
euler
We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.
Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.
Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.
Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.
Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.
Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.
We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.
Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.
You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.
Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.
Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.
You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.
You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.
Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.
We create perfect papers according to the guidelines.
We seamlessly edit out errors from your papers.
We thoroughly read your final draft to identify errors.
Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!
Dedication. Quality. Commitment. Punctuality
Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.
We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.
We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.
We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.
We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.