Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Write the definitionof a function called cubes with the following specifications:
- It takes an integer as parameter.
-It dynamically allocates memory for an array of N integers; where N is the value of the function arguement, and assigns the address of the array to a pointer.
- It stores on the array the cubes of numbers from 1 to N.
- It returns a pointer to that array.
Example:
If the function is called with the argument 5, it should return a pointer to an integer array with the following content: 1 8 27 64 125
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- For Assignment 5, you will design and write a program that covers the following topics: Functions, Vectors, Structures, and Classes. Functions & Passing Variables: Write a different function for each type of variable used. The functions should provide some sort of output through a cout or return value. Normal variable: Passing a variable by value to a paramater of a function. Show that this only makes a copy of the variable passed to it. Normal variable with a default value: Set a default value for a function parameter. Show how the default value gets used. Reference variable: Passing a variable by reference to a parameter of a function. Show how a reference variable can change the value of variable in main(). Show how the use of const can make a reference variable safer (think of it in terms of read/write). Pointer variable: Passing an address of a variable to a parameter of a function. Show how a pointer can change the value of a variable in main(). Show…arrow_forwardC++arrow_forwardDeclare an integer pointer variable intPointer. Initialize it to point to an int variablenamed someInt.Assign the value 451 to someInt and output (cout) the variable someInt and output (cout)the value pointed to by intPointer.Write an assignment statement that indirectly stores 900 into the value pointed to by intPointer.Output (cout) the value pointed to by intPointer and output (cout) the variable someInt,arrow_forward
- Write a c++ function that accepts an array of doubles and the array’s size as its only arguments. The function should use dynamic memory allocation to create a new array that is double the size of the argument array. The function should copy the contents of the argument array to the second half of the new array and initialize the first half of the new 0s. The function should return a pointer to the new array. So, if the original array contained 1 2 3 4, the new array should contain 0 0 0 0 1 2 3 4. So, if the original array contained 1 2 3 4, the new array should contain 0 0 0 0 1 2 3 4.arrow_forwardChoose if each of the following is true or false:Dynamically binding data to virtual functions is limited to pointers and references.arrow_forwardWrite a function named rockPaperScissors. It should have one input:- An array with 2 elements, each representing a player in the game of Rock Paper Scissors.It should return one output- A scalar with the result of the game.For the purposes of this program, assume the following numerical code:- 1 is rock- 2 is paper- 3 is scissorsIn the game of Rock, Paper, Scissors, rock beats scissors, paper beats rock, and scissors bears paper. Ifplayers play the same object, the result is a tie.Your output should be:- The index of the winning player if there is a winner.- 0 if there is a tie- -1 if a player played an invalid object (a number that is not 1, 2, or 3)For example, if we called our function:result = rockPaperScissors([1 2]);result would be 2, as paper beats rock.If we called our functionresult = rockPaperScissors([3 2]);result would be 1 because scissors beats papearrow_forward
- 1- Write a user-defined function that accepts an array of integers. The function should generate the percentage each value in the array is of the total of all array values. Store the % value in another array. That array should also be declared as a formal parameter of the function. 2- In the main function, create a prompt that asks the user for inputs to the array. Ask the user to enter up to 20 values, and type -1 when done. (-1 is the sentinel value). It marks the end of the array. A user can put in any number of variables up to 20 (20 is the size of the array, it could be partially filled). 3- Display a table like the following example, showing each data value and what percentage each value is of the total of all array values. Do this by invoking the function in part 1.arrow_forwardDefine a function named “getExamListInfo” that accepts an array of Exam objects and its size. It will return the following information to the caller: - The number of exams with perfect score - The number of exams with “Pass” status - The index of the Exam object in the array that has the largest score. For example, if you get the exam info for this array of Exam object Exam examList[] = { {"Midterm1 Exam", 90}, {"Midterm2 Exam", 80}, {"Final Exam", 50}, {"Extra Credit", 100}, {"Initial Test", 0}, {"Homework1", 69} } ; You will get Perfect Count: 1 Pass Count: 3 Index of the largest: 3 C++arrow_forwardWrite a value-returning function that receives an array of structs of the type defined below and the length of the array as parameters. It should return as the value of the function the sum of the offspring amounts in the array. Note: you do not need a main function or to create an array. Assume the array already exists from main. #include <iostream>using namespace std; // struct declaration for Animal struct Animal { // a string for animal typestring animal_type;// a string for color string color;// an integer for number of offspring. int number_of_offspring;}; // Main function to declare a structure variable of type Animal. int main(){struct Animal A1;return 0;}arrow_forward
- write in html and scriptarrow_forwardC++ Question Hello Please answer the attached C++ programming question correctly, just as the prompt states. Also, make sure that the code is working properly. Thank you.arrow_forwardChoose if each of the following is true or false:Dynamically binding data to virtual functions is limited to pointers and references.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education