程序代写代做代考 C AU 2020 CSE 2421 LAB 3 Assigned: Wednesday, September 16th

AU 2020 CSE 2421 LAB 3 Assigned: Wednesday, September 16th
Early Due Date: Wednesday, September 23rd by noon Due: Thursday, September24th, by 11:30 p.m.
Objectives:
∙ Pointers
∙ Multiple Levels of indirection ∙ Dynamic memoryallocation
∙ Functions
∙ Arrays (dynamically allocated) ∙ Character Strings
REMINDERS and GRADING CRITERIA:
 This is an individual lab.
 Waitinguntilthedaythislabisduetostartworkingonit,wouldbeanunbelievablybadidea.
 Effort has been made to insure that this lab description is complete and consistent. That does not
mean that you will not find errors or inconsistency. If you do, please ask for clarification.
 Every lab requires a Readme file (for this lab, it should be called lab3Readme – use this name. This file should include the following:
∙ Required Header:
BY SUBMITTING THIS FILE TO CARMEN, I CERTIFY THAT I HAVE STRICTLY ADHERED TO THE TENURES OF THE OHIO STATE UNIVERSITY’S ACADEMIC INTEGRITY POLICY WITH RESPECT TO THIS ASSIGNMENT.
THIS IS THE README FILE FOR LAB 3.
∙ Your name
∙ Total amount of time (effort) it took for you to complete the lab
∙ Short description of any concerns, interesting problems or discoveries encountered, or comments in general about the contents of the lab
∙ Describe, with 4-5 sentences, how you used gdb to find a bug in your program while debugging it. Or, if you had no bugs in your program, how you used gdb to verify that your program was working correctly. Include how you set breakpoints, variables you printed out, what values they had, what you found that enabled you to fix the bug.
 You should aim to always hand an assignment in on time or early. If you are late (even by a minute – or heaven forbid, less than a minute late), you will receive 75% of your earned points for the designated grade as long as the assignment is submitted by 11:30 pm the following day, based on the due date given above. If you are more than 24 hours late, you will receive a zero for the assignment and your assignment will not be graded at all.
 Any lab submitted that does not compile – without errors or warnings – and run WILL RECEIVE AN AUTOMATIC GRADE OF ZERO. No exceptions will be made for this rule – to achieve even a single point on a lab, your code must minimally build (compile to an executable without errors or warnings) on stdlinux and execute on stdlinux without crashing, the gcc command must use the –ansi

and -pedantic options.
Since a Makefile is required for this lab, you must create the appropriate compile statements to create a lab3main.o, readtitles.o, get_title.o, getfavorites.o, savedata.o, and free_dmem.o files, which would then create a lab3 executable. Graders will be downloading your lab3.zip file from Carmen, unzipping it, and then executing make from a linux command line prompt. Your program must compile –without errors or warnings – via commands within the Makefile. Given valid input, your program must also run without having a seg fault or other abnormal termination.
 You are welcome to do more than what is required by the assignment as long as it is clear what you are doing and it does not interfere with the mandatory requirements.
LAB DESCRIPTION
BOOK LIST WITH FAVORITES (100%) Mandatory filenames: lab3main.c readtitles.c
get_title.c getfavorites.c savedata.c free_dmem.c
Mandatory executable name: lab3
PROBLEM:
The user of your program will use it to create a list of books s/he had read, and then your program
will create a subset of this list as a favorites list. You will not know how many books the user wishes to include on the list until the program gets its first input. After the user has finished entering all of the books titles, you must prompt the user for a subset of the book titles to put on a “favorites” list. You will want to review Slide Deck 13, slides 47 through 53 to help you visualize how the data should be stored. You must use pointers within this project such that you have one array of char * that contains all of the book titles and an array of char ** for favorites. The third item this program does is ask the user whether s/he want to store a copy of their information to a file on disk. If so, you program will ask for a file name and store the information within the file in the format shown in the example below.
1. First, you must prompt the user to enter the number of books titles they plan to enter. The user will enteranintegergreaterthanorequalto1toindicatethenumberofbooktitles.(NOTE: Makea point to test your program to ensure entering just 1 book title works.)
2. You must dynamically allocate memory for the titles array, then dynamically allocate enough memory to hold each individual book title as each book title is read in. You can assume that there will be no book title with more than 60 characters. Remember that all character strings in C are null terminated and that you have to allocate space in your string for that null character, in addition to the length of the string you wish to have. Also realize that you won’t know how many of the 60 characters the book title will fill until after you read the title.
3. You must then prompt the user to enter each book title on a separate line. You must assume that each book title could contain more than one word and will be separated by a newline character from the next book title. You can assume that the user will enter the input in this format, so you do not need to check to make sure that the format of the input meets this description, and you do not need to reject input

which is not properly formatted. You can also assume that the user’s input is correct. If you do not completely understand this description jump to the bottom of this file and check out the example data.
4. You can assume that there will be no book title duplicates.
5. After reading in all the book titles, your program must print all of the book titles back out with a number next to each title.
6. You must then ask the user to pick how many books s/he wishes to put on their favorites list. The favorites list will consist of a subset (up through all books on the titles list) of the books on the titles list.
7. Once you have this number, you will have to dynamically allocate enough space for an array of 8- byte addresses for the favorites array.
8. The user will then specify by title number which books should be included on the favorites list.
9. Your program must then print out the books on the favorite list.
10. Next, your program must ask whether the user wishes to store in an ASCII file the information they have input. They indicate yes/no with 1 or 2.
11. If the user wishes to save the data, you must open a file and store the information in the file based on the format shown below, close the file, and then confirm to the user the data has been saved.
12. Prior to exiting the program, you must free() all dynamically allocated memory. You can determine whether you have managed to accomplish this with the valgrind tool.
CONSTRAINTS:
∙ Source code files (.c files) submitted to Carmen as a part of this program must include the following at the top of the file:
/* BY SUBMITTING THIS FILE TO CARMEN, I CERTIFY THAT I HAVE STRICTLY ADHERED TO THE TENURES OF THE OHIO STATE UNIVERSITY’S ACADEMIC INTEGRITY POLICY WITH RESPECT TO THIS ASSIGNMENT.
*/
If you choose not to put the above comment in your file, you will receive no points for the lab.
 Youmustcommentyourcode
 Youmustadheretoitems1-12above.
 YoumustcreateandsubmitaMakefilethatwillbeusedtocreateyour.zipfileandyourexecutable, lab3. This Makefile must define at least each of the following targets: all, lab 3, lab3.zip, lab3main.o,

readtitles.o, get_title.o, getfavorites.o, savedata.o, free_dmem.o, and clean. Creating this file at the beginning of your development process and using it as you work, will allow you to test your Makefile for proper operation.
 Separateyourcodeintodifferentfunctionssothatyourmain()isunclutteredandeasytounderstand. Pointers to your two arrays must be declared in your main() program. You must have a different function that is called from main() that performs each of the following tasks:
1. populates the titles array in a file called readtitles.c
A. readtitles()mustcallafunctioncalledget_title()thatreads asinglebooktitlefrominput.
readtitles() must reside in a file called read_title.c
2. populates the favorites array in a file called getfavorites.c
3. saves data to a file in a file called savedata.c
4. frees all dynamically allocated memory in a file called free_dmem.c
 Youmustcreatealab3.hfilethatholdstheprototypestothesefivefunctions.
 Novariablescanbedeclaredoutsideofablock.Thatis,novariablescanbedeclaredas“global”.
 Youmayonlyusegetchar(),printf(),fprintf(),scanf(),fopen()andfclose()foranyI/Oneedsyouhave while writing this program.
 Youmustusepointerswithinthisprojectsuchthatyouhaveanarrayofcharpointersthatcontains the addresses of all of the book title strings (the variable that holds the address to this array must be declared as char **) and an array for favorites that contains addresses from the titles array (the variable that holds the address to this array must be declared as char ***).
 Besureyourdirectionstotheuserareclearsotheyaresuretoentertheinput data correctly.
 Youcannotusestaticallydeclaredarraysinthislabtostoreanyoftheuserdata other than the filename in which to store user’s information.
 YourcodemustworkcorrectlyforANYNUMBERofbooktitles(includingjust1andup to the limits of available memory, of course), and these numbers are not known in advance.
 Youmustusepointerstoaccessuserdata
 thevalgrindprogrammustindicatethatyourprogramhasnomemoryleaks
 Youmaynotaccessanyoftheallocatedstoragespaceusingindexes,asisusuallydone for a statically declared array, but only by using pointers and pointer arithmetic.
LAB SUBMISSION
Always be sure your linux prompt reflects the correct directory or folder where all of your files to be submitted reside. If you are not in the directory with your files, the following will not work correctly.

You must submit all your lab assignments electronically to Carmen in .zip file format. The format of zip command is as follows:
[jones.5684@fl1 lab3] $ zip
where is the name of the file you want zip to add all of your files to and is a list of the file(s) that make up the lab. Remember that you must be at the correct location (the designated directory) for the command to be able to find your files-to-submit.
For lab3, the zip command would look like this:
zip lab3 lab3main.c readtitles.c get_title.c getfavorites.c savedata.c free_dmem.c lab3.h Makefile lab3Readme
You must put this command in your Makefile.
NOTE:
• Your programs MUST be submitted in source code form. Make sure that you zip all the required .c files for the current lab (and .h files when necessary), and any other files specified in the assignment description. Do NOT submit the object files (.o) and/or the executable. The grader will not use executables that you submit anyway. She or he will always build/compile your code using your Makefile after inspecting it to insure it compiles using gcc -ansi – pedantic and then test the executable generated by that command.
• It is YOUR responsibility to make sure your code can compile and run on CSE department server stdlinux.cse.ohio-state.edu, using gcc -ansi –pedantic without generating any errors or warnings or segmentation faults, etc. Any program that generates errors or warnings when compiled or does not run without system errors will receive 0 points. No exceptions!
See below for a sample input to the program. Your program must work for all valid input not just this one. Be creative with your test data!!! 
Sample Screen Input/Output for this lab: (user provided input is in green.)
How many library book titles do you plan to enter? 9
Enter the 9 book titles one to a line: Harry Potter and the Order of the Phoenix David Copperfield
3001: The Final Odyssey
Uriel’s Machine
2001: A Space Odyssey
War and Peace
Great Expectations
The Rubaiyat
Adventures of Tom Sawyer
You’ve entered:
1. Harry Potter and the Order of the Phoenix
2. David Copperfield
3. 3001: The Final Odyssey
4. Uriel’s Machine
5. 2001: A Space Odyssey
6. War and Peace
7. Great Expectations

8. The Rubaiyat
9. Adventures of Tom Sawyer
Of those 9 books, how many do you plan to put on your favorites list? 5
Enter the number next to each book title you want on your favorites list: 1 3 5 7 9
The books on your favorites list are:
1. Harry Potter and the Order of the Phoenix
2. 3001: The Final Odyssey
3. 2001: A Space Odyssey
4. Great Expectations
5. Adventures of Tom Sawyer
Do you want to save them (1=yes, 2=no): 1
What file name do you want to use? booksIveRead
Your booklist and favorites have been saved to the file booksIveRead.
Sample File Output for this lab(i.e. what is written to disk):
Books I’ve Read:
Harry Potter and the Order of the Phoenix David Copperfield
3001: The Final Odyssey
Uriel’s Machine
2001: A Space Odyssey
War and Peace
Great Expectations
The Rubaiyat
Adventures of Tom Sawyer
My Favorites are:
Harry Potter and the Order of the Phoenix 3001: The Final Odyssey
2001: A Space Odyssey
Great Expectations
Adventures of Tom Sawyer