CSE 130

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

CSE 130

Post by answerhappygod »

CSE 130
Cse 130 1
Cse 130 1 (221.6 KiB) Viewed 31 times
Cse 130 2
Cse 130 2 (117.93 KiB) Viewed 31 times
Cse 130 3
Cse 130 3 (136.86 KiB) Viewed 31 times
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 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 Dustin's wisdom is: 18
Use inheritance to create the following tree: Food Meat Chicken Beef Vegetable Spinach Tomato Fruit 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;
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):
your maximum memory size. Print the size of the array along with where the array is being stored (your output will differ):
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply