Page 1 of 1

Homework 3 Due Saturday, July 16, 2022 at 11:59 pm Deliverables: Please upload the .cpp files to Blackboard. Also, inclu

Posted: Sun Jul 10, 2022 11:26 am
by answerhappygod
Homework 3 Due Saturday July 16 2022 At 11 59 Pm Deliverables Please Upload The Cpp Files To Blackboard Also Inclu 1
Homework 3 Due Saturday July 16 2022 At 11 59 Pm Deliverables Please Upload The Cpp Files To Blackboard Also Inclu 1 (88.55 KiB) Viewed 73 times
Homework 3 Due Saturday, July 16, 2022 at 11:59 pm Deliverables: Please upload the .cpp files to Blackboard. Also, include a document which describes what each program is doing in a file called comments.txt. This comments file is important because it is critical that you can describe what the code is doing. If you worked with another student to complete this assignment, attribute them in your homework by writing "I worked with xxxx" on the top of your homework. BE SURE TO WRITE AND COMPILE YOUR OWN CODE. The comments.txt file must include your own words. Do not copy and paste from anyone else. Problem 1 Create an empty vector v. Then, create a prompt which will continuously ask you for a value to insert into the vector, along with the index value. Use the insert function to insert the value at the given index. After every iteration, print the vector. Continue to enter values until someone enters an illegal index value. In that case, end the program. Please enter a value: 7 Please enter an index: 0 7 Please enter a value: 3 Please enter an index: 1 73 Please enter a value: 4 Please enter an index: 1 743 Please enter a value: 9 Please enter an index: 2 7493 Please enter a value: 8 Please enter an index: 10 Index value not allowed! Problem 2 Refer back to the noe code (you may refer to either my solution or your own). Manipulate it so that instead of breaking when a word with an e is entered, words with e's are added to a vector and printed at the end. Also, keep track of the words that were entered that do not contain e's.
Please enter a word (enter Q to quit): I Please enter a word (enter Q to quit): am Please enter a word (enter Q to quit): trying Please enter a word (enter Q to quit): to Please enter a word (enter Q to quit): write Please enter a word (enter Q to quit): words Please enter a word (enter Q to quit): that Please enter a word (enter Q to quit): do Please enter a word (enter Q to quit): not Please enter a word (enter Q to quit): contain Please enter a word (enter Q to quit): e's Please enter a word (enter Q to quit): Q Words entered with e's: write e's Words entered with no e's: I am trying to words that do not contain Problem 3 I have manipulated the DND code from Lab 4 to be able to be read by C++ (attached to this homework). Now, modify the code such that instead of storing the characters and traits in arrays, create a character object to store the traits. Store each characteristic (wisdom, dexterity, etc.) as attributes in the character object. Assume that the traits will always be in this order: Strength, Dexterity, Constitution, Intelligence, Wisdom, and Charisma. HINT: Be sure that you are creating the objects with the following attributes: name, strength, dexterity, constitution, intelligence, wisdom, and charisma. Do not worry about creating these attributes dynamically. Once you have read in all of the data and created the objects, store the characters in a vector. Use a loop to print out the character information from the character vector. Will's strength is: 11 Will's dexterity is: 12 Will's constitution is: 4 Will's intelligence is: 17 Will's wisdom is: 2 Will's charisma is: 13 Mike's strength is: 2 Mike's dexterity is: 20 Mike's constitution is: 18 Mike's intelligence is: 16 Mike's wisdom is: 7 Mike's charisma is: 2 Dustin's strength is: 2 Dustin's dexterity is: 5 Dustin's constitution is: 3 Dustin's intelligence is: 7
Problem 4 Use inheritance to create the following tree: Food Meat Chicken Beef Vegetable Fruit Spinach Tomato Strawberry Apple Then, in main, create a function that will take in a type of food and return the inheritance chain. Please enter the type of food: Strawberry Strawberry is a type of Fruit which is Food Please enter the type of food: Chicken Chicken is a type of Meat which is Food HINT: The code that created the last line looks like this: cout << c.type << " is a type of " << c.group << " which is " << c.name; Problem 5 You can use malloc, calloc, and realloc in C++ the same way that you can in C- so be sure to watch the memory allocation lecture. You can apply everything that you learned from C in C++. Recall that realloc is called with (int *)realloc(p, x) where p is a pointer that has previously been declared and x is the size that the user wants to reallocate. We want to show how we can use realloc to approximate the maximum size of an array that you can create in C++. First, use malloc to create space for an array in C++. Then, create a loop that will use realloc to increase the size of that array by a predetermined amount (I chose an increase of 1000000 - feel free to use your own sizes if you wish). If you create a pointer ptr (which should be returned by realloc), you can print the location of the ptr in memory with cout << ptr << endl. To end the loop, check to see if the pointer returned by realloc is the null pointer. This will be a sign that you have reached
your maximum memory size. Print the size of the array along with where the array is being stored (your output will differ): 147000001 23C40040 148000001 46D13040 149000001 00F43040 150000001 247BE040 151000001 4840A040 152000001 00F47040 153000001 2532D040 154000001 49AE3040 155000001 00F46040 156000001 25E96040 157000001 4B1BC040 158000001 00F4C040 159000001 26A1E040 160000001 4C8B3040 161000001 00F4B040 162000001 27584040 The maximum size is: 163000001