Homework 3 Due Saturday, July 16, 2022 at 11:59 pm Deliverables: Please upload the .cpp files to Blackboard. Also, inclu
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Homework 3 Due Saturday, July 16, 2022 at 11:59 pm Deliverables: Please upload the .cpp files to Blackboard. Also, inclu
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